# 既存のAuthenticationを再利用する このガイドでは、「Reuse Connector Authentication」と呼ばれる新機能について説明します。この機能により、既存のConnector Authenticationを再利用できます。 新しい統合ごとに新しいAuthenticationを作成する代わりに、既存のAuthenticationsを再利用できます。これにより、セキュリティが向上し、統合のセットアップ時の時間を節約できます。また、OAuth2認証方法のみをサポートする統合を、WorkflowおよびTD Toolbelt CLIで利用できるようになります。 ## Authenticationの作成と再利用 ### 新しいAuthenticationを作成する(オプション) 必要に応じて、新しいAuthenticationを作成します: 1. TD Consoleを開きます。 2. **Integrations Hub > Catalog**に移動します。 ![](/assets/26617500.ca92fa4ab9277dca95973c6bd413fc662a3f0d04b57d58f7a8c952a29f28bbec.ef656343.png) 1. Catalogで統合を検索し、アイコンの上にマウスをホバーして**Create Authentication**を選択します。 ![](/assets/26617501.d6a5ad453f9fa98b4336af9506dadbd04ea44299e2f9af7fd760f75ac68e3f88.ef656343.png) 1. Credentialsタブが選択されていることを確認し、統合の資格情報を入力します。 Authenticationの詳細は、タイプによって異なります([About Treasure Data Integrations](https://docs.treasuredata.com/smart/project-integrations/about-treasure-data-integrations)を参照)。以下はAuthenticationページの例です: ![](/assets/image2022-4-18_11-7-14.94b62d1ba550c90c07c8664e6b98c607512237d3e1ca928c681329ba4c042beb.ef656343.png) 1. **Continue**を選択します。 2. Authenticationの名前を入力し、**Done**を選択します。 ### 既存のAuthentication IDを特定する 既存のAuthenticationを再利用するには、まずAuthentication IDを特定する必要があります。このIDは通常、AuthenticationsのブラウザURLに表示されます。保存されているAuthenticationのAuthentication IDを取得するには、次の手順に従います。 1. TD Console UIで操作します。 2. **Integrations Hub > Authentications**に移動します。 3. 保存されているAuthenticationをクリックします。 4. ブラウザURLのAuthentication IDをコピーして保存します。 ![](/assets/authid.8ef0eb138b0aca4a9fdfd1d3efabb92353a04b78567d36f64199b75e3e46dcfc.ef656343.png) ### 既存のAuthenticationを使用する 既存のAuthenticationを再利用するには、設定キー td_authentication_id に Authentication IDの値を指定します。上記の例では、値は255574になります。 この設定キーは、以下のCLIコマンドで使用できます: * connector:guess * connector:preview * connector:issue * connector:create * connector:update * sched:create * sched:update * query * export:result また、以下のWorkflow Operatorでも使用できます: * td * td_run * td_load #### 新しいJobおよびWorkflow設定でAuthenticationを再利用する例 新しいJobまたはWorkflow設定の場合、td_authentication_id を Authentication IDに設定するだけです。場合によっては、特定のtd_authentication_idで設定されたconfig.ymlファイルを最初に作成する必要があります。 例えば、assume_role認証方法を使用するS3_v2統合の場合は次のようになります。 ![](/assets/image003.473bc72550b7f89df3d72ea9cbd484323780c34ee3eebc52ae2d07e228f3ee99.ef656343.png) * connector:guessの設定ファイル このファイル(s3_v2_seed.yml)では、td_authentication_idがAuthentication ID 260370に設定されています。このファイルは、config.ymlファイルの作成に使用されます。 ```yaml --- in: type: s3_v2 td_authentication_id: 260370 bucket: qa-auto-test-3 path_prefix: 'qh_s3connector_test/Compress/assume_role_staging.csv' ``` * **connector:guess**の結果 connector:guessは、s3_v2_seed.ymlを使用してconfig.ymlファイルを作成します。このファイルはTD Toolbelt CLIコマンドで使用されます。 ```bash td -k 1/xxx -e https://api.treasuredata.com connector:guess s3_v2_seed.yml ``` 推測された設定: ```yaml --- in: type: s3_v2 bucket: qa-auto-test-3 path_prefix: qh_s3connector_test/Compress/assume_role_staging.csv parser: charset: UTF-8 newline: CRLF type: csv delimiter: "," quote: "\"" escape: "\"" trim_if_not_quoted: false skip_header_lines: 1 allow_extra_columns: false allow_optional_columns: false columns: - {name: path, type: string} - {name: cnt, type: string} - {name: user, type: string} - {name: host, type: string} - {name: referer, type: string} - {name: code, type: long} - {name: agent, type: string} - {name: size, type: long} - {name: method, type: string} - {name: time, type: long} td_authentication_id: 260370 out: {} exec: {} filters: [] ``` config.ymlファイルを作成しました。 'td -k 1/xxx -e https://console.treasuredata.com connector:preview config.yml'を使用して、バルクロードのプレビューを確認してください。 * **connector:preview**の結果 ```bash td -k 1/xxx -e https://console.treasuredata.com connector:preview config.yml ``` * **connector:issue** ```bash td -k 1/xxx -e https://api.treasuredata.com connector:issue config.yml --database tuan_db --table test_tbl ``` * **connector:create** ```bash td -k 1/xxxx -e https://api.treasuredata.com connector:create bulkload_data_from_s3 "0 * * * *" tuan_db test_tbl config.yml ``` * **connector:update** ```bash td -k 1/xxx -e https://api.treasuredata.com connector:update bulkload_data_from_s3 -c config.yml -s '0 0 * * *' ``` * **sched:create** ```bash td -k 1/xxx -e https://api.treasuredata.com sched:create result_to_s3_v2 '0 0 * * *' --database tuan_db 'SELECT * from aaks' --result '{"type":"s3_v2","td_authentication_id":260370,"duration_in_seconds":3600,"bucket":"qa-auto-test-3","path":"qh_s3connector_test/Compress/assume_role_staging1.csv","format":"csv","compression":"none","header":true}' ``` * **sched:update** ```bash td - k 1/xxx -e https://api.treasuredata.com sched:update result_to_s3_v2 -s '0 0 * * *' --database tuan_db --result '{"type":"s3_v2","td_authentication_id":260370,"duration_in_seconds":3600,"bucket":"qa-auto-test-3","path":"qh_s3connector_test/Compress/assume_role_staging2.csv","format":"csv","compression":"none","header":true}' ``` * **query** ```bash td -k "1/xxxx" -e https://api.treasuredata.com query --database tuan_db --wait "SELECT * from aaks" --type presto --result '{"type":"s3_v2","td_authentication_id":260370,"duration_in_seconds":3600,"bucket":"qa-auto-test-3","path":"qh_s3connector_test/Compress/assume_role_staging.csv","format":"csv","compression":"none","header":true}' ``` * **export:result** ```bash td -k "1/xxxx" -e https://api.treasuredata.com export:result 1696822041 '{"type":"s3_v2", "td_authentication_id":260370, "bucket": "qa-auto-test-us-east-1", "path":"quang/test_export_result_02.csv"}' ``` #### 新しいWorkflow設定の例 * **td_load** この例では、td_loadコマンドがs3_v2_guessed.ymlを使用します。このファイルでは、td_authentication_idが260370に設定されています。 ### s3_v2_guessed.ymlファイル ```yaml --- in: type: s3_v2 td_authentication_id: 260370 bucket: qa-auto-test-3 path_prefix: 111time.csv parser: charset: UTF-8 newline: CRLF type: csv delimiter: "," quote: "\"" escape: "\"" trim_if_not_quoted: false skip_header_lines: 1 allow_extra_columns: false allow_optional_columns: false columns: - name: col_1 type: string - name: col_2 type: string - name: col_3 ``` ```yaml +import_from_s3_assume_role_with_existing_connection: td_load>: s3_v2_guessed.yml database: tuan_data table: wf_test ``` * **query** ```yaml +query_data_and_write_result_with_existing_connection_by_url: td>: query: 'select * from wf_test' database: tuan_data result_url: '{"td_authentication_id": 260370, "bucket": "qa-auto-test-3", "path": "viet/assume_role_from_eu01.csv"}' ``` * **td_run** この例では、presto_select_all_s3v2は保存されたクエリです。 ```yaml +query_sql: td_run>: presto_select_all_s3v2 database: quang result_url: '{"type":"s3_v2", "td_authentication_id":260370, "bucket": "qa-auto-test-us-east-1", "path":"quang/wf_jan16_1444.csv"}' ``` * **td_result_export** このOperatorは、result_connectionでTD Console UIのAuthentication名を返すことにより、レガシー方式で既存の統合Authenticationの再利用をサポートします。 ```yaml _export: td: database: quang +export_query_result: td_result_export>: job_id: 14660140 result_connection: quang_s3v2_happy_case_1195 result_settings: bucket: qa-auto-test-us-east-1 path: quang/s3v2_wf_jan16_1655.csv ``` #### 既存のJobまたはWorkflow設定でAuthenticationを再利用する例 既存のJobおよびWorkflow設定の場合、設定から既存のConnector Authenticationの宣言を削除し、Authentication IDを指定するtd_authentication_idに置き換えるだけです。この例では、TD ConsoleのAuthentication URLの末尾から取得したAuthenticationは11です。 ![](/assets/image005.7b64922d3538209cbd99829b9ebd4869c41055c580432949806338d151aad11c.ef656343.png)