Skip to content

Commit

Permalink
feat(new): create Cloudflare Turnstile instance for iroots new
Browse files Browse the repository at this point in the history
  • Loading branch information
codepuncher committed Aug 21, 2024
1 parent 41b45eb commit 7d2f1f4
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import {createApiKey} from '../lib/sendgrid.js'
import {createToken} from '../lib/packagist.js'
import {
cloneEnvironment,
createSite,
createSite as createKinstaSite,
getSite,
getSiteEnvironments,
setPhpVersion,
envNamesToCloneEnvironmentArgs,
} from '../lib/kinsta.js'
import {createProject, getAllProjectKeys} from '../lib/sentry.js'
import {createSite as createTurnstileSite} from '../lib/cloudflare.js'

type QAndA = {
from: string
Expand Down Expand Up @@ -238,6 +239,7 @@ export default class New extends Command {
description: 'The API key',
env: 'IROOTS_SENTRY_API_KEY',
required: true,
dependsOn: ['sentry'],
}),
sentry_organisation_slug: Flags.string({
required: true,
Expand Down Expand Up @@ -276,7 +278,7 @@ export default class New extends Command {
relationships: [
{
type: 'some',
flags: ['kinsta', 'sentry'],
flags: ['kinsta', 'sentry', 'turnstile'],
},
],
}),
Expand All @@ -287,6 +289,23 @@ export default class New extends Command {
default: true,
allowNo: true,
}),
turnstile: Flags.boolean({
description: 'whether or not to create a Clouflare Turnstile instance',
default: true,
allowNo: true,
}),
turnstile_api_key: Flags.string({
description: 'The API key',
env: 'IROOTS_CLOUDFLARE_API_KEY',
required: true,
dependsOn: ['turnstile'],
}),
turnstile_account: Flags.string({
description: 'The account identifier',
required: true,
env: 'IROOTS_CLOUDFLARE_ACCOUNT_ID',
dependsOn: ['turnstile'],
}),
}

// eslint-disable-next-line no-warning-comments
Expand Down Expand Up @@ -337,6 +356,9 @@ export default class New extends Command {
sentry_project_default_rules,
display_name,
wp_ssh_aliases,
turnstile,
turnstile_account,
turnstile_api_key,
} = flags

if (existsSync(site)) {
Expand All @@ -354,7 +376,7 @@ export default class New extends Command {
if (kinsta) {
const secondsToWait = 10
ux.action.start('Creating Kinsta site live environment')
const createSiteResponse = await createSite(kinsta_api_key, {
const createSiteResponse = await createKinstaSite(kinsta_api_key, {
company: kinsta_company,
display_name: display_name,
region: 'europe-west2',
Expand Down Expand Up @@ -461,6 +483,37 @@ export default class New extends Command {
ux.action.stop()
}

if (turnstile) {
ux.action.start('Creating Turnstile instance')

const domains = [
process.env.IROOTS_NEW_xxxDEV_DOMAINxxx,
process.env.IROOTS_NEW_xxxSTAGING_DOMAINxxx,
process.env.IROOTS_NEW_xxxUAT_DOMAINxxx,
process.env.IROOTS_NEW_xxxLIVE_DOMAINxxx,
].filter(Boolean)
const createTurnstileSiteResponse = await createTurnstileSite(turnstile_api_key, turnstile_account, {
bot_fight_mode: false,
clearance_level: 'no_clearance',
domains,
mode: 'managed',
name: display_name,
offlabel: false,
region: 'world',
})
if (createTurnstileSiteResponse) {
const {sitekey, secret} = createTurnstileSiteResponse

ux.info(`Cloudflare Turnstile siteKey: ${sitekey}`)
ux.info(`Cloudflare Turnstile secret: ${secret}`)

process.env.IROOTS_NEW_xxxCLOUDFLARE_TURNSTILE_SITE_KEY = sitekey
process.env.IROOTS_NEW_xxxCLOUDFLARE_TURNSTILE_SECRET = secret
}

ux.action.stop()
}

if (github) {
ux.action.start('Creating Bedrock and Trellis repos on GitHub')
await gh.createRepo(bedrockRemoteOwner, bedrockRemoteRepo, {
Expand Down

0 comments on commit 7d2f1f4

Please sign in to comment.