Merge pull request #17624 from backstage/mob/ingestion

[cli]: Expand `onboard` command with an entity discovery feature
This commit is contained in:
Fredrik Adelöw
2023-05-30 13:46:02 +02:00
committed by GitHub
24 changed files with 1247 additions and 9 deletions
+26
View File
@@ -176,6 +176,18 @@ export class DefaultGithubCredentialsProvider
getCredentials(opts: { url: string }): Promise<GithubCredentials>;
}
// @public
export class DefaultGitlabCredentialsProvider
implements GitlabCredentialsProvider
{
// (undocumented)
static fromIntegrations(
integrations: ScmIntegrationRegistry,
): DefaultGitlabCredentialsProvider;
// (undocumented)
getCredentials(opts: { url: string }): Promise<GitlabCredentials>;
}
// @public
export function defaultScmResolveUrl(options: {
url: string;
@@ -489,6 +501,20 @@ export type GithubIntegrationConfig = {
apps?: GithubAppConfig[];
};
// @public (undocumented)
export type GitlabCredentials = {
headers?: {
[name: string]: string;
};
token?: string;
};
// @public (undocumented)
export interface GitlabCredentialsProvider {
// (undocumented)
getCredentials(opts: { url: string }): Promise<GitlabCredentials>;
}
// @public
export class GitLabIntegration implements ScmIntegration {
constructor(integrationConfig: GitLabIntegrationConfig);
@@ -0,0 +1,57 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ScmIntegrationRegistry } from '../registry';
import { SingleInstanceGitlabCredentialsProvider } from './SingleInstanceGitlabCredentialsProvider';
import { GitlabCredentials, GitlabCredentialsProvider } from './types';
/**
* Handles the creation and caching of credentials for GitLab integrations.
*
* @public
*/
export class DefaultGitlabCredentialsProvider
implements GitlabCredentialsProvider
{
static fromIntegrations(integrations: ScmIntegrationRegistry) {
const credentialsProviders: Map<string, GitlabCredentialsProvider> =
new Map<string, GitlabCredentialsProvider>();
integrations.gitlab.list().forEach(integration => {
const credentialsProvider =
SingleInstanceGitlabCredentialsProvider.create(integration.config);
credentialsProviders.set(integration.config.host, credentialsProvider);
});
return new DefaultGitlabCredentialsProvider(credentialsProviders);
}
private constructor(
private readonly providers: Map<string, GitlabCredentialsProvider>,
) {}
async getCredentials(opts: { url: string }): Promise<GitlabCredentials> {
const parsed = new URL(opts.url);
const provider = this.providers.get(parsed.host);
if (!provider) {
throw new Error(
`There is no GitLab integration that matches ${opts.url}. Please add a configuration for an integration.`,
);
}
return provider.getCredentials(opts);
}
}
@@ -0,0 +1,43 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { GitLabIntegrationConfig } from './config';
import { GitlabCredentials, GitlabCredentialsProvider } from './types';
export class SingleInstanceGitlabCredentialsProvider
implements GitlabCredentialsProvider
{
static create: (
config: GitLabIntegrationConfig,
) => GitlabCredentialsProvider = config => {
return new SingleInstanceGitlabCredentialsProvider(config.token);
};
private constructor(private readonly token?: string) {}
async getCredentials(_opts: { url: string }): Promise<GitlabCredentials> {
if (!this.token) {
return {};
}
return {
headers: {
Authorization: `Bearer ${this.token}`,
},
token: this.token,
};
}
}
+2
View File
@@ -22,3 +22,5 @@ export {
export type { GitLabIntegrationConfig } from './config';
export { getGitLabFileFetchUrl, getGitLabRequestOptions } from './core';
export { GitLabIntegration, replaceGitLabUrlType } from './GitLabIntegration';
export { DefaultGitlabCredentialsProvider } from './DefaultGitlabCredentialsProvider';
export type { GitlabCredentials, GitlabCredentialsProvider } from './types';
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @public
*/
export type GitlabCredentials = {
headers?: { [name: string]: string };
token?: string;
};
/**
* @public
*/
export interface GitlabCredentialsProvider {
getCredentials(opts: { url: string }): Promise<GitlabCredentials>;
}