Skip to content

Commit 3f3d2aa

Browse files
authored
vault pass gen (#100)
1 parent ba6c104 commit 3f3d2aa

File tree

5 files changed

+54
-13
lines changed

5 files changed

+54
-13
lines changed

commands/path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function setupPath(path) {
1313
if (currentPath) {
1414
writeInfo(`Your path is: ${currentPath}`)
1515
} else {
16-
writeError(`No path is set, run \`lisa path [path]\` to set a paht.`)
16+
writeError("No path is set, run `lisa path [path]` to set a path.")
1717
}
1818

1919
return

index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env node
2+
import { generateCompletionSpec } from "@fig/complete-commander"
23
import chalk from "chalk"
34
import { Command } from "commander"
5+
import fs from "fs"
46

57
import {
68
createCdnS3GoDaddy,
@@ -24,6 +26,7 @@ import exec from "./lib/exec.js"
2426
import { getSitesPath } from "./lib/path.js"
2527
import { set } from "./lib/store.js"
2628
import { checkLisaVersion } from "./lib/versions.js"
29+
import { generateVaultPass } from "./tasks/trellis.js"
2730

2831
export const program = new Command()
2932
export const LISA_VERSION = "2.15.7"
@@ -140,6 +143,25 @@ Make sure your standing in the folder where your composer.json file is located.
140143
.description("Update Bucket Lifecycle Policy in S3")
141144
.action(updateBucketLicecyclePolicy)
142145

146+
program
147+
.command("vault-pass-generate")
148+
.description(
149+
"Generate a new vault password, use when no existing password is available",
150+
)
151+
.argument(
152+
"[path]",
153+
"Path to where the vault password should be saved",
154+
`${process.cwd()}/.vault_pass`,
155+
)
156+
.action(generateVaultPass)
157+
158+
if (process.env.NODE_ENV === "development") {
159+
const lisaFigSecContent = generateCompletionSpec(program)
160+
const lisaFigSecPath = `${process.env.HOME}/.fig/autocomplete/lisa.ts`
161+
fs.writeFileSync(lisaFigSecPath, lisaFigSecContent, { encoding: "utf8" })
162+
// npx @fig/publish-spec@latest --spec-path ~/.fig/autocomplete/lisa.ts
163+
// npx @fig/publish-spec@latest --spec-path ~/.fig/autocomplete/lisa.ts --team triggerfish
164+
}
143165
program.parse()
144166
}
145167

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"semver": "^7.3.8"
3333
},
3434
"devDependencies": {
35+
"@fig/complete-commander": "^2.0.1",
3536
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
3637
"@types/node": "^20.8.6",
3738
"eslint": "^8.51.0",

tasks/trellis.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,41 @@ import {
1212
} from "../lib/vault.js"
1313
import { writeStep, writeSuccess } from "../lib/write.js"
1414

15-
export async function addVaultPassword() {
16-
let trellisPath = getTrellisPath()
17-
let vaultPassPath = `${trellisPath}/.vault_pass`
18-
let password = generator.generate({
15+
export async function generateVaultPass(
16+
vaultPassPath = `${process.cwd()}/.vault_pass`,
17+
) {
18+
console.log(vaultPassPath)
19+
const password = generator.generate({
1920
length: 32,
2021
numbers: true,
2122
})
2223

23-
fs.writeFile(vaultPassPath, password, (err) => {
24+
fs.writeFile(vaultPassPath, password, { encoding: "utf8" }, (err) => {
2425
if (err) {
2526
console.log(err)
2627
}
2728
})
28-
2929
conf.set("vaultPass", password)
3030

3131
writeSuccess(`Vault pass written to ${vaultPassPath}`)
3232
}
3333

34+
export async function addVaultPassword() {
35+
const trellisPath = getTrellisPath()
36+
const vaultPassPath = `${trellisPath}/.vault_pass`
37+
await generateVaultPass(vaultPassPath)
38+
}
39+
3440
export async function changeVaultPasswords() {
3541
writeStep("Update all vault files with new vault pass")
3642

37-
let lisaVaultPassPath = getLisaVaultPassPath()
38-
let vaultPassPath = getVaultPassPath()
43+
const lisaVaultPassPath = getLisaVaultPassPath()
44+
const vaultPassPath = getVaultPassPath()
3945

40-
let allGroupVarsPath = getGroupVarsPath("all")
41-
let developmentGroupVarsPath = getGroupVarsPath("development")
42-
let stagingGroupVarsPath = getGroupVarsPath("staging")
43-
let productionGroupVarsPath = getGroupVarsPath("production")
46+
const allGroupVarsPath = getGroupVarsPath("all")
47+
const developmentGroupVarsPath = getGroupVarsPath("development")
48+
const stagingGroupVarsPath = getGroupVarsPath("staging")
49+
const productionGroupVarsPath = getGroupVarsPath("production")
4450

4551
await writeTempLisaVaultPass()
4652

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,13 @@
837837
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.51.0.tgz#6d419c240cfb2b66da37df230f7e7eef801c32fa"
838838
integrity sha512-HxjQ8Qn+4SI3/AFv6sOrDB+g6PpUTDwSJiQqOrnneEk8L71161srI9gjzzZvYVbzHiVg/BvcH95+cK/zfIt4pg==
839839

840+
"@fig/complete-commander@^2.0.1":
841+
version "2.0.1"
842+
resolved "https://registry.yarnpkg.com/@fig/complete-commander/-/complete-commander-2.0.1.tgz#6dd84f8812389107529aaedebd1bb67ac8bc16c6"
843+
integrity sha512-AbGETely7iwD4F7XHe4g7pW6icWYYqJMdQog8CdEi9syU/av5L0O24BvCfgEeGO6TRPMpC+rFL7ZDJsqRtckOA==
844+
dependencies:
845+
prettier "^2.3.2"
846+
840847
"@humanwhocodes/config-array@^0.11.11":
841848
version "0.11.11"
842849
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.11.tgz#88a04c570dbbc7dd943e4712429c3df09bc32844"
@@ -2956,6 +2963,11 @@ prettier-linter-helpers@^1.0.0:
29562963
dependencies:
29572964
fast-diff "^1.1.2"
29582965

2966+
prettier@^2.3.2:
2967+
version "2.8.8"
2968+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
2969+
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
2970+
29592971
prettier@^3.0.3:
29602972
version "3.0.3"
29612973
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643"

0 commit comments

Comments
 (0)