Skip to content

Commit

Permalink
chore: Convert more code to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
robcresswell committed Mar 15, 2021
1 parent 3a1c3d4 commit 2f6bcbe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/lib/authorization.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/lib/authorization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as snyk from './';
import request = require('./request');
import * as config from './config';

export async function actionAllowed(
action: string,
options: { org?: string },
): Promise<{ allowed: boolean; reason: string }> {
const org = options.org || config.org || null;

try {
const res = await request({
method: 'GET',
url: config.API + '/authorization/' + action,
json: true,
headers: {
authorization: 'token ' + snyk.api,
},
qs: org && { org },
});

return (res as any).body.result;
} catch (err) {
return {
allowed: false,
reason: 'There was an error while checking authorization',
};
}
}

0 comments on commit 2f6bcbe

Please sign in to comment.