はじめに
この記事は、SAP Build Process AutomationでBTPのユーザ登録を自動化するシリーズの続きです。前回の記事では、Cloud Foundryにユーザ登録するためのAPIを作成しました。今回はこのAPIをSAP Build Process AutomationのActionとして使えるように設定を行います。
Actionとは
Process AutomationのフローからAPIを呼び出すときに使うものです。"Action"というオブジェクトを事前に作成し、使用するAPIのエンドポイントや、APIに渡す項目の事前設定をしておきます。使用しない項目は削除するなど、フローから使いやすいようにAPIをカスタマイズしておくことができます。
Actionの登録準備
Actionの登録に必要なものは2つです。
-
Destination
Actionとして使えるようにするために、以下のプロパティを設定したDestinationを作成しておきます。
sap.applicationdevelopment.actions.enabled: true
sap.processautomation.enabled: true
作成したDestinationをProcess AutomationのSettings>Destinationsにも追加します。
-
Open API仕様で記述したAPIの仕様
Swaggerを使用してAPIの仕様を作成しました。
openapi: 3.0.0
info:
description: Execute Cloud Foundry command
version: "1.0.0"
title: Cloud foundry command
paths:
/spaceuser:
post:
operationId: addSpaceUser
description: Adds a user to Cloud foundry space
responses:
'200':
description: space user was added
content:
application/json:
schema:
type: object
items:
$ref: '#/components/schemas/Response'
example:
result: 'Space user was addedded successfully.'
'400':
description: 'invalid input, object invalid'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UserRole'
description: User and role to add
components:
schemas:
UserRole:
type: object
properties:
user:
type: string
role:
type: string
description: User and space role
Response:
type: object
properties:
result:
type: string
servers:
# Added by API Auto Mocking Plugin
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/MIOFUJITA01/cfcommand/1.0.0
作成した仕様を Export> Download API> JSON Resolvedを選択してダウンロードします。
Actionの登録
1. Actionの登録
Process Automationのロビーからアクションを登録します。
ダウンロードしておいたAPI仕様を選択して登録します。
使用するエンドポイントを選択して(ここでは一つしかありませんが)追加します。
2. パラメータの設定
今回Cloud Foundryのロールは"SpaceDeveloper"のみを使用するので、固定値で設定します。
3. テスト
TestタブからAPIをテストします。Destinationを選択し、必要な項目を設定してテストを実行します。
ステータス200でレスポンスが返ってくればOKです。(APIはレスポンスのメッセージも返しているのですがなぜか表示されていません)
返しているはずのレスポンス
{
"result": "Space user was addedded successfully."
}
4. アクションを公開
作成したアクションはリリース、公開することによってフローから使えるようになります(画像は別のアクションを使用しています)。
フローへのActionの組み込み
アクションを追加したい位置で+をクリックし、Actions>Brouse libraryを選択します。
公開したアクションを選択します。
フローにアクションが追加されます。
Destinaionとインプットを設定すれば完了です。
※Destinationはプロジェクトの環境変数として事前に作成しておいたものです
動作確認
フローを実行した結果、Cloud Foundryのスペースにユーザが登録されました。
今回追加したステップは正常に動いていましたが、後続のロールコレクション割当でエラーが起きました。
Destinationがらみのエラーのようです。以前は正常に動いており、Destinationの設定は変えていないので理由はわかりません。
エラーについてはSAP Communityに問い合わせ中です。
https://answers.sap.com/questions/13843304/build-process-automation-invalid-argument-type-of.html