Skip to content

Commit

Permalink
fix: use correct auth header for api requests
Browse files Browse the repository at this point in the history
This is an immediate fix to ensure we use the correct header based on if SNYK_OAUTH_TOKEN is used.
We'll look into improving the auth experience in CLI in the near future.
  • Loading branch information
Jahed Ahmed committed May 13, 2022
1 parent 16cdd81 commit 36211dd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Expand Up @@ -2,7 +2,7 @@ import { IaCErrorCodes, IacOrgSettings } from '../types';
import { Payload } from '../../../../../../lib/snyk-test/types';
import config from '../../../../../../lib/config';
import { isCI } from '../../../../../../lib/is-ci';
import { api } from '../../../../../../lib/api-token';
import { getAuthHeader } from '../../../../../../lib/api-token';
import { makeRequest } from '../../../../../../lib/request';
import { CustomError } from '../../../../../../lib/errors';
import { getErrorStringCode } from '../error-utils';
Expand All @@ -17,7 +17,7 @@ export function getIacOrgSettings(
qs: { org: publicOrgId },
headers: {
'x-is-ci': isCI(),
authorization: `token ${api()}`,
authorization: getAuthHeader(),
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/test/iac/local-execution/usage-tracking.ts
@@ -1,6 +1,6 @@
import { makeRequest } from '../../../../../lib/request';
import config from '../../../../../lib/config';
import { api as getApiToken } from '../../../../../lib/api-token';
import { getAuthHeader } from '../../../../../lib/api-token';
import { CustomError } from '../../../../../lib/errors';

export async function trackUsage(
Expand All @@ -15,7 +15,7 @@ export async function trackUsage(
const trackingResponse = await makeRequest({
method: 'POST',
headers: {
Authorization: `token ${getApiToken()}`,
Authorization: getAuthHeader(),
},
url: `${config.API}/track-iac-usage/cli`,
body: { results: trackingData },
Expand Down
6 changes: 3 additions & 3 deletions src/lib/authorization.ts
@@ -1,6 +1,6 @@
import * as snyk from './';
import { makeRequest } from './request';
import { getAuthHeader } from './api-token';
import config from './config';
import { makeRequest } from './request';

export async function actionAllowed(
action: string,
Expand All @@ -14,7 +14,7 @@ export async function actionAllowed(
url: config.API + '/authorization/' + action,
json: true,
headers: {
authorization: 'token ' + snyk.api,
authorization: getAuthHeader(),
},
qs: org && { org },
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib/plugins/sast/checks.ts
@@ -1,6 +1,6 @@
import { makeRequest } from '../../request';

import { api as getApiToken } from '../../api-token';
import { getAuthHeader } from '../../api-token';
import config from '../../config';
import { assembleQueryString } from '../../snyk-test/common';
import { SastSettings, TrackUsageResponse } from './types';
Expand All @@ -9,7 +9,7 @@ export async function getSastSettingsForOrg(org): Promise<SastSettings> {
const response = await makeRequest({
method: 'GET',
headers: {
Authorization: `token ${getApiToken()}`,
Authorization: getAuthHeader(),
},
qs: assembleQueryString({ org }),
url: `${config.API}/cli-config/settings/sast`,
Expand All @@ -24,7 +24,7 @@ export async function trackUsage(org): Promise<TrackUsageResponse> {
const response = await makeRequest({
method: 'POST',
headers: {
Authorization: `token ${getApiToken()}`,
Authorization: getAuthHeader(),
},
qs: assembleQueryString({ org }),
url: `${config.API}/track-sast-usage/cli`,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/snyk-test/run-test.ts
Expand Up @@ -817,7 +817,7 @@ async function assembleRemotePayloads(root, options): Promise<Payload[]> {
json: true,
headers: {
'x-is-ci': isCI(),
authorization: 'token ' + snyk.api,
authorization: getAuthHeader(),
},
},
];
Expand Down

0 comments on commit 36211dd

Please sign in to comment.