1414 * limitations under the License.
1515 */
1616
17+ import { posix } from 'path' ;
18+
1719import {
1820 getBooleanInput ,
1921 getInput ,
@@ -24,7 +26,13 @@ import {
2426} from '@actions/core' ;
2527import { ExternalAccountClientOptions } from 'google-auth-library' ;
2628
27- import { CloudFunctionsClient , CloudFunction } from './client' ;
29+ import {
30+ CloudFunction ,
31+ CloudFunctionsClient ,
32+ SecretEnvVar ,
33+ SecretVolume ,
34+ } from './client' ;
35+ import { SecretName } from './secret' ;
2836import {
2937 errorMessage ,
3038 isServiceAccountKey ,
@@ -72,6 +80,11 @@ async function run(): Promise<void> {
7280 ) ;
7381 const buildWorkerPool = presence ( getInput ( 'build_worker_pool' ) ) ;
7482
83+ const secretEnvVars = parseKVString (
84+ getInput ( 'secret_environment_variables' ) ,
85+ ) ;
86+ const secretVols = parseKVString ( getInput ( 'secret_volumes' ) ) ;
87+
7588 const dockerRepository = presence ( getInput ( 'docker_repository' ) ) ;
7689 const kmsKeyName = presence ( getInput ( 'kms_key_name' ) ) ;
7790
@@ -127,19 +140,56 @@ async function run(): Promise<void> {
127140 ) ;
128141 }
129142
143+ // Build environment variables.
144+ const buildEnvironmentVariables = parseKVStringAndFile (
145+ buildEnvVars ,
146+ buildEnvVarsFile ,
147+ ) ;
148+ const environmentVariables = parseKVStringAndFile ( envVars , envVarsFile ) ;
149+
150+ // Build secret environment variables.
151+ const secretEnvironmentVariables : SecretEnvVar [ ] = [ ] ;
152+ if ( secretEnvVars ) {
153+ for ( const [ key , value ] of Object . entries ( secretEnvVars ) ) {
154+ const secretRef = new SecretName ( value ) ;
155+ secretEnvironmentVariables . push ( {
156+ key : key ,
157+ projectId : secretRef . project ,
158+ secret : secretRef . name ,
159+ version : secretRef . version ,
160+ } ) ;
161+ }
162+ }
163+
164+ // Build secret volumes.
165+ const secretVolumes : SecretVolume [ ] = [ ] ;
166+ if ( secretVols ) {
167+ for ( const [ key , value ] of Object . entries ( secretVols ) ) {
168+ const mountPath = posix . dirname ( key ) ;
169+ const pth = posix . basename ( key ) ;
170+
171+ const secretRef = new SecretName ( value ) ;
172+ secretVolumes . push ( {
173+ mountPath : mountPath ,
174+ projectId : secretRef . project ,
175+ secret : secretRef . name ,
176+ versions : [
177+ {
178+ path : pth ,
179+ version : secretRef . version ,
180+ } ,
181+ ] ,
182+ } ) ;
183+ }
184+ }
185+
130186 // Create Cloud Functions client
131187 const client = new CloudFunctionsClient ( {
132188 projectID : projectID ,
133189 location : region ,
134190 credentials : credentialsJSON ,
135191 } ) ;
136192
137- const buildEnvironmentVariables = parseKVStringAndFile (
138- buildEnvVars ,
139- buildEnvVarsFile ,
140- ) ;
141- const environmentVariables = parseKVStringAndFile ( envVars , envVarsFile ) ;
142-
143193 // Create Function definition
144194 const cf : CloudFunction = {
145195 name : name ,
@@ -156,6 +206,8 @@ async function run(): Promise<void> {
156206 labels : labels ,
157207 maxInstances : maxInstances ? + maxInstances : undefined ,
158208 minInstances : minInstances ? + minInstances : undefined ,
209+ secretEnvironmentVariables : secretEnvironmentVariables ,
210+ secretVolumes : secretVolumes ,
159211 serviceAccountEmail : serviceAccountEmail ,
160212 timeout : `${ timeout } s` ,
161213 vpcConnector : vpcConnector ,
0 commit comments