@backstage/integration
Advanced tools
Comparing version 0.0.0-nightly-202011921610 to 0.0.0-nightly-20210124517
# @backstage/integration | ||
## 0.0.0-nightly-202011921610 | ||
## 0.0.0-nightly-20210124517 | ||
### Patch Changes | ||
- 8054117: Move the core url and auth logic to integration for the four major providers | ||
- 8054117: Add the basics of cross-integration concerns | ||
- 0915610: Provide support for on-prem azure devops | ||
## 0.1.4 | ||
### Patch Changes | ||
- 1d1c2860f: Implement readTree on BitBucketUrlReader and getBitbucketDownloadUrl | ||
- 4eafdec4a: Introduce readTree method for GitLab URL Reader | ||
- 178e09323: Validate that integration config contains a valid host | ||
## 0.1.3 | ||
### Patch Changes | ||
- 38e24db00: Move the core url and auth logic to integration for the four major providers | ||
- b8ecf6f48: Add the basics of cross-integration concerns | ||
- Updated dependencies [e3bd9fc2f] | ||
- Updated dependencies [e3bd9fc2f] | ||
- @backstage/config@0.1.2 | ||
## 0.1.2 | ||
@@ -11,0 +28,0 @@ |
@@ -13,2 +13,8 @@ 'use strict'; | ||
function isValidHost(url) { | ||
const check = new URL("http://example.com"); | ||
check.host = url; | ||
return check.host === url; | ||
} | ||
const AZURE_HOST = "dev.azure.com"; | ||
@@ -19,2 +25,5 @@ function readAzureIntegrationConfig(config2) { | ||
const token = config2.getOptionalString("token"); | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid Azure integration config, '${host}' is not a valid host`); | ||
} | ||
return {host, token}; | ||
@@ -43,3 +52,3 @@ } | ||
const ref = (_a = parsedUrl.searchParams.get("version")) == null ? void 0 : _a.substr(2); | ||
if (parsedUrl.hostname !== "dev.azure.com" || empty !== "" || userOrOrg === "" || project === "" || srcKeyword !== "_git" || repoName === "" || path === "" || ref === "") { | ||
if (empty !== "" || userOrOrg === "" || project === "" || srcKeyword !== "_git" || repoName === "" || path === "" || ref === "") { | ||
throw new Error("Wrong Azure Devops URL or Invalid file path"); | ||
@@ -98,2 +107,5 @@ } | ||
const appPassword = config2.getOptionalString("appPassword"); | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid Bitbucket integration config, '${host}' is not a valid host`); | ||
} | ||
if (apiBaseUrl) { | ||
@@ -123,2 +135,42 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, ""); | ||
async function getBitbucketDefaultBranch(url, config2) { | ||
const {name: repoName, owner: project, resource} = parseGitUrl__default['default'](url); | ||
const isHosted = resource === "bitbucket.org"; | ||
const branchUrl = isHosted ? `${config2.apiBaseUrl}/repositories/${project}/${repoName}` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`; | ||
const response = await fetch__default['default'](branchUrl, getBitbucketRequestOptions(config2)); | ||
if (!response.ok) { | ||
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`; | ||
throw new Error(message); | ||
} | ||
let defaultBranch; | ||
if (isHosted) { | ||
const repoInfo = await response.json(); | ||
defaultBranch = repoInfo.mainbranch.name; | ||
} else { | ||
const {displayId} = await response.json(); | ||
defaultBranch = displayId; | ||
} | ||
if (!defaultBranch) { | ||
throw new Error(`Failed to read default branch from ${branchUrl}`); | ||
} | ||
return defaultBranch; | ||
} | ||
async function getBitbucketDownloadUrl(url, config2) { | ||
const { | ||
name: repoName, | ||
owner: project, | ||
ref, | ||
protocol, | ||
resource, | ||
filepath | ||
} = parseGitUrl__default['default'](url); | ||
const isHosted = resource === "bitbucket.org"; | ||
let branch = ref; | ||
if (!branch) { | ||
branch = await getBitbucketDefaultBranch(url, config2); | ||
} | ||
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : ""; | ||
const archiveUrl = isHosted ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.zip` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=zip&at=${branch}&prefix=${project}-${repoName}${path}`; | ||
return archiveUrl; | ||
} | ||
function getBitbucketFileFetchUrl(url, config2) { | ||
@@ -164,2 +216,5 @@ try { | ||
const token = config2.getOptionalString("token"); | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid GitHub integration config, '${host}' is not a valid host`); | ||
} | ||
if (apiBaseUrl) { | ||
@@ -222,7 +277,17 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, ""); | ||
const GITLAB_HOST = "gitlab.com"; | ||
const GITLAB_API_BASE_URL = "gitlab.com/api/v4"; | ||
function readGitLabIntegrationConfig(config2) { | ||
var _a; | ||
const host = (_a = config2.getOptionalString("host")) != null ? _a : GITLAB_HOST; | ||
let apiBaseUrl = config2.getOptionalString("apiBaseUrl"); | ||
const token = config2.getOptionalString("token"); | ||
return {host, token}; | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid GitLab integration config, '${host}' is not a valid host`); | ||
} | ||
if (apiBaseUrl) { | ||
apiBaseUrl = apiBaseUrl.replace(/\/+$/, ""); | ||
} else if (host === GITLAB_HOST) { | ||
apiBaseUrl = GITLAB_API_BASE_URL; | ||
} | ||
return {host, token, apiBaseUrl}; | ||
} | ||
@@ -292,3 +357,3 @@ function readGitLabIntegrationConfigs(configs) { | ||
if (!url.pathname.includes("/-/blob/")) { | ||
throw new Error("Please provide full path to yaml file from Gitlab"); | ||
throw new Error("Please provide full path to yaml file from GitLab"); | ||
} | ||
@@ -416,2 +481,4 @@ try { | ||
exports.getAzureRequestOptions = getAzureRequestOptions; | ||
exports.getBitbucketDefaultBranch = getBitbucketDefaultBranch; | ||
exports.getBitbucketDownloadUrl = getBitbucketDownloadUrl; | ||
exports.getBitbucketFileFetchUrl = getBitbucketFileFetchUrl; | ||
@@ -418,0 +485,0 @@ exports.getBitbucketRequestOptions = getBitbucketRequestOptions; |
@@ -111,2 +111,17 @@ import { Config } from '@backstage/config'; | ||
/** | ||
* Given a URL pointing to a path on a provider, returns the default branch. | ||
* | ||
* @param url A URL pointing to a path | ||
* @param config The relevant provider config | ||
*/ | ||
declare function getBitbucketDefaultBranch(url: string, config: BitbucketIntegrationConfig): Promise<string>; | ||
/** | ||
* Given a URL pointing to a path on a provider, returns a URL that is suitable | ||
* for downloading the subtree. | ||
* | ||
* @param url A URL pointing to a path | ||
* @param config The relevant provider config | ||
*/ | ||
declare function getBitbucketDownloadUrl(url: string, config: BitbucketIntegrationConfig): Promise<string>; | ||
/** | ||
* Given a URL pointing to a file on a provider, returns a URL that is suitable | ||
@@ -208,2 +223,12 @@ * for fetching the contents of the data. | ||
/** | ||
* The base URL of the API of this provider, e.g. "https://gitlab.com/api/v4", | ||
* with no trailing slash. | ||
* | ||
* May be omitted specifically for GitLab; then it will be deduced. | ||
* | ||
* The API will always be preferred if both its base URL and a token are | ||
* present. | ||
*/ | ||
apiBaseUrl?: string; | ||
/** | ||
* The authorization token to use for requests this provider. | ||
@@ -293,2 +318,2 @@ * | ||
export { AzureIntegrationConfig, BitbucketIntegrationConfig, GitHubIntegrationConfig, GitLabIntegrationConfig, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs }; | ||
export { AzureIntegrationConfig, BitbucketIntegrationConfig, GitHubIntegrationConfig, GitLabIntegrationConfig, ScmIntegration, ScmIntegrationRegistry, ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs }; |
import parseGitUrl from 'git-url-parse'; | ||
import fetch from 'cross-fetch'; | ||
function isValidHost(url) { | ||
const check = new URL("http://example.com"); | ||
check.host = url; | ||
return check.host === url; | ||
} | ||
const AZURE_HOST = "dev.azure.com"; | ||
@@ -9,2 +15,5 @@ function readAzureIntegrationConfig(config2) { | ||
const token = config2.getOptionalString("token"); | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid Azure integration config, '${host}' is not a valid host`); | ||
} | ||
return {host, token}; | ||
@@ -33,3 +42,3 @@ } | ||
const ref = (_a = parsedUrl.searchParams.get("version")) == null ? void 0 : _a.substr(2); | ||
if (parsedUrl.hostname !== "dev.azure.com" || empty !== "" || userOrOrg === "" || project === "" || srcKeyword !== "_git" || repoName === "" || path === "" || ref === "") { | ||
if (empty !== "" || userOrOrg === "" || project === "" || srcKeyword !== "_git" || repoName === "" || path === "" || ref === "") { | ||
throw new Error("Wrong Azure Devops URL or Invalid file path"); | ||
@@ -88,2 +97,5 @@ } | ||
const appPassword = config2.getOptionalString("appPassword"); | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid Bitbucket integration config, '${host}' is not a valid host`); | ||
} | ||
if (apiBaseUrl) { | ||
@@ -113,2 +125,42 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, ""); | ||
async function getBitbucketDefaultBranch(url, config2) { | ||
const {name: repoName, owner: project, resource} = parseGitUrl(url); | ||
const isHosted = resource === "bitbucket.org"; | ||
const branchUrl = isHosted ? `${config2.apiBaseUrl}/repositories/${project}/${repoName}` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/branches/default`; | ||
const response = await fetch(branchUrl, getBitbucketRequestOptions(config2)); | ||
if (!response.ok) { | ||
const message = `Failed to retrieve default branch from ${branchUrl}, ${response.status} ${response.statusText}`; | ||
throw new Error(message); | ||
} | ||
let defaultBranch; | ||
if (isHosted) { | ||
const repoInfo = await response.json(); | ||
defaultBranch = repoInfo.mainbranch.name; | ||
} else { | ||
const {displayId} = await response.json(); | ||
defaultBranch = displayId; | ||
} | ||
if (!defaultBranch) { | ||
throw new Error(`Failed to read default branch from ${branchUrl}`); | ||
} | ||
return defaultBranch; | ||
} | ||
async function getBitbucketDownloadUrl(url, config2) { | ||
const { | ||
name: repoName, | ||
owner: project, | ||
ref, | ||
protocol, | ||
resource, | ||
filepath | ||
} = parseGitUrl(url); | ||
const isHosted = resource === "bitbucket.org"; | ||
let branch = ref; | ||
if (!branch) { | ||
branch = await getBitbucketDefaultBranch(url, config2); | ||
} | ||
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : ""; | ||
const archiveUrl = isHosted ? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.zip` : `${config2.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=zip&at=${branch}&prefix=${project}-${repoName}${path}`; | ||
return archiveUrl; | ||
} | ||
function getBitbucketFileFetchUrl(url, config2) { | ||
@@ -154,2 +206,5 @@ try { | ||
const token = config2.getOptionalString("token"); | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid GitHub integration config, '${host}' is not a valid host`); | ||
} | ||
if (apiBaseUrl) { | ||
@@ -212,7 +267,17 @@ apiBaseUrl = apiBaseUrl.replace(/\/+$/, ""); | ||
const GITLAB_HOST = "gitlab.com"; | ||
const GITLAB_API_BASE_URL = "gitlab.com/api/v4"; | ||
function readGitLabIntegrationConfig(config2) { | ||
var _a; | ||
const host = (_a = config2.getOptionalString("host")) != null ? _a : GITLAB_HOST; | ||
let apiBaseUrl = config2.getOptionalString("apiBaseUrl"); | ||
const token = config2.getOptionalString("token"); | ||
return {host, token}; | ||
if (!isValidHost(host)) { | ||
throw new Error(`Invalid GitLab integration config, '${host}' is not a valid host`); | ||
} | ||
if (apiBaseUrl) { | ||
apiBaseUrl = apiBaseUrl.replace(/\/+$/, ""); | ||
} else if (host === GITLAB_HOST) { | ||
apiBaseUrl = GITLAB_API_BASE_URL; | ||
} | ||
return {host, token, apiBaseUrl}; | ||
} | ||
@@ -282,3 +347,3 @@ function readGitLabIntegrationConfigs(configs) { | ||
if (!url.pathname.includes("/-/blob/")) { | ||
throw new Error("Please provide full path to yaml file from Gitlab"); | ||
throw new Error("Please provide full path to yaml file from GitLab"); | ||
} | ||
@@ -402,3 +467,3 @@ try { | ||
export { ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs }; | ||
export { ScmIntegrations, getAzureDownloadUrl, getAzureFileFetchUrl, getAzureRequestOptions, getBitbucketDefaultBranch, getBitbucketDownloadUrl, getBitbucketFileFetchUrl, getBitbucketRequestOptions, getGitHubFileFetchUrl, getGitHubRequestOptions, getGitLabFileFetchUrl, getGitLabRequestOptions, readAzureIntegrationConfig, readAzureIntegrationConfigs, readBitbucketIntegrationConfig, readBitbucketIntegrationConfigs, readGitHubIntegrationConfig, readGitHubIntegrationConfigs, readGitLabIntegrationConfig, readGitLabIntegrationConfigs }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@backstage/integration", | ||
"version": "0.0.0-nightly-202011921610", | ||
"version": "0.0.0-nightly-20210124517", | ||
"main": "dist/index.cjs.js", | ||
@@ -32,8 +32,9 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@backstage/config": "^0.1.1", | ||
"@backstage/config": "^0.1.2", | ||
"cross-fetch": "^3.0.6", | ||
"git-url-parse": "^11.4.0" | ||
"git-url-parse": "^11.4.3" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "^0.0.0-nightly-202011921610", | ||
"@backstage/cli": "^0.4.2", | ||
"@backstage/test-utils": "^0.1.5", | ||
"@types/jest": "^26.0.7", | ||
@@ -40,0 +41,0 @@ "msw": "^0.21.2" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135066
1266
4
3
25
26
226
Updated@backstage/config@^0.1.2
Updatedgit-url-parse@^11.4.3