2
0

[IRNA] APIレスポンスのヘッダーとContent-Typeの変更方法

Last updated at Posted at 2024-07-19

はじめに

IBM Rapid Network Automation (IRNA)のデフォルト設定では、APIレスポンスのヘッダーに任意のヘッダーを付与できず、メディア・タイプ (Content-Typeヘッダー) が「application/json」で固定になっています。

この記事では、APIの応答ヘッダーとメディア・タイプを変更するための設定方法を紹介します。

デフォルトのAPI応答の構成画面

APIの応答は、Workflowのデプロイ画面のCustom Response Configurationで定義します。デフォルトの設定では応答としてマッピングできるのは、Status Code, Body, Formatの3項目のみとなっています。
CustomResponse Configuration_default.png

環境変数の設定

製品マニュアルの「Implicit response configuration」の記載に従って、rna-core-pliant-frontrna-core-pliant-app-gatewayの2つDeploymentに対して環境変数ENABLE_INSECURE_MAPPINGS定義を追加し、値に1をセットします。(デフォルトでは該当環境変数定義はなく無効になっています。)

Deploymentの編集

以下のコマンドでDeployment rna-core-pliant-frontを直接編集し、ENABLE_INSECURE_MAPPINGS=1を追加します。

[root@rna ~]# kubectl -n rna-core edit deployment rna-core-pliant-front
rna-core-pliant-front
... (omit)
spec:
  ... (omit)
  template:
    ... (omit)
    spec:
      containers:
      - env:
        - name: ENABLE_INSECURE_MAPPINGS         ### 追記 ###
          value: "1"                                                    ### 追記 ###
        - name: WHITELABELING_DEFAULT_TO_EMPTY
          value: "1"
... (omit)

変更を保存すると下記Podが再起動されるので、正常起動されたことを確認します。

[root@rna ~]# kubectl -n rna-core get pod | grep front
rna-core-pliant-front-7797558cdb-qxxpq                  1/1     Running     0             25s
rna-core-pliant-front-7797558cdb-p52bc                  1/1     Running     0             25s

同様に、rna-core-pliant-app-gatewayにも環境変数を追加し保存します。

rna-core-pliant-app-gateway
... (omit)
spec:
  ... (omit)
  template:
    ... (omit)
    spec:
      containers:
      - env:
        - name: ENABLE_INSECURE_MAPPINGS       ### 追記 ###
          value: "1"                                                  ### 追記 ###
        - name: API_URI
          value: http://pliant-api:8080
        ... (omit)

変更を保存すると下記Podが再起動されるので、正常起動されたことを確認します。

[root@rna ~]# kubectl -n rna-core get pod | grep app
rna-core-pliant-app-gateway-8679965d7c-4cgc4            1/1     Running     0             36s

環境変数設定後のAPI応答の構成画面

再度Workflowのデプロイ画面のCustom Response Configurationを開くと、HeadersContent-Typeの項目が追加され、設定できるようになりました。
CustomResponse Configuration_after-settings.png

任意の応答ヘッダーを定義したい場合は、ワークフロー内でobject形式で変数を定義し、Headersでその変数を選択します。
Content-Typeは以下のリストから値を選択可能です。

Content-Typeの選択肢
application/json
application/xml
application/octet-stream
application/zip
application/gzip
image/png
image/svg+xml
image/x-icon
text/css
text/html
text/javascript
text/plain

以上、APIの応答ヘッダーとメディア・タイプを変更するための設定方法の紹介でした。

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