Skip to content

Commit

Permalink
fix: 🐛 clean secret
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Sep 25, 2020
1 parent 2e617c8 commit 7549b8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ export namespace Action {
export async function run() {
try {
const token = await Util.getAppToken()
await Util.saveAppTokenToSecret(token)
core.info('Token generated!')
const secretName = core.getInput('SECRET_NAME')
if (secretName) {
await Util.saveAppTokenToSecret(secretName, token)
core.info(`Token save in secret "${secretName}"`)
}
core.setSecret(token)
core.setOutput('token', token)
core.info('Token generated!')
} catch (e) {
core.error(e)
core.setFailed(e.message)
Expand All @@ -17,8 +21,11 @@ export namespace Action {

export async function cleanup() {
try {
await Util.removeAppTokenFromSecret()
core.info('Token cleaned!')
const secretName = core.getInput('SECRET_NAME')
if (secretName) {
await Util.removeAppTokenFromSecret(secretName)
core.info(`Token in secret "${secretName}" was cleaned`)
}
} catch (e) {
core.error(e)
core.setFailed(e.message)
Expand Down
11 changes: 6 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { context, getOctokit } from '@actions/github'
import { Octokit } from '@octokit/core'
import { getInput } from '@actions/core'
import { Octokit } from '@octokit/core'
import { App } from '@octokit/app'
import isBase64 from 'is-base64'
import sodium from 'tweetsodium'
Expand All @@ -24,15 +24,16 @@ export namespace Util {
})
}

export async function saveAppTokenToSecret(token: string) {
const secretName = getInput('SECRET_NAME')
export async function saveAppTokenToSecret(
secretName: string,
token: string,
) {
if (secretName) {
return createOrUpdateRepoSecret(token, secretName, token)
}
}

export async function removeAppTokenFromSecret() {
const secretName = getInput('SECRET_NAME')
export async function removeAppTokenFromSecret(secretName: string) {
if (secretName) {
const token = await getAppToken()
return Util.deleteSecret(token, secretName)
Expand Down

0 comments on commit 7549b8e

Please sign in to comment.