7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Microsoft Fabric データパイプラインで SharePoint Online / Teams 上のファイルを OneLake に連携する

Last updated at Posted at 2024-04-04

はじめに

Azure Data Factory でできたことをできるのか確認

2024-04-08 時点の情報です。

連携対象

10_ファイル連携フォルダの全ファイルをもってきたい

image.png

image.png

検証手順

疎通準備

  1. アプリ登録、サイトアクセス許可を実施(https://learn.microsoft.com/ja-jp/fabric/data-factory/connector-sharepoint-online-list-copy-activity)
  2. レイクハウスを作成して、出力先のフォルダ作っておく(https://learn.microsoft.com/ja-jp/fabric/data-engineering/tutorial-build-lakehouse)
    image.png
  3. 接続を構成しておく(https://learn.microsoft.com/ja-jp/fabric/data-factory/connector-sharepoint-online-list)
    ※遷移用URL https://app.fabric.microsoft.com/groups/me/gateways
  4. パイプラインを作成して対象フォルダを示すパラメータを作成
    image.png
  5. 作成した接続でもってルックアップを構成
    image.png
  6. 配列が帰ってきました
    image.png
  7. Lookupした結果をフィルタします
@and(
    startswith(item().パス,pipeline().parameters.directory)
    ,equals(item().コンテンツタイプ,'ドキュメント'))

image.png

ファイルを取得する(トークン取得)

ファイル取得では専用の子パイプラインを作成してみます。
まずはトークンを取得するためのWebアクティビティを使います。

  1. http 接続
    https://accounts.accesscontrol.windows.net/ への Web v2 接続を構成します。末尾のスラッシュ忘れずに
    ※遷移用URL https://app.fabric.microsoft.com/groups/me/gateways
    image.png
  2. 新しいパイプラインを作成してパラメータを追加
    image.png
  3. web アクティビティを追加して、
    image.png
    相対URL
@concat(pipeline().parameters.tenant_id,'/tokens/OAuth/2')

本文

@concat(
    'grant_type=client_credentials&client_id=',
    pipeline().parameters.client_id,
    '@',
    pipeline().parameters.tenant_id,
    '&client_secret=',
    pipeline().parameters.client_secret,
    '&resource=00000003-0000-0ff1-ce00-000000000000/',
    pipeline().parameters.tenant_name,
    '.sharepoint.com@',
    pipeline().parameters.tenant_id
)

ヘッダー
名前:Content-Type
値:application/x-www-form-urlencoded
4. 一度実行して、成功を確認したら入力と出力についてセキュリティで保護のチェックをつけましょう
image.png

ファイルを取得する(ファイル取得、書き込み)

  1. [テナント名].sharepoint.com への Web 接続 を構成します。末尾のスラッシュ忘れずに。また、ここではテスト接続をスキップしましょう。(ここを間違えるとはまります)
    image.png
    ※遷移用URL https://app.fabric.microsoft.com/groups/me/gateways
    URLはhttps://{テナント名}.sharepoint.com/sites/{サイト名}/_api/web/ で入力
  2. コピーアクティビティを後続に追加してソース設定を以下のようにします。
    image.png
    相対 URL
GetFileByServerRelativeUrl('@{pipeline().parameters.file_path}/@{pipeline().parameters.file_name}')/$value

追加のヘッダー

@{concat('Authorization: Bearer ', activity('get_access_token').output.access_token)}

※アクティビティ名に合わせてください。
3. あて先の設定をします
image.png

ファイルパス(フォルダ)

@replace(
    concat(pipeline().parameters.distination_path,
        '/',
        pipeline().parameters.file_path)
    ,pipeline().parameters.directory
    ,''
    )

ファイルパス(ファイル名)

@pipeline().parameters.file_name

4.ルックアップを構成したパイプラインに戻ってfor_eachを追加
image.png
項目

@activity('Filter1').output.value

5.パイプライン呼び出しを for_each内に形成。各種のパラメータ内容は変数などにすると管理が楽かもしれません
image.png
tenant_id: サービスプリンシパル情報から取得
client_id: サービスプリンシパル情報から取得
client_secret: サービスプリンシパル情報から取得(secretはkeyvaultから取れるようになってほしいですね
tenant_name: [tenant_name].sharepoint.com 形式のURLから取得
file_path:

@item().パス

file_name:

@item().名前

distination_path: ファイルを出力したフォルダ名。今回の例なら冒頭に作成したレイクハウスのフォルダ名からsharepoint
directory:

@pipeline().parameters.directory

6.実行すると、フォルダ内のファイル3点すべて連携されました。ファイル数が多い場合に時間がかかりそうなのが心配なので、標準機能でバルクなファイルコピーできるようになるのを期待
image.png

image.png

image.png

はまったところメモ

ACSの有効化

既定で無効となっているので有効化する必要がある

2018 年 11 月 7 日より後に構築されたテナントの場合、ACS は既定で無効になっています。

なお、ACSは廃止されるらしいので EntraID API許可でつないだほうがよさそう。サイトレベルのアクセス許可にはGraphAPIでの操作が必要ぽいけど要検証

MSGraph API によるアクセストークン取得とSharepont API使用

2024-04-08追記

できたので備忘メモ(当分はやる必要なしなので自分用)

graph api 用のアクセストークン取得(Post)する。Web V2 コネクタ(https://login.microsoftonline.com/)

URL

@concat(pipeline().parameters.tenant_id,'/oauth2/v2.0/token')

body

@concat(
    'grant_type=client_credentials&client_id=',
    pipeline().parameters.client_id,
    '@',
    pipeline().parameters.tenant_id,
    '&client_secret=',
    pipeline().parameters.client_secret,
    '&scope=https://graph.microsoft.com/.default'
)

siteId をgetする。Web V2 コネクタ(https://graph.microsoft.com/)

URL

v1.0/sites/pipeline().parameters.tenant_name:/sites/{sitename}

nameでフィルタして、Web コネクタ(https://graph.microsoft.com/)で取得


v1.0/sites/pipeline().parameters.tenant_name,
    '.sharepoint.com,{siteId}/drive/root:/General/{fileName}:/content

利用したAPI https://learn.microsoft.com/ja-jp/graph/api/driveitem-get?view=graph-rest-1.0&tabs=http

メモ:サイトを絞る場合 https://qiita.com/mnrst/items/4315fdbe80c9cb0e5640

7
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?