cURLのインストールおよび使用
このドキュメント内の例では、cURLを使用して、Oracle Linux Automation Manager REST APIへのアクセスおよび使用方法を示します。
タスク1: cURLのインストール
サーバーに安全に接続するには、認証局(CA)証明書に対して認証するSSL CA証明書ファイルまたはバンドルを提供するcURLのバージョンをインストールする必要があります。 CA証明書認証の詳細は、認証を参照してください。
次の手順では、Oracle Linux 8システムにcURLをインストールする方法を示します。
-
cURLがシステムにすでにインストールされているかどうかを確認します。
sudo dnf info curl
パッケージがインストールされている場合は、「インストール済パッケージ」リストに表示されます。 インストールされていない場合は、「使用可能なパッケージ」リストにそのリストが表示されます。 cURLがリポジトリで使用できない場合は、ol8_baseos_latestリポジトリを有効にして、このステップを繰り返します。
-
cURLがまだインストールされていない場合はインストールします。
sudo dnf install curl
これで、cURLを使用してリクエストを送信する準備ができました。
タスク2: cURLの呼出し
cURLを起動し、必要に応じて次の表で定義されている1つ以上のコマンドライン・オプションを指定して、その実行を指示します。
cURLのオプション | 説明 |
---|---|
-i --include
|
レスポンスのヘッダーを返します。 |
-H --header |
H --header: リクエストにヘッダーを含めます。 |
"Authorization: Bearer <token>"
|
コマンドの実行に必要なOauth2トークンを指定します。 |
-X <method>
|
リクエストのメソッド(GET、POSTなど)、その後にAPIエンティティ・パスを示します。 |
-d, --data @file.json
|
ローカル・マシン上の、JSON形式のリクエスト本文が含まれているファイルを識別します。 または、-d"{id=5,status='OK'} を使用してリクエスト本文を渡すことができます。
|
-F, --form @file.json
|
ローカル・マシン上でJSON形式のフォーム・データを識別します。 |
-k |
CA権限が設定されておらず、接続が安全でないことを示します。 このオプションはお薦めしません。 |
cURLコマンドの構文は次のとおりです。
curl -i -H Authorization: Bearer <token> -X <method> https://<hostname or IP address>/api/v2/<resource-path>
前述の例で、<token>はユーザー・アカウントに対して生成されたOauth2トークン、<method>はアクション(Get、Post、Delete、Put、Patchなど)、<hostname or IP address>はOracle Linux Automation Managerサーバーのホスト名またはIPアドレス、<resource-path>はユーザー/やcredential_types/などのリソース・パスです。
たとえば:
curl -i -H "Authorization: Bearer pVQoc51Apt4LNrXrNzoSbaMCDzjK8B" -X GET https://192.102.118.107/api/v2/users/ HTTP/1.1 200 OK Server: nginx/1.14.1 Date: Mon, 12 Aug 2024 16:56:44 GMT Content-Type: application/json Content-Length: 1952 Connection: keep-alive Vary: Accept, Accept-Language, Origin Allow: GET, POST, HEAD, OPTIONS X-API-Product-Version: 23.7.0 X-API-Product-Name: AWX X-API-Node: 100.102.118.107 X-API-Time: 0.024s Content-Language: en X-API-Total-Time: 0.059s X-API-Request-Id: af9121bf2bb748d08c60696334d4ea72 Access-Control-Expose-Headers: X-API-Request-Id Strict-Transport-Security: max-age=15768000 {"count":2,"next":null,"previous":null,"results":[{"id":1,"type":"user","url":"/api/v2/users/1/","related":{"teams":"/api/v2/users/1/teams/","organizations":"/api/v2/users/1/organizations/","admin_of_organizations":"/api/v2/users/1/admin_of_organizations/","projects":"/api/v2/users/1/projects/","credentials":"/api/v2/users/1/credentials/","roles":"/api/v2/users/1/roles/","activity_stream":"/api/v2/users/1/activity_stream/","access_list":"/api/v2/users/1/access_list/","tokens":"/api/v2/users/1/tokens/","authorized_tokens":"/api/v2/users/1/authorized_tokens/","personal_tokens":"/api/v2/users/1/personal_tokens/"},"summary_fields":{"user_capabilities":{"edit":false,"delete":false}},"created":"2024-08-12T16:46:26.217924Z","modified":"2024-08-12T16:48:34.750654Z","username":"admin","first_name":"","last_name":"","email":"admin@example.com","is_superuser":true,"is_system_auditor":false,"password":"$encrypted$","ldap_dn":"","last_login":"2024-08-12T16:48:34.750654Z","external_account":null,"auth":[]},{"id":2,"type":"user","url":"/api/v2/users/2/","related":{"teams":"/api/v2/users/2/teams/","organizations":"/api/v2/users/2/organizations/","admin_of_organizations":"/api/v2/users/2/admin_of_organizations/","projects":"/api/v2/users/2/projects/","credentials":"/api/v2/users/2/credentials/","roles":"/api/v2/users/2/roles/","activity_stream":"/api/v2/users/2/activity_stream/","access_list":"/api/v2/users/2/access_list/","tokens":"/api/v2/users/2/tokens/","authorized_tokens":"/api/v2/users/2/authorized_tokens/","personal_tokens":"/api/v2/users/2/personal_tokens/"},"summary_fields":{"user_capabilities":{"edit":true,"delete":false}},"created":"2024-08-12T16:49:57.582764Z","modified":null,"username":"automationuser","first_name":"automationuser","last_name":"Automation","email":"automation@account.com","is_superuser":false,"is_system_auditor":true,"password":"$encrypted$","ldap_dn":"","last_login":null,"external_account":null,"auth":[]}]}