Skip to content

Commit

Permalink
Check for custom deploy key in library
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Mar 5, 2024
1 parent 6162ba4 commit 976898b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/bin/vip-app-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
} from '../lib/custom-deploy/custom-deploy';
import { trackEventWithEnv } from '../lib/tracker';

const CUSTOM_DEPLOY_KEY = process.env.CUSTOM_DEPLOY_KEY || '';

const appQuery = `
id,
name,
Expand Down Expand Up @@ -129,10 +127,8 @@ export async function appDeployCmd( arg: string[] = [], opts: Record< string, un
exit.withError( 'The type of application you specified does not currently support deploys.' );
}

if ( CUSTOM_DEPLOY_KEY ) {
debug( 'Validating custom deploy key...' );
await validateCustomDeployKey( CUSTOM_DEPLOY_KEY, envId );
}
debug( 'Validating custom deploy key if present...' );
await validateCustomDeployKey( envId );

await validateFile( app, env, fileMeta );

Expand Down
10 changes: 4 additions & 6 deletions src/lib/custom-deploy/custom-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import { trackEventWithEnv } from '../../lib/tracker';
import { validateDeployFileExt, validateFilename } from '../../lib/validations/custom-deploy';

const DEPLOY_MAX_FILE_SIZE = 4 * GB_IN_BYTES;
const CUSTOM_DEPLOY_KEY = process.env.CUSTOM_DEPLOY_KEY;

export function isSupportedApp( app: App ): boolean {
return WORDPRESS_SITE_TYPE_IDS.includes( app.typeId as number );
}

export async function validateCustomDeployKey(
customDeployKey: string,
envId: number
): Promise< void > {
if ( customDeployKey.length === 0 ) {
export async function validateCustomDeployKey( envId: number ): Promise< void > {
if ( ! CUSTOM_DEPLOY_KEY || CUSTOM_DEPLOY_KEY.length === 0 ) {
exit.withError( 'Valid custom deploy key is required.' );
}

Expand All @@ -32,7 +30,7 @@ export async function validateCustomDeployKey(
}
`;

const api = await API( { customAuthToken: customDeployKey } );
const api = await API( { customAuthToken: CUSTOM_DEPLOY_KEY } );
try {
await api.mutate( { mutation: VALIDATE_CUSTOM_DEPLOY_ACCESS_MUTATION } );
} catch ( error ) {
Expand Down

0 comments on commit 976898b

Please sign in to comment.