1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SAP Build Process Automation: 自作のAPIからActionを作る

Last updated at Posted at 2023-03-15

はじめに

この記事は、SAP Build Process AutomationでBTPのユーザ登録を自動化するシリーズの続きです。前回の記事では、Cloud Foundryにユーザ登録するためのAPIを作成しました。今回はこのAPIをSAP Build Process AutomationのActionとして使えるように設定を行います。

Actionとは

Process AutomationのフローからAPIを呼び出すときに使うものです。"Action"というオブジェクトを事前に作成し、使用するAPIのエンドポイントや、APIに渡す項目の事前設定をしておきます。使用しない項目は削除するなど、フローから使いやすいようにAPIをカスタマイズしておくことができます。
image.png

Actionの登録準備

Actionの登録に必要なものは2つです。

  • Destination
    Actionとして使えるようにするために、以下のプロパティを設定したDestinationを作成しておきます。
    sap.applicationdevelopment.actions.enabled: true
    sap.processautomation.enabled: true
    image.png
    作成したDestinationをProcess AutomationのSettings>Destinationsにも追加します。
    image.png

  • Open API仕様で記述したAPIの仕様
    Swaggerを使用してAPIの仕様を作成しました。
    image.png

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を選択してダウンロードします。
image.png

Actionの登録

1. Actionの登録

Process Automationのロビーからアクションを登録します。
image.png
ダウンロードしておいたAPI仕様を選択して登録します。
image.png
使用するエンドポイントを選択して(ここでは一つしかありませんが)追加します。
image.png

2. パラメータの設定

今回Cloud Foundryのロールは"SpaceDeveloper"のみを使用するので、固定値で設定します。
image.png

3. テスト

TestタブからAPIをテストします。Destinationを選択し、必要な項目を設定してテストを実行します。
image.png
ステータス200でレスポンスが返ってくればOKです。(APIはレスポンスのメッセージも返しているのですがなぜか表示されていません)
image.png

返しているはずのレスポンス

{
  "result": "Space user was addedded successfully."
}

4. アクションを公開

作成したアクションはリリース、公開することによってフローから使えるようになります(画像は別のアクションを使用しています)。

  • リリース
    image.png
  • 公開
    image.png

フローへのActionの組み込み

アクションを追加したい位置で+をクリックし、Actions>Brouse libraryを選択します。
image.png
公開したアクションを選択します。
image.png
フローにアクションが追加されます。
image.png
Destinaionとインプットを設定すれば完了です。
image.png
※Destinationはプロジェクトの環境変数として事前に作成しておいたものです
image.png

最終的なフローは以下のようになりました。
image.png

動作確認

フローを実行した結果、Cloud Foundryのスペースにユーザが登録されました。
image.png

今回追加したステップは正常に動いていましたが、後続のロールコレクション割当でエラーが起きました。
image.png
Destinationがらみのエラーのようです。以前は正常に動いており、Destinationの設定は変えていないので理由はわかりません。
image.png
エラーについてはSAP Communityに問い合わせ中です。
https://answers.sap.com/questions/13843304/build-process-automation-invalid-argument-type-of.html

1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?