export async function buildSecret()

in src/run.ts [55:148]


export async function buildSecret(
   secretName: string,
   namespace: string
): Promise<V1Secret> {
   // The secret type for the new secret
   const secretType: string = core.getInput('secret-type')

   const metaData: V1ObjectMeta = {
      name: secretName,
      namespace: namespace
   }

   const containerRegistryURL = core.getInput('container-registry-url')
   const containerRegistryUserName = core.getInput(
      'container-registry-username'
   )
   const containerRegistryPassword = core.getInput(
      'container-registry-password'
   )
   const containerRegistryEmail = core.getInput('container-registry-email')

   // Check if any container registry credentials are provided
   if (
      containerRegistryURL ||
      containerRegistryUserName ||
      containerRegistryPassword ||
      containerRegistryEmail
   ) {
      if (!containerRegistryURL) {
         core.setFailed(
            'container-registry-url is required when container-registry-username or container-registry-password is provided'
         )
      }
      if (!containerRegistryUserName) {
         core.setFailed(
            'container-registry-username is required when container-registry-url or container-registry-password is provided'
         )
      }
      if (!containerRegistryPassword) {
         core.setFailed(
            'container-registry-password is required when container-registry-url or container-registry-username or container-registry-email is provided'
         )
      }

      const dockerConfigJSON = buildContainerRegistryDockerConfigJSON(
         containerRegistryURL,
         containerRegistryUserName,
         containerRegistryPassword,
         containerRegistryEmail
      )
      const dockerConfigJSONString = JSON.stringify(dockerConfigJSON)
      const dockerConfigBase64 = Buffer.from(dockerConfigJSONString).toString(
         'base64'
      )

      const data = {
         '.dockerconfigjson': dockerConfigBase64
      }

      return {
         apiVersion: 'v1',
         kind: 'Secret',
         metadata: metaData,
         type: secretType,
         data: data
      }
   }

   // The serialized form of the secret data is a base64 encoded string
   let data: {[key: string]: string} = {}
   if (core.getInput('data')) {
      core.debug(`loading 'data' field`)
      data = JSON.parse(core.getInput('data'))
   }

   // The plaintext form of the secret data
   let stringData: {[key: string]: string} = {}
   if (core.getInput('string-data')) {
      core.debug(`loading 'string-data' field`)
      stringData = JSON.parse(core.getInput('string-data'))
   }

   // Create secret object for passing to the api
   core.debug(`creating V1Secret`)
   const secret: V1Secret = {
      apiVersion: 'v1',
      type: secretType,
      data: data,
      stringData: stringData,
      metadata: metaData
   }

   return secret
}