-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:aws-amplify/samsara-cli into add-fo…
…rm-cli
- Loading branch information
Showing
29 changed files
with
868 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@aws-amplify/backend-secret': minor | ||
'@aws-amplify/backend-cli': minor | ||
'@aws-amplify/backend': patch | ||
--- | ||
|
||
Provides sandbox secret CLI commands |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"no-console": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { EOL } from 'os'; | ||
|
||
/** | ||
* The class that pretty prints to the console. | ||
*/ | ||
export class Printer { | ||
/** | ||
* Print an object/record to console. | ||
*/ | ||
static printRecord = <T extends Record<string | number, string | number>>( | ||
object: T | ||
): void => { | ||
let message = ''; | ||
const entries = Object.entries(object); | ||
entries.forEach(([key, val]) => { | ||
message = message.concat(` ${key}: ${val}${EOL}`); | ||
}); | ||
console.log(message); | ||
}; | ||
|
||
/** | ||
* Prints an array of objects/records to console. | ||
*/ | ||
static printRecords = <T extends Record<string | number, string | number>>( | ||
objects: T[] | ||
): void => { | ||
for (const obj of objects) { | ||
this.printRecord(obj); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SANDBOX_BRANCH = 'sandbox'; |
52 changes: 52 additions & 0 deletions
52
packages/cli/src/commands/sandbox/sandbox-secret/sandbox_secret_command.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { describe, it } from 'node:test'; | ||
import yargs, { CommandModule } from 'yargs'; | ||
import { | ||
TestCommandError, | ||
TestCommandRunner, | ||
} from '../../../test-utils/command_runner.js'; | ||
import assert from 'node:assert'; | ||
import { SandboxIdResolver } from '../sandbox_id_resolver.js'; | ||
import { getSecretClient } from '@aws-amplify/backend-secret'; | ||
import { SandboxSecretCommand } from './sandbox_secret_command.js'; | ||
import { SandboxSecretGetCommand } from './sandbox_secret_get_command.js'; | ||
|
||
const testBackendId = 'testBackendId'; | ||
|
||
void describe('sandbox secret command', () => { | ||
const secretClient = getSecretClient(); | ||
const sandboxIdResolver = new SandboxIdResolver({ | ||
resolve: () => Promise.resolve(testBackendId), | ||
}); | ||
|
||
// Creates only a 'get' subcommand. | ||
const sandboxSecretCmd = new SandboxSecretCommand([ | ||
new SandboxSecretGetCommand( | ||
sandboxIdResolver, | ||
secretClient | ||
) as unknown as CommandModule, | ||
]); | ||
|
||
const parser = yargs().command(sandboxSecretCmd); | ||
const commandRunner = new TestCommandRunner(parser); | ||
|
||
void it('show --help', async () => { | ||
const output = await commandRunner.runCommand('secret --help'); | ||
assert.match(output, /Manage sandbox secret/); | ||
['secret get'].forEach((cmd) => assert.match(output, new RegExp(cmd))); | ||
['secret set', 'secret list', 'secret remove'].forEach((cmd) => | ||
assert.doesNotMatch(output, new RegExp(cmd)) | ||
); | ||
}); | ||
|
||
void it('throws error if no verb subcommand', async () => { | ||
await assert.rejects( | ||
() => commandRunner.runCommand('secret'), | ||
(err: TestCommandError) => { | ||
assert.equal(err.error.name, 'YError'); | ||
assert.match(err.error.message, /Not enough non-option arguments/); | ||
assert.match(err.output, /Not enough non-option arguments/); | ||
return true; | ||
} | ||
); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/cli/src/commands/sandbox/sandbox-secret/sandbox_secret_command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Argv, CommandModule } from 'yargs'; | ||
|
||
/** | ||
* Root command to manage sandbox secret. | ||
*/ | ||
export class SandboxSecretCommand implements CommandModule<object> { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
readonly command: string; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
readonly describe: string; | ||
|
||
/** | ||
* Root command to manage sandbox secret | ||
*/ | ||
constructor(private readonly secretSubCommands: CommandModule[]) { | ||
this.command = 'secret <command>'; | ||
this.describe = 'Manage sandbox secret'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
handler = (): void => { | ||
// no-op for non-terminal command. | ||
return; | ||
}; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
builder = (yargs: Argv): Argv => { | ||
return ( | ||
yargs | ||
.command(this.secretSubCommands) | ||
// Hide inherited options since they are not applicable here. | ||
.option('dirToWatch', { | ||
hidden: true, | ||
}) | ||
.option('exclude', { | ||
hidden: true, | ||
}) | ||
.option('name', { | ||
hidden: true, | ||
}) | ||
.option('out', { | ||
hidden: true, | ||
}) | ||
.help() | ||
); | ||
}; | ||
} |
Oops, something went wrong.