Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthBypassTokenDuration CLI Additions #2182

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-gifts-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Added an `--auth-bypass-token-duration` flag to the `deploy` command to allow for specified token duration between 1 to 12 hours.
13 changes: 13 additions & 0 deletions packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,24 @@
},
"auth-bypass-token": {
"description": "Generate an authentication bypass token, which can be used to perform end-to-end tests against the deployment.",
"env": "AUTH_BYPASS_TOKEN",
"name": "auth-bypass-token",
"required": false,
"allowNo": false,
"type": "boolean"
},
"auth-bypass-token-duration": {
"dependsOn": [
"auth-bypass-token"
],
"description": "Specify the duration (in hours) up to 12 hours for the authentication bypass token. Defaults to `2`",
"env": "AUTH_BYPASS_TOKEN_DURATION",
"name": "auth-bypass-token-duration",
"required": false,
"hasDynamicHelp": false,
"multiple": false,
"type": "option"
},
"build-command": {
"description": "Specify a build command to run before deploying. If not specified, `shopify hydrogen build` will be used.",
"name": "build-command",
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/commands/hydrogen/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,26 @@ describe('deploy', () => {
});
});

it('supports valid authBypassTokenDuration when generateAuthBypassToken is true', async () => {
const params = {
...deployParams,
generateAuthBypassToken: true,
authBypassTokenDuration: '2',
};

await expect(runDeploy(params)).resolves.not.toThrow();

expect(vi.mocked(createDeploy)).toHaveBeenCalledWith(
expect.objectContaining({
config: expect.objectContaining({
generateAuthBypassToken: true,
authBypassTokenDuration: '2',
}),
}),
);
expect(vi.mocked(renderSuccess)).toHaveBeenCalled();
});

it('calls createDeploy against a environment selected by env', async () => {
vi.mocked(getOxygenDeploymentData).mockResolvedValue({
oxygenDeploymentToken: 'some-encoded-token',
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/commands/hydrogen/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export default class Deploy extends Command {
'Generate an authentication bypass token, which can be used to perform end-to-end tests against the deployment.',
required: false,
default: false,
env: 'AUTH_BYPASS_TOKEN',
}),
'auth-bypass-token-duration': Flags.string({
description:
'Specify the duration (in hours) up to 12 hours for the authentication bypass token. Defaults to `2`',
required: false,
env: 'AUTH_BYPASS_TOKEN_DURATION',
dependsOn: ['auth-bypass-token'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to add an env flag name to both auth-bypass-token and auth-bypass-token-duration so that devs can pass these values from env variables.

}),
'build-command': Flags.string({
description:
Expand Down Expand Up @@ -178,6 +186,7 @@ export default class Deploy extends Command {
}

interface OxygenDeploymentOptions {
authBypassTokenDuration?: string;
authBypassToken: boolean;
buildCommand?: string;
defaultEnvironment: boolean;
Expand Down Expand Up @@ -226,6 +235,7 @@ export async function runDeploy(
options: OxygenDeploymentOptions,
): Promise<void> {
const {
authBypassTokenDuration,
authBypassToken: generateAuthBypassToken,
buildCommand,
defaultEnvironment,
Expand Down Expand Up @@ -458,6 +468,7 @@ export async function runDeploy(
userChosenEnvironmentTag ||
fallbackEnvironmentTag,
generateAuthBypassToken,
authBypassTokenDuration,
verificationMaxDuration: 180,
metadata: {
...(metadataDescription ? {description: metadataDescription} : {}),
Expand Down
Loading