AEM での cURL の使用 using-curl-with-aem

管理者は、多くの場合、システムの一般的なタスクを自動化またはシンプル化する必要があります。例えば、AEM では、ユーザーの管理、パッケージのインストールおよび OSGi バンドルの管理は、一般に行う必要のあるタスクです。

AEM が構築されている Sling フレームワークの RESTful 特性により、ほとんどのタスクは URL 呼び出しで実行できます。cURL は、そのような URL 呼び出しの実行に使用でき、AEM 管理者にとって便利なツールです。

cURL とは what-is-curl

cURL は、URL 操作を実行するために使用される、オープンソールのコマンドラインツールです。HTTP、HTTPS、FTP、FTPS、SCP、SFTP、TFTP、LDAP、DAP、DICT、TELNET、FILE、IMAP、POP3、SMTP および RTSP など、様々なインターネットプロトコルをサポートします。

cURL は、URL 構文を使用してデータを取得または送信するための、広く使用される安定したツールで、最初にリリースされたのは 1997 年です。cURL という名前の由来は、「URL を参照(see URL)」です。

AEM が構築されている Sling フレームワークの RESTful 特性により、ほとんどのタスクを URL 呼び出しに集約し、cURL で実行することができます。ページのアクティベートおよびワークフローの開始などのコンテンツ操作タスクや、パッケージ管理およびユーザー管理などの運用タスクは、cURL を使用して自動化できます。さらに、AEM のほとんどのタスクについて、独自の cURL コマンドを作成できます。

NOTE
cURL を使用して実行された AEM コマンドは、AEM の任意のユーザーと同様に承認される必要があります。cURL を使用して AEM コマンドを実行する場合、すべての ACL およびアクセス権が適用されます。

cURL のダウンロード downloading-curl

cURL は、macOS および一部の Linux ディストリビューションに標準で備わっています。実質的にほぼすべてのオペレーティングシステムで使用できます。最新のダウンロードは、https://curl.haxx.se/download.html にあります。

cURL のソースリポジトリは、GitHub にもあります。

cURL 対応 AEM コマンドの作成 building-a-curl-ready-aem-command

cURL コマンドは、ワークフローのトリガー、OSGi 設定の確認、JMX コマンドのトリガー、レプリケーションエージェントの作成など、AEM のほとんどの操作を対象に作成できます。

特定の操作に必要な最適なコマンドを見つけるには、ブラウザーの開発者ツールを使用して、AEM コマンドを実行する際に、サーバーに対する POST 呼び出しをキャプチャする必要があります。

次の手順では、例として、Chrome ブラウザー内で新しいページを作成してこの操作を実行する方法について説明します。

  1. AEM 内で呼び出すアクションを準備します。この例では、ページを作成 ​ウィザードの最後まで進みましたが、まだ「作成」はクリックしていません。

    chlimage_1-66

  2. 開発者ツールを開始して、「ネットワーク」タブを選択します。コンソールをクリアする前に、「ログを保持」オプションをクリックします。

    chlimage_1-67

  3. ページを作成 ​ウィザードの「作成」をクリックして、実際にワークフローを作成します。

  4. 結果として表示される POST アクションを右クリックして、コピーcURL としてコピー ​を選択します。

    chlimage_1-68

  5. cURL コマンドをテキストエディターにコピーして、コマンドから -H で始まるすべてのヘッダー(下図の青い部分)を削除し、-u <user>:<password> などの適切な認証パラメーターを追加します。

    chlimage_1-69

  6. コマンドラインで cURL コマンドを実行して、応答を表示します。

    chlimage_1-70

一般的な操作の AEM cURL コマンド common-operational-aem-curl-commands

次に、一般的な管理および操作タスクの AEM cURL コマンドのリストを示します。

NOTE
次の例では、AEM が localhost のポート 4502 で実行され、ユーザー admin(パスワード admin)を使用していると仮定します。追加のコマンドのプレースホルダーは、山括弧で囲まれています。

パッケージを管理 package-management

インストールされているすべてのパッケージを一覧表示

curl -u <user>:<password> http://<host>:<port>/crx/packmgr/service.jsp?cmd=ls

パッケージを作成 create-a-package

curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=create -d packageName=<name> -d groupName=<name>

パッケージをプレビュー preview-a-package

curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=preview

パッケージコンテンツを一覧表示 list-package-content

curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/console.html/etc/packages/mycontent.zip?cmd=contents

パッケージをビルド build-a-package

curl -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=build

パッケージを再度含める rewrap-a-package

curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=rewrap

パッケージの名前変更 rename-a-package

curl -u <user>:<password> -X POST -Fname=<New Name> http://localhost:4502/etc/packages/<Group Name>/<Package Name>.zip/jcr:content/vlt:definition

パッケージのアップロード upload-a-package

curl -u <user>:<password> -F cmd=upload -F force=true -F package=@test.zip http://localhost:4502/crx/packmgr/service/.json

パッケージのインストール install-a-package

curl -u <user>:<password> -F cmd=install http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip

パッケージのアンインストール uninstall-a-package

curl -u <user>:<password> -F cmd=uninstall http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip

パッケージの削除 delete-a-package

curl -u <user>:<password> -F cmd=delete http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip

パッケージのダウンロード download-a-package

curl -u <user>:<password> http://localhost:4502/etc/packages/my_packages/test.zip

パッケージのレプリケート replicate-a-package

curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip?cmd=replicate

ユーザー管理 user-management

新しいユーザーの作成 create-a-new-user

curl -u <user>:<password> -FcreateUser= -FauthorizableId=hashim -Frep:password=hashim http://localhost:4502/libs/granite/security/post/authorizables

新しいグループの作成 create-a-new-group

curl -u <user>:<password> -FcreateGroup=group1 -FauthorizableId=testGroup1 http://localhost:4502/libs/granite/security/post/authorizables

既存のユーザーへのプロパティの追加 add-a-property-to-an-existing-user

curl -u <user>:<password> -Fprofile/age=25 http://localhost:4502/home/users/h/hashim.rw.html

プロファイルを使用したユーザーの作成 create-a-user-with-a-profile

curl -u <user>:<password> -FcreateUser=testuser -FauthorizableId=hashimkhan -Frep:password=hashimkhan -Fprofile/gender=male http://localhost:4502/libs/granite/security/post/authorizables

グループのメンバーとしての新しいユーザーの作成 create-a-new-user-as-a-member-of-a-group

curl -u <user>:<password> -FcreateUser=testuser -FauthorizableId=testuser -Frep:password=abc123 -Fmembership=contributor http://localhost:4502/libs/granite/security/post/authorizables

グループへのユーザーの追加 add-a-user-to-a-group

curl -u <user>:<password> -FaddMembers=testuser1 http://localhost:4502/home/groups/t/testGroup.rw.html

グループからのユーザーの削除 remove-a-user-from-a-group

curl -u <user>:<password> -FremoveMembers=testuser1 http://localhost:4502/home/groups/t/testGroup.rw.html

ユーザーのグループのメンバーシップの設定 set-a-user-s-group-membership

curl -u <user>:<password> -Fmembership=contributor -Fmembership=testgroup http://localhost:4502/home/users/t/testuser.rw.html

ユーザーの削除 delete-a-user

curl -u <user>:<password> -FdeleteAuthorizable= http://localhost:4502/home/users/t/testuser

グループの削除 delete-a-group

curl -u <user>:<password> -FdeleteAuthorizable= http://localhost:4502/home/groups/t/testGroup

バックアップ backup

詳しくは、バックアップとリストアを参照してください。

OSGi osgi

バンドルの開始 starting-a-bundle

curl -u <user>:<password> -Faction=start http://localhost:4502/system/console/bundles/<bundle-name>

バンドルの停止 stopping-a-bundle

curl -u <user>:<password> -Faction=stop http://localhost:4502/system/console/bundles/<bundle-name>

Dispatcher dispatcher

キャッシュの無効化 invalidate-the-cache

curl -H "CQ-Action: Activate" -H "CQ-Handle: /content/test-site/" -H "CQ-Path: /content/test-site/" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://localhost:4502/dispatcher/invalidate.cache

キャッシュの削除 evict-the-cache

curl -H "CQ-Action: Deactivate" -H "CQ-Handle: /content/test-site/" -H "CQ-Path: /content/test-site/" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://localhost:4502/dispatcher/invalidate.cache

レプリケーションエージェント replication-agent

エージェントのステータスの確認 check-the-status-of-an-agent

curl -u <user>:<password> "http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json?agent=publish"
http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json?agent=publish

エージェントの削除 delete-an-agent

curl -X DELETE http://localhost:4502/etc/replication/agents.author/replication99 -u <user>:<password>

エージェントの作成 create-an-agent

curl -u <user>:<password> -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:title=new-replication" -F "jcr:content/sling:resourceType=/libs/cq/replication/components/agent" -F "jcr:content/template=/libs/cq/replication/templates/agent" -F "jcr:content/transportUri=http://localhost:4503/bin/receive?sling:authRequestLogin=1" -F "jcr:content/transportUser=admin" -F "jcr:content/transportPassword={DES}8aadb625ced91ac483390ebc10640cdf"http://localhost:4502/etc/replication/agents.author/replication99

エージェントの一時停止 pause-an-agent

curl -u <user>:<password> -F "cmd=pause" -F "name=publish"  http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json

エージェントキューのクリア clear-an-agent-queue

curl -u <user>:<password> -F "cmd=clear" -F "name=publish"  http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json

Communities communities

バッジの割り当てと取り消し assign-and-revoke-badges

詳しくは、コミュニティのスコアとバッジを参照してください。

詳しくは、スコアおよびバッジの基本事項を参照してください。

MSRP インデックス再作成 msrp-reindexing

詳しくは、MSRP - MongoDB ストレージリソースプロバイダーを参照してください。

セキュリティ security

CRX DE Lite の有効化および無効化 enabling-and-disabling-crx-de-lite

詳しくは、AEM で CRXDE Lite を有効にするを参照してください。

データストアのガベージコレクション data-store-garbage-collection

詳しくは、データストアのガベージコレクションを参照してください。

Analytics と Target の統合 analytics-and-target-integration

詳しくは、Adobe Analytics および Adobe Target との統合のオプトインを参照してください。

シングルサインオン single-sign-on

テストヘッダーの送信 send-test-header

詳しくは、シングルサインオンを参照してください。

一般的なコンテンツ操作の AEM cURL コマンド common-content-manipulation-aem-curl-commands

次に、コンテンツ操作の AEM cURL コマンドのリストを示します。

NOTE
次の例では、AEM が localhost のポート 4502 で実行され、ユーザー admin(パスワード admin)を使用していると仮定します。追加のコマンドのプレースホルダーは、山括弧で囲まれています。

ページを管理 page-management

ページのアクティベーション page-activation

curl -u <user>:<password> -X POST -F path="/content/path/to/page" -F cmd="activate" http://localhost:4502/bin/replicate.json

ページのアクティベーション解除 page-deactivation

curl -u <user>:<password> -X POST -F path="/content/path/to/page" -F cmd="deactivate" http://localhost:4502/bin/replicate.json

ツリーのアクティベーション tree-activation

curl -u <user>:<password> -F cmd=activate -F ignoredeactivated=true -F onlymodified=true -F path=/content/geometrixx http://localhost:4502/etc/replication/treeactivation.html

ページをロック lock-page

curl -u <user>:<password> -X POST -F cmd="lockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

ページをロック解除 unlock-page

curl -u <user>:<password> -X POST -F cmd="unlockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand

ページをコピー copy-page

curl -u <user>:<password> -F cmd=copyPage -F destParentPath=/path/to/destination/parent -F srcPath=/path/to/source/location http://localhost:4502/bin/wcmcommand

ワークフロー workflows

詳しくは、プログラムによるワークフローとのやり取りを参照してください。

Sling コンテンツ sling-content

フォルダーを作成 create-a-folder

curl -u <user>:<password> -F jcr:primaryType=sling:Folder http://localhost:4502/etc/test

ノードを削除 delete-a-node

curl -u <user>:<password> -F :operation=delete http://localhost:4502/etc/test/test.properties

ノードを移動 move-a-node

curl -u <user>:<password> -F":operation=move" -F":applyTo=/sourceurl"  -F":dest=/target/parenturl/" https://localhost:4502/content

ノードをコピー copy-a-node

curl -u <user>:<password> -F":operation=copy" -F":applyTo=/sourceurl"  -F":dest=/target/parenturl/" https://localhost:4502/content

Sling PostServlet の使用によるファイルのアップロード upload-files-using-sling-postservlet

curl -u <user>:<password> -F"*=@test.properties"  http://localhost:4502/etc/test

Sling PostServlet の使用およびノード名の指定によるファイルのアップロード upload-files-using-sling-postservlet-and-specifying-node-name

curl -u <user>:<password> -F"test2.properties=@test.properties"  http://localhost:4502/etc/test

コンテンツタイプを指定したファイルのアップロード upload-files-specifying-a-content-type

curl -u <user>:<password> -F "*=@test.properties;type=text/plain" http://localhost:4502/etc/test

アセットを操作 asset-manipulation

詳しくは、Assets HTTP API を参照してください。

recommendation-more-help
19ffd973-7af2-44d0-84b5-d547b0dffee2