# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

---

paths:

  /metalakes/{metalake}/objects/{metadataObjectType}/{metadataObjectFullName}/credentials:
    parameters:
      - $ref: "./openapi.yaml#/components/parameters/metalake"
      - $ref: "./openapi.yaml#/components/parameters/metadataObjectType"
      - $ref: "./openapi.yaml#/components/parameters/metadataObjectFullName"
    get:
      tags:
        - credentials
      summary: Get credentials
      operationId: getCredentials
      responses:
        "200":
          description: Returns the list of credential objects associated with specified metadata object.
          content:
            application/vnd.gravitino.v1+json:
              schema:
                $ref: "#/components/responses/CredentialResponse"
              examples:
                CredentialResponse:
                  $ref: "#/components/examples/CredentialResponse"
        "400":
          $ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse"
        "404":
          description: Not Found - The specified metalake does not exist
          content:
            application/vnd.gravitino.v1+json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
              examples:
                NoSuchMetalakeException:
                  $ref: "./metalakes.yaml#/components/examples/NoSuchMetalakeException"
        "5xx":
          $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"


components:
  schemas:
    Credential:
      type: object
      description: A credential
      required:
        - credentialType
        - expireTimeInMs
        - credentialInfo
      properties:
        credentialType:
          type: string
          description: The type of the credential, for example, s3-token, s3-secret-key, oss-token, oss-secret-key, gcs-token, adls-token, azure-account-key, etc.
        expireTimeInMs:
          type: integer
          description: The expiration time of the credential in milliseconds since the epoch, 0 means not expire.
        credentialInfo:
          type: object
          description: The specific information of the credential.
          default: { }
          additionalProperties:
            type: string

  responses:
    CredentialResponse:
      type: object
      properties:
        code:
          type: integer
          format: int32
          description: Status code of the response
          enum:
            - 0
        credentials:
          type: array
          description: A list of credential objects
          items:
            $ref: "#/components/schemas/Credential"

  examples:
    CredentialResponse:
      value: {
        "code": 0,
        "credentials": [
          {
            "credentialType": "s3-token",
            "expireTimeInMs": 1735891948411,
            "credentialInfo": {
              "s3-access-key-id": "value1",
              "s3-secret-access-key": "value2",
              "s3-session-token": "value3"
            }
          },
          {
            "credentialType": "s3-secret-key",
            "expireTimeInMs": 0,
            "credentialInfo": {
              "s3-access-key-id": "value1",
              "s3-secret-access-key": "value2"
            }
          },
        ]
      }