Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
feat(cli): make subject configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Oct 26, 2020
1 parent 95e0189 commit d84c057
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cli/commands/create-ca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CommandDefinition } from './CommandDefinition'
import { createCA } from '../jitp/createCA'
import { Iot, CloudFormation } from 'aws-sdk'
import { region } from '../../cdk/regions'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

export const createCACommand = ({
certsDir,
Expand All @@ -18,6 +19,7 @@ export const createCACommand = ({
certsDir,
iot,
cf,
stack: CORE_STACK_NAME,
log: (...message: any[]) => {
console.log(...message.map((m) => chalk.magenta(m)))
},
Expand Down
9 changes: 5 additions & 4 deletions cli/jitp/createCA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { promises as fs } from 'fs'
import { caFileLocations } from './caFileLocations'
import { run } from '../process/run'
import { toObject } from '@bifravst/cloudformation-helpers'
import { CORE_STACK_NAME } from '../../cdk/stacks/stackName'

/**
* Creates a CA certificate and registers it for Just-in-time provisioning
Expand All @@ -13,6 +12,8 @@ export const createCA = async (args: {
certsDir: string
iot: Iot
cf: CloudFormation
stack: string
subject?: string
log: (...message: any[]) => void
debug: (...message: any[]) => void
}): Promise<{ certificateId: string }> => {
Expand All @@ -39,11 +40,11 @@ export const createCA = async (args: {
const [stackOutput, registrationCode] = await Promise.all([
// Fetch the stack configuration, we need the Thing Group and the role name
cf
.describeStacks({ StackName: CORE_STACK_NAME })
.describeStacks({ StackName: args.stack })
.promise()
.then(async ({ Stacks }) => {
if (Stacks?.length === 0 || Stacks?.[0].Outputs === undefined) {
throw new Error(`Stack ${CORE_STACK_NAME} not found.`)
throw new Error(`Stack ${args.stack} not found.`)
}
return toObject(Stacks[0].Outputs)
}),
Expand Down Expand Up @@ -86,7 +87,7 @@ export const createCA = async (args: {
'-out',
caFiles.cert,
'-subj',
`/OU=${CORE_STACK_NAME}`,
`/OU=${args.subject ?? args.stack}`,
],
log: debug,
})
Expand Down

0 comments on commit d84c057

Please sign in to comment.