Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
"sinon": "^8.1.1",
"standard-version": "^9.3.1"
},
"peerDependencies": {
"serverless": "2 || 3"
},
"scripts": {
"commitlint": "commitlint -f HEAD@{15}",
"commitlint:pull-request": "commitlint -f HEAD~1",
Expand Down
33 changes: 26 additions & 7 deletions provider/googleProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,35 @@ class GoogleProvider {
cloudfunctions: google.cloudfunctions('v1'),
};

this.configurationVariablesSources = {
gs: {
async resolve({ address }) {
if (!address) {
throw new serverless.classes.Error(
'Missing address argument in variable "gs" source',
'GOOGLE_CLOUD_MISSING_GS_VAR ADDRESS'
);
}
const groups = address.split('/');
const bucket = groups.shift();
const object = groups.join('/');
return { value: await this.gsValue({ bucket, object }) };
},
},
};

// TODO: Remove with next major
this.variableResolvers = {
gs: this.getGsValue,
gs: (variableString) => {
const groups = variableString.split(':')[1].split('/');
const bucket = groups.shift();
const object = groups.join('/');
return this.gsValue({ bucket, object });
},
};
}

getGsValue(variableString) {
const groups = variableString.split(':')[1].split('/');
const bucket = groups.shift();
const object = groups.join('/');

async getGsValue({ bucket, object }) {
return this.serverless
.getProvider('google')
.request('storage', 'objects', 'get', {
Expand All @@ -173,7 +192,7 @@ class GoogleProvider {
alt: 'media',
})
.catch((err) => {
throw new Error(`Error getting value for ${variableString}. ${err.message}`);
throw new Error(`Error getting value for ${bucket}/${object}. ${err.message}`);
});
}

Expand Down