import { getInput , warning as logWarning , setFailed , setOutput , setSecret } from '@actions/core' ; import { Credential , parseCredential , errorMessage } from '@google-github-actions/actions-utils' ; import { Client } from './client' ; import { parseSecretsRefs } from './reference' ; /**
 * Executes the main action. It includes the main business logic and is the
 * primary entry point. It is documented inline.
 */ async function run ( ) { try { const secretsInput = getInput ( 'secrets' , { required : true } ) ; const credentials = getInput ( 'credentials' ) ; let credentialsJSON ; if ( credentials ) { logWarning ( 'The "credentials" input is deprecated. ' + 'Please switch to using google-github-actions/auth which supports both Workload Identity Federation and JSON Key authentication. ' + 'For more details, see https://github.com/google-github-actions/get-secretmanager-secrets#authorization' ) ; credentialsJSON = parseCredential ( credentials ) ; } const client = new Client ( { credentials : credentialsJSON , } ) ; const secretsRefs = parseSecretsRefs ( secretsInput ) ; for ( const ref of secretsRefs ) { const value = await client . accessSecret ( ref . selfLink ( ) ) ; value . split ( /\r\n|\r|\n/g ) . forEach ( ( line ) => setSecret ( line ) ) ; setOutput ( ref . output , value ) ; } } catch ( err ) { const msg = errorMessage ( err ) ; setFailed ( `google-github-actions/get-secretmanager-secrets failed with: ${ msg }` ) ; } } run ( ) ;