Plan

El plan define el conjunto de interceptores que serán ejecutados en el API Gateway. Cada API puede tener varios planes, pero cada plan solo se ejecuta cuando está vinculado a una app o access token.

Agrupando interceptores en un plan, puede crear diferentes niveles de uso para sus APIs, estableciendo políticas de flujo distintas para cada nivel. Esto ofrece un mayor control sobre cómo diferentes tipos de usuarios acceden a sus APIs.

Aunque una API puede tener varios planes para diferentes controles de flujo, cada plan está vinculado a una única API.

Consulte la documentación de Planes para más detalles.

Estructura del archivo .yaml de Plan (comando apply)

apiVersion: api-management.sensedia.com/v1
kind: Plan
metadata:
  timestamp: "2024-04-16T17:06:24.046-03:00"
spec:
  name: Plan Sample
  apiRef:
    name: API Sample
    version: "1.0"
  description: Plan Sample
  default: true
  flows:
  - context:
      revision: all
      resourceRef:
        name: all
      operationRef:
        method: all
        path: /
    requestInterceptors:
    - restrictAccess:
        environmentRefs:
        - name: Sandbox
        type: Allow | Block
    - rateLimit:
        calls: 1000
        limitBy: IP
        interval: SECOND | MINUTE | HOUR | DAY | MONTH
        softLimit:
          enabled: true | false
          percentage: 0 | 100
        returnQuotaHeader: true
    - log:
        encryptContent: false | true
        encryptParams: false | true
    - logObfuscation:
        location: HEADER | BODY
        attribute: "lorem.ipsum"
        customRegex: .+
        replaceWith: "ipsum"
    - header:
        headers:
        - name: Content-Type
          type: CUSTOM
          value: application/json
    - xmlToJson:
        forceValueAsString: true | false
    - timeAllowed:
        timezone: America/Sao_Paulo
        hoursOfDayInUTC: 4|15
    - dataObfuscation:
        location: BODY
        customRegex: '"cnpj":".*"'
        replaceWith: '"cnpj":"**.***.***/****-**"'
    - destination:
        type: APP | ACCESS_TOKEN | CUSTOM
        value: "123"
    - httpMethod:
        method: POST
    responseInterceptors:
    - jsonToXml: {}
    - header:
        headers:
        - name: Content-Type
          type: CUSTOM
          value: text/xml

Uso

Si no especifica ningun flag, se activará el modo interactivo.
$ ssd (api-management | apim) get plan --name Plan Sample --api-name API Sample --api-version 1.0.0

Busca un plan con formato yaml
$ ssd api-management get plan --id 111 --output yaml

Busca un plan y lo guarda en un archivo yaml
$ ssd api-management get plan --id 111 --output yaml > plan.yaml

Schema de Plan (comando apply)

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "https://sensedia.com/cli/api-management/plan/apply",
  "type": "object",
  "properties": {
    "apiVersion": {
      "type": "string",
      "enum": [
        "api-management.sensedia.com/v1"
      ]
    },
    "kind": {
      "type": "string",
      "enum": [
        "Plan"
      ]
    },
    "metadata": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "spec": {
      "additionalProperties": false,
      "type": "object",
      "required": [
        "name",
        "apiRef"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "apiRef": {
          "$ref": "#/$defs/apiRef"
        },
        "default": {
          "type": "boolean"
        },
        "flows": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/flow"
          }
        }
      }
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "spec"
  ],
  "$defs": {
    "apiRef": {
      "additionalProperties": false,
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "version": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "version"
      ]
    },
    "namedRef": {
      "additionalProperties": false,
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ]
    },
    "requestInterceptor": {
      "type": "object",
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "ipFiltering": {
              "$ref": "#/$defs/ipFilteringInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "log": {
              "$ref": "#/$defs/logInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "rateLimit": {
              "$ref": "#/$defs/rateLimitInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "restrictAccess": {
              "$ref": "#/$defs/restrictAccessInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "mock": {
              "$ref": "#/$defs/mockInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "timeAllowed": {
              "$ref": "#/$defs/timeAllowedInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "header": {
              "$ref": "#/$defs/headerInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "destination": {
              "$ref": "#/$defs/destinationInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "httpMethod": {
              "$ref": "#/$defs/httpMethodInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "logObfuscation": {
              "$ref": "#/$defs/logObfuscationInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "dataObfuscation": {
              "$ref": "#/$defs/dataObfuscationInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "spikeArrest": {
              "$ref": "#/$defs/spikeArrestInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "jsonToTxt": {
              "$ref": "#/$defs/jsonToTxtInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "jsonToXml": {
              "$ref": "#/$defs/jsonToXmlInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "txtToJson": {
              "$ref": "#/$defs/txtToJsonInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "xmlToJson": {
              "$ref": "#/$defs/xmlToJsonInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "payloadSize": {
              "$ref": "#/$defs/payloadSizeInterceptor"
            }
          }
        }
      ]
    },
    "responseInterceptor": {
      "type": "object",
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "ipFiltering": {
              "$ref": "#/$defs/ipFilteringInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "log": {
              "$ref": "#/$defs/logInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "header": {
              "$ref": "#/$defs/headerInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "httpMethod": {
              "$ref": "#/$defs/httpMethodInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "logObfuscation": {
              "$ref": "#/$defs/logObfuscationInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "dataObfuscation": {
              "$ref": "#/$defs/dataObfuscationInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "jsonToTxt": {
              "$ref": "#/$defs/jsonToTxtInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "jsonToXml": {
              "$ref": "#/$defs/jsonToXmlInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "txtToJson": {
              "$ref": "#/$defs/txtToJsonInterceptor"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "xmlToJson": {
              "$ref": "#/$defs/xmlToJsonInterceptor"
            }
          }
        }
      ]
    },
    "flow": {
      "additionalProperties": false,
      "type": "object",
      "properties": {
        "context": {
          "oneOf": [
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "revision": {
                  "type": "string"
                },
                "resourceRef": {
                  "$ref": "#/$defs/namedRef"
                },
                "operationRef": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "method": {
                      "type": "string",
                      "enum": [
                        "GET",
                        "POST",
                        "PATCH",
                        "PUT",
                        "DELETE",
                        "OPTIONS",
                        "all"
                      ]
                    },
                    "path": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "method",
                    "path"
                  ]
                }
              },
              "required": [
                "revision",
                "resourceRef",
                "operationRef"
              ]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "revision": {
                  "type": "number",
                  "format": "int"
                },
                "resourceRef": {
                  "$ref": "#/$defs/namedRef"
                }
              },
              "required": [
                "revision",
                "resourceRef"
              ]
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "revision": {
                  "type": "number",
                  "format": "int"
                }
              },
              "required": [
                "revision"
              ]
            }
          ]
        },
        "requestInterceptors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/requestInterceptor"
          }
        },
        "responseInterceptors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/responseInterceptor"
          }
        }
      }
    },
    "ipFilteringInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "ips": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "type": {
          "type": "string",
          "enum": [
            "Allow",
            "Block"
          ]
        }
      },
      "required": [
        "ips",
        "type"
      ]
    },
    "logInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "encryptContent": {
          "type": "boolean"
        },
        "encryptParams": {
          "type": "boolean"
        }
      }
    },
    "oauthInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "allowedGrantTypes": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "AuthorizationCode",
              "Implicit",
              "ClientCredentials",
              "Password",
              "JWT"
            ]
          }
        }
      }
    },
    "rateLimitInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "calls": {
          "type": "integer"
        },
        "limitBy": {
          "type": "string",
          "enum": [
            "TOTAL_CALLS",
            "IP"
          ]
        },
        "interval": {
          "type": "string",
          "enum": [
            "SECOND",
            "MINUTE",
            "HOUR",
            "DAY",
            "MONTH"
          ]
        },
        "softLimit": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "percentage": {
              "type": "integer"
            }
          }
        },
        "returnQuotaHeader": {
          "type": "boolean"
        }
      },
      "required": [
        "calls",
        "interval",
        "limitBy"
      ]
    },
    "restrictAccessInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "environmentRefs": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/namedRef"
          }
        },
        "type": {
          "type": "string",
          "enum": [
            "Allow",
            "Block"
          ]
        }
      },
      "required": [
        "environmentRefs",
        "type"
      ]
    },
    "mockInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "headers": {
          "type": "array",
          "items": {
            "properties": {
              "key": {
                "type": "string"
              },
              "value": {
                "type": "string"
              }
            },
            "required": [
              "key",
              "value"
            ]
          }
        },
        "statusCode": {
          "type": "integer"
        },
        "body": {
          "type": "string"
        }
      },
      "required": [
        "statusCode"
      ]
    },
    "timeAllowedInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "timezone": {
          "type": "string"
        },
        "hoursOfDayInUTC": {
          "type": "string"
        }
      },
      "required": [
        "timezone",
        "hoursOfDayInUTC"
      ]
    },
    "headerInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "headers": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "APP",
                  "ACCESS_TOKEN",
                  "CUSTOM"
                ]
              },
              "value": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "type",
              "value"
            ]
          }
        }
      }
    },
    "destinationInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "APP",
            "ACCESS_TOKEN",
            "CUSTOM"
          ]
        },
        "value": {
          "type": "string"
        },
        "urlType": {
          "type": "string",
          "enum": [
            "ENTIRE_URL",
            "HOST"
          ]
        }
      },
      "required": [
        "type",
        "value"
      ]
    },
    "httpMethodInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "method": {
          "type": "string",
          "enum": [
            "GET",
            "POST",
            "PUT",
            "DELETE"
          ]
        }
      },
      "required": [
        "method"
      ]
    },
    "logObfuscationInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "location": {
          "type": "string",
          "enum": [
            "HEADER",
            "BODY"
          ]
        },
        "attribute": {
          "type": "string"
        },
        "customRegex": {
          "type": "string"
        },
        "replaceWith": {
          "type": "string"
        }
      },
      "required": [
        "location",
        "replaceWith"
      ]
    },
    "dataObfuscationInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "location": {
          "type": "string",
          "enum": [
            "HEADER",
            "BODY"
          ]
        },
        "attribute": {
          "type": "string"
        },
        "customRegex": {
          "type": "string"
        },
        "replaceWith": {
          "type": "string"
        }
      },
      "required": [
        "location",
        "replaceWith"
      ]
    },
    "spikeArrestInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "limit": {
          "type": "integer"
        },
        "interval": {
          "type": "string",
          "enum": [
            "SECOND",
            "MINUTE",
            "HOUR"
          ]
        }
      },
      "required": [
        "limit",
        "interval"
      ]
    },
    "jsonToTxtInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {}
    },
    "jsonToXmlInterceptor": {},
    "txtToJsonInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {}
    },
    "xmlToJsonInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "forceValueAsString": {
          "type": "boolean"
        }
      }
    },
    "payloadSizeInterceptor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "maximumSizeKBytes": {
          "type": "integer"
        }
      },
      "required": ["maximumSizeKBytes"]
    }
  }
}
Thanks for your feedback!
EDIT

Share your suggestions with us!
Click here and then [+ Submit idea]