@codefresh-io/cf-git-providers
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { Provider, Repository, Branch, Webhook, ProviderName, User, PullRequest, RepositoryPermission } from './types'; | ||
import { Provider, Repository, Branch, Webhook, ProviderName, User, PullRequest, RepositoryPermission, PermissionScopes } from './types'; | ||
export default class BitbucketServer implements Provider { | ||
@@ -109,2 +109,5 @@ private baseUrl; | ||
}): Promise<PullRequest>; | ||
assertApiScopes(opt: { | ||
scopes: PermissionScopes[]; | ||
}): Promise<void>; | ||
} |
@@ -405,4 +405,7 @@ "use strict"; | ||
} | ||
async assertApiScopes(opt) { | ||
//TODO : Impl validation | ||
} | ||
} | ||
exports.default = BitbucketServer; | ||
//# sourceMappingURL=bitbucket-server.js.map |
@@ -1,2 +0,2 @@ | ||
import { ProviderName, Provider, Branch, Repository, Webhook, User, PullRequest, RepositoryPermission } from './types'; | ||
import { ProviderName, Provider, Branch, Repository, Webhook, User, PullRequest, RepositoryPermission, PermissionScopes } from './types'; | ||
export default class Bitbucket implements Provider { | ||
@@ -110,2 +110,5 @@ private baseUrl; | ||
}): Promise<RepositoryPermission>; | ||
assertApiScopes(opt: { | ||
scopes: PermissionScopes[]; | ||
}): Promise<void>; | ||
} |
@@ -241,4 +241,7 @@ "use strict"; | ||
} | ||
async assertApiScopes(opt) { | ||
//TODO : Impl validation | ||
} | ||
} | ||
exports.default = Bitbucket; | ||
//# sourceMappingURL=bitbucket.js.map |
@@ -1,2 +0,2 @@ | ||
import { ProviderName, Provider, Branch, Repository, Webhook, CommitStatus, User, PullRequest, RepositoryPermission } from './types'; | ||
import { ProviderName, Provider, Branch, Repository, Webhook, CommitStatus, User, PullRequest, RepositoryPermission, PermissionScopes } from './types'; | ||
export default class Github implements Provider { | ||
@@ -103,2 +103,5 @@ private githubClient; | ||
}): Promise<RepositoryPermission>; | ||
assertApiScopes(opt: { | ||
scopes: PermissionScopes[]; | ||
}): Promise<void>; | ||
} |
@@ -26,2 +26,7 @@ "use strict"; | ||
}; | ||
const scopesMap = { | ||
repo_read: 'repo', | ||
repo_write: 'repo', | ||
admin_repo_hook: 'admin:repo_hook', | ||
}; | ||
const _getAgent = (insecure) => { | ||
@@ -462,4 +467,18 @@ const options = { keepAlive: true, maxSockets: 10, rejectUnauthorized: !insecure }; | ||
} | ||
async assertApiScopes(opt) { | ||
const [err, res] = await helpers_1.to(this.githubClient.request('/user')); | ||
if (err) { | ||
throw new Error(`ValidationError: ${err}, status code ${err.status}`); | ||
} | ||
if (!res.headers['x-oauth-scopes']) { | ||
throw new Error(`ValidationError: missing scopes: ${opt.scopes.toString()}`); | ||
} | ||
const originalScopes = res.headers['x-oauth-scopes'].replace(/ /g, '').split(','); | ||
const isValid = opt.scopes.every(val => originalScopes.includes(scopesMap[val])); | ||
if (!isValid) { | ||
throw new Error(`ValidationError: got scopes ${res.headers['x-oauth-scopes'].toString()} while expected: ${opt.scopes.toString()}`); | ||
} | ||
} | ||
} | ||
exports.default = Github; | ||
//# sourceMappingURL=github.js.map |
@@ -1,2 +0,2 @@ | ||
import { Provider, Branch, Repository, Webhook, ProviderName, User, PullRequest, RepositoryPermission } from './types'; | ||
import { Provider, Branch, Repository, Webhook, ProviderName, User, PullRequest, RepositoryPermission, PermissionScopes } from './types'; | ||
export default class Gitlab implements Provider { | ||
@@ -106,2 +106,5 @@ private baseUrl; | ||
}): Promise<RepositoryPermission>; | ||
assertApiScopes(opt: { | ||
scopes: PermissionScopes[]; | ||
}): Promise<void>; | ||
} |
@@ -376,4 +376,7 @@ "use strict"; | ||
} | ||
async assertApiScopes(opt) { | ||
//TODO : Impl validation | ||
} | ||
} | ||
exports.default = Gitlab; | ||
//# sourceMappingURL=gitlab.js.map |
@@ -16,2 +16,3 @@ export declare type ProviderConstructor = new (opt: { | ||
export declare type CommitStatus = 'pending' | 'running' | 'success' | 'failure' | 'error'; | ||
export declare type PermissionScopes = 'repo_read' | 'repo_write' | 'admin_repo_hook'; | ||
export interface Provider { | ||
@@ -109,2 +110,5 @@ getName(): ProviderName; | ||
}): Promise<RepositoryPermission>; | ||
assertApiScopes(opt: { | ||
scopes: PermissionScopes[]; | ||
}): Promise<void>; | ||
} | ||
@@ -111,0 +115,0 @@ export interface RepositoryPermission { |
{ | ||
"name": "@codefresh-io/cf-git-providers", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "An NPM module/CLI for interacting with various git providers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
220991
1.24%3351
1.33%