Skip to content

Commit

Permalink
feat: support login utm from environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Mar 10, 2020
1 parent f4d4861 commit aba5b03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cli/commands/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MisconfiguredAuthInCI } from '../../../lib/errors/misconfigured-auth-in
import { AuthFailedError } from '../../../lib/errors/authentication-failed-error';
import { verifyAPI } from './is-authed';
import { CustomError } from '../../../lib/errors';
import { getUtmsAsString } from '../../../lib/utm';

export = auth;

Expand All @@ -33,6 +34,7 @@ async function webAuth(via: AuthCliCommands) {
};

let urlStr = authUrl + '/login?token=' + token;
urlStr += '&' + getUtmsAsString();

// validate that via comes from our code, and not from user & CLI
if (redirects[via]) {
Expand Down
17 changes: 17 additions & 0 deletions src/lib/utm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as url from 'url';

const SNYK_UTM_MEDIUM = process.env.SNYK_UTM_MEDIUM || '';
const SNYK_UTM_SOURCE = process.env.SNYK_UTM_SOURCE || '';
const SNYK_UTM_CAMPAIGN = process.env.SNYK_UTM_CAMPAIGN || '';

export function getUtmsAsString(): string {
/* eslint-disable @typescript-eslint/camelcase */
const utmQueryParams = new url.URLSearchParams({
utm_medium: SNYK_UTM_MEDIUM,
utm_source: SNYK_UTM_SOURCE,
utm_campaign: SNYK_UTM_CAMPAIGN,
});
/* eslint-enable @typescript-eslint/camelcase */

return utmQueryParams.toString();
}

0 comments on commit aba5b03

Please sign in to comment.