Last active
December 4, 2019 15:00
-
-
Save marcelosousa/916449bbe31a98511e231c1fb4e8556e to your computer and use it in GitHub Desktop.
Google cloud function deployment with protobot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createProbot } = require('probot'); | |
async function dec() { | |
const kms = require('@google-cloud/kms'); | |
const client = new kms.KeyManagementServiceClient(); | |
const ciphertext = "asdadkjasdCASDASdlkjasdasd11"; | |
const name = 'projects/PROJECT-ID/locations/global/keyRings/KEY-NAME/cryptoKeys/CRYPTO-NAME'; | |
const [result] = await client.decrypt({name, ciphertext}); | |
return result.plaintext.toString('ascii'); | |
} | |
appFn = app => { | |
console.log('Yay, the app was loaded!') | |
app.on('issues.opened', async context => { | |
const params = context.issue({ body: 'Hello World!' }) | |
// Post a comment on the issue | |
return context.github.issues.createComment(params) | |
}) | |
} | |
serverless = (apps, options) => { | |
return () => dec().then(function(sec) { | |
const opts = { | |
id: 11111, | |
secret: sec, | |
cert: "" | |
}; | |
const probot = createProbot(opts) | |
apps = [].concat(apps) // Coerce to array | |
apps.forEach(a => probot.load(a)) | |
return probot.server | |
}) | |
} | |
exports.protobot = serverless(appFn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment