Skip to content

Commit

Permalink
fix: use client id from sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mbystedt committed Sep 24, 2024
1 parent 93eafd4 commit 1e29486
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 30 deletions.
22 changes: 22 additions & 0 deletions generators/gh-maven-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ export default class extends Generator {
this.log(
' ' + chalk.dim('Example: super-project-backend-war'),
);
this.log(
' ' +
chalk.bold('Client ID: ') +
chalk.dim(
'The client id of the Broker account to use. Leave blank to use manually set BROKER_JWT secret.',
),
);
this.log(
' ' +
chalk.bold('Artifactory: ') +
Expand Down Expand Up @@ -128,6 +135,13 @@ export default class extends Generator {
message: 'Service:',
store: true,
},
{
type: 'input',
name: 'clientId',
message: 'Client ID:',
default: '',
store: true,
},
{
type: 'input',
name: 'pomRoot',
Expand Down Expand Up @@ -233,12 +247,19 @@ export default class extends Generator {

// Generate GitHub workflows and NR Broker intention files
writingWorkflow() {
const brokerJwt = this.answers.clientId.trim()
? `broker-jwt:${this.answers.clientId.trim()}`.replace(
/[^a-zA-Z0-9_]/g,
'_',
)
: 'BROKER_JWT';
this.fs.copyTpl(
this.templatePath('build-release.yaml'),
this.destinationPath('.github/workflows/build-release.yaml'),
{
projectName: this.answers.projectName,
serviceName: this.answers.serviceName,
brokerJwt,
artifactoryProject: this.answers.artifactoryProject,
pomRoot: this.answers.pomRoot,
unitTestsPath: this.answers.unitTestsPath,
Expand Down Expand Up @@ -266,6 +287,7 @@ export default class extends Generator {
{
projectName: this.answers.projectName,
serviceName: this.answers.serviceName,
brokerJwt,
artifactoryProject: this.answers.artifactoryProject,
pomRoot: this.answers.pomRoot,
gitHubPackages: this.answers.gitHubPackages,
Expand Down
4 changes: 2 additions & 2 deletions generators/gh-maven-build/templates/build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:

env:
BROKER_URL: https://broker.io.nrs.gov.bc.ca
BROKER_JWT: ${{ secrets.BROKER_JWT }}
BROKER_JWT: ${{ secrets.<%= brokerJwt %> }}
SERVICE_PROJECT: <%= projectName %>
SERVICE_NAME: <%= serviceName %>

Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
- name: Open intention
uses: bcgov-nr/action-broker-intention-open@v2
with:
broker_jwt: ${{ secrets.BROKER_JWT }}
broker_jwt: ${{ secrets.<%= brokerJwt %> }}
intention_path: intention.json
quickstart: true
- name: Set intention ID for deployment job
Expand Down
4 changes: 2 additions & 2 deletions generators/gh-maven-build/templates/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
echo "artifact_sha256=${artifact_checksum#sha256:}" >> $GITHUB_OUTPUT
env:
BROKER_URL: https://broker.io.nrs.gov.bc.ca
BROKER_JWT: ${{ secrets.BROKER_JWT }}
BROKER_JWT: ${{ secrets.<%= brokerJwt %> }}
SERVICE_PROJECT: ${{ env.SERVICE_PROJECT }}
SERVICE_NAME: ${{ env.SERVICE_NAME }}
GITHUB_SHA: ${{ github.sha }}
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
echo "artifact_sha256=${artifact_checksum#sha256:}" >> $GITHUB_OUTPUT
env:
BROKER_URL: https://broker.io.nrs.gov.bc.ca
BROKER_JWT: ${{ secrets.BROKER_JWT }}
BROKER_JWT: ${{ secrets.<%= brokerJwt %> }}
SERVICE_PROJECT: ${{ env.SERVICE_PROJECT }}
SERVICE_NAME: ${{ env.SERVICE_NAME }}
- name: Checkout repository
Expand Down
4 changes: 4 additions & 0 deletions generators/util/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export const pathToProps = [
],
prop: 'addWebadeConfig',
},
{
path: ['metadata', 'annotations', 'playbook.io.nrs.gov.bc.ca/clientId'],
prop: 'clientId',
},
];

export function extractFromYaml(doc, pathToProps) {
Expand Down
84 changes: 62 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
"test": "jest"
},
"dependencies": {
"yaml": "^2.5.0",
"yaml": "^2.5.1",
"yeoman-generator": "^7.3.2",
"yosay": "^3.0.0"
},
"devDependencies": {
"eslint": "^9.8.0",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"lint-staged": "^15.2.8",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"yeoman-assert": "^3.1.1",
"yeoman-test": "^9.0.0"
"yeoman-test": "^9.1.0"
},
"type": "module",
"license": "Apache-2.0"
Expand Down

0 comments on commit 1e29486

Please sign in to comment.