Add fromConfig remove logging
This commit is contained in:
@@ -38,7 +38,7 @@ export default async function createPlugin({
|
||||
templaters.register('cra', craTemplater);
|
||||
|
||||
const preparers = await Preparers.fromConfig(config, { logger });
|
||||
const publishers = await Publishers.fromConfig(config, { logger });
|
||||
const publishers = await Publishers.fromConfig(config);
|
||||
|
||||
const dockerClient = new Docker();
|
||||
|
||||
|
||||
@@ -33,19 +33,13 @@ export class AzurePreparer implements PreparerBase {
|
||||
private readonly scaffolderToken: string | undefined;
|
||||
|
||||
static fromConfig(config: Config, { logger }: { logger: Logger }) {
|
||||
const integrations = readAzureIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.azure') ?? [],
|
||||
);
|
||||
|
||||
if (
|
||||
config.getOptionalString('scaffolder.azure.api.token') &&
|
||||
!integrations.length
|
||||
) {
|
||||
if (config.getOptionalString('scaffolder.azure.api.token')) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the token format under 'scaffolder.azure.api.token' will not be respected in future releases. Please consider using integrations config instead",
|
||||
'Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
);
|
||||
}
|
||||
|
||||
return new AzurePreparer(config);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,17 +34,13 @@ export class BitbucketPreparer implements PreparerBase {
|
||||
private readonly integrations: BitbucketIntegrationConfig[];
|
||||
|
||||
static fromConfig(config: Config, { logger }: { logger: Logger }) {
|
||||
const integrations = readBitbucketIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.bitbucket') ?? [],
|
||||
);
|
||||
|
||||
const user = config.getOptionalString('scaffolder.bitbucket.api.username');
|
||||
const token = config.getOptionalString('scaffolder.bitbucket.api.token');
|
||||
const password = config.getOptionalString(
|
||||
'scaffolder.bitbucket.api.appPassword',
|
||||
);
|
||||
|
||||
if (!integrations && (user || token || password)) {
|
||||
if (user || token || password) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Setting credentials under 'scaffolder.bitbucket.api' will not be respected in future releases. Please consider using integrations config instead",
|
||||
'Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
|
||||
@@ -33,14 +33,7 @@ export class GithubPreparer implements PreparerBase {
|
||||
private readonly scaffolderToken: string | undefined;
|
||||
|
||||
static fromConfig(config: Config, { logger }: { logger: Logger }) {
|
||||
const integrations = readGitHubIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.github') ?? [],
|
||||
);
|
||||
|
||||
if (
|
||||
config.getOptionalString('scaffolder.github.token') &&
|
||||
!integrations.length
|
||||
) {
|
||||
if (config.getOptionalString('scaffolder.github.token')) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the token format under 'scaffolder.github.token' will not be respected in future releases. Please consider using integrations config instead",
|
||||
'Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
|
||||
@@ -33,14 +33,7 @@ export class GitlabPreparer implements PreparerBase {
|
||||
private readonly scaffolderToken: string | undefined;
|
||||
|
||||
static fromConfig(config: Config, { logger }: { logger: Logger }) {
|
||||
const integrations = readGitLabIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.gitlab') ?? [],
|
||||
);
|
||||
|
||||
if (
|
||||
config.getOptionalString('scaffolder.gitlab.api.token') &&
|
||||
!integrations.length
|
||||
) {
|
||||
if (config.getOptionalString('scaffolder.gitlab.api.token')) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the token format under 'scaffolder.gitlab.token' will not be respected in future releases. Please consider using integrations config instead",
|
||||
'Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
|
||||
@@ -51,7 +51,6 @@ describe('Azure Publisher', () => {
|
||||
},
|
||||
},
|
||||
}),
|
||||
{ logger },
|
||||
);
|
||||
mockGitClient.createRepository.mockResolvedValue({
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
@@ -106,7 +105,6 @@ describe('Azure Publisher', () => {
|
||||
],
|
||||
},
|
||||
}),
|
||||
{ logger },
|
||||
);
|
||||
mockGitClient.createRepository.mockResolvedValue({
|
||||
remoteUrl: 'https://dev.azure.com/organization/project/_git/repo',
|
||||
|
||||
@@ -19,7 +19,6 @@ import { IGitApi } from 'azure-devops-node-api/GitApi';
|
||||
import { GitRepositoryCreateOptions } from 'azure-devops-node-api/interfaces/GitInterfaces';
|
||||
import { Config } from '@backstage/config';
|
||||
import { initRepoAndPush } from './helpers';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
AzureIntegrationConfig,
|
||||
readAzureIntegrationConfigs,
|
||||
@@ -32,33 +31,18 @@ export class AzurePublisher implements PublisherBase {
|
||||
private readonly apiBaseUrl?: string;
|
||||
private readonly token?: string;
|
||||
|
||||
constructor(config: Config, { logger }: { logger: Logger }) {
|
||||
static fromConfig(config: Config) {
|
||||
return new AzurePublisher(config);
|
||||
}
|
||||
|
||||
constructor(config: Config) {
|
||||
this.integrations = readAzureIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.azure') ?? [],
|
||||
);
|
||||
|
||||
if (!this.integrations.length) {
|
||||
logger.warn(
|
||||
'Integrations for Azure in Scaffolder are not set. This will cause errors in a future release. Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
);
|
||||
}
|
||||
|
||||
this.token = config.getOptionalString('scaffolder.azure.api.token');
|
||||
if (this.token) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the token format under 'scaffolder.github.api.token' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
|
||||
this.apiBaseUrl = config.getOptionalString('scaffolder.azure.api.baseUrl');
|
||||
|
||||
if (this.apiBaseUrl) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the apiBaseUrl format under 'scaffolder.azure.api.baseUrl' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async publish({
|
||||
values,
|
||||
directory,
|
||||
|
||||
@@ -71,9 +71,6 @@ describe('Bitbucket Publisher', () => {
|
||||
],
|
||||
},
|
||||
}),
|
||||
{
|
||||
logger: getVoidLogger(),
|
||||
},
|
||||
);
|
||||
|
||||
const result = await publisher.publish({
|
||||
@@ -140,9 +137,6 @@ describe('Bitbucket Publisher', () => {
|
||||
],
|
||||
},
|
||||
}),
|
||||
{
|
||||
logger: getVoidLogger(),
|
||||
},
|
||||
);
|
||||
|
||||
const result = await publisher.publish({
|
||||
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
BitbucketIntegrationConfig,
|
||||
readBitbucketIntegrationConfigs,
|
||||
} from '@backstage/integration';
|
||||
import { Logger } from 'winston';
|
||||
import gitUrlParse from 'git-url-parse';
|
||||
|
||||
// TODO(blam): We should probably start to use a bitbucket client here that we can change
|
||||
@@ -35,48 +34,21 @@ export class BitbucketPublisher implements PublisherBase {
|
||||
private readonly appPassword?: string;
|
||||
private readonly integrations: BitbucketIntegrationConfig[];
|
||||
|
||||
constructor(config: Config, { logger }: { logger: Logger }) {
|
||||
static fromConfig(config: Config) {
|
||||
return new BitbucketPublisher(config);
|
||||
}
|
||||
constructor(config: Config) {
|
||||
this.integrations = readBitbucketIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.bitbucket') ?? [],
|
||||
);
|
||||
|
||||
if (!this.integrations.length) {
|
||||
logger.warn(
|
||||
'Integrations for Bitbucket in Scaffolder are not set. This will cause errors in a future release. Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
);
|
||||
}
|
||||
|
||||
this.token = config.getOptionalString('scaffolder.bitbucket.api.token');
|
||||
if (this.token) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the token format under 'scaffolder.bitbucket.api.token' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
|
||||
this.host = config.getOptionalString('scaffolder.bitbucket.api.host');
|
||||
if (this.host) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the apiBaseUrl format under 'scaffolder.bitbucket.api.host' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
|
||||
this.username = config.getOptionalString(
|
||||
'scaffolder.bitbucket.api.username',
|
||||
);
|
||||
if (this.username) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the apiBaseUrl format under 'scaffolder.bitbucket.api.username' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
|
||||
this.appPassword = config.getOptionalString(
|
||||
'scaffolder.bitbucket.api.appPassword',
|
||||
);
|
||||
if (this.appPassword) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the appPassword format under 'scaffolder.bitbucket.api.appassword' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async publish({
|
||||
|
||||
@@ -49,9 +49,6 @@ describe('GitHub Publisher', () => {
|
||||
],
|
||||
},
|
||||
}),
|
||||
{
|
||||
logger,
|
||||
},
|
||||
);
|
||||
|
||||
describe('publish: createRemoteInGithub', () => {
|
||||
@@ -211,7 +208,6 @@ describe('GitHub Publisher', () => {
|
||||
},
|
||||
},
|
||||
}),
|
||||
{ logger },
|
||||
);
|
||||
|
||||
it('creates a private repository in the organization with visibility set to internal', async () => {
|
||||
@@ -273,9 +269,6 @@ describe('GitHub Publisher', () => {
|
||||
},
|
||||
},
|
||||
}),
|
||||
{
|
||||
logger,
|
||||
},
|
||||
);
|
||||
|
||||
it('creates a private repository', async () => {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
import { PublisherBase, PublisherOptions, PublisherResult } from './types';
|
||||
import { initRepoAndPush } from './helpers';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
GitHubIntegrationConfig,
|
||||
readGitHubIntegrationConfigs,
|
||||
@@ -32,35 +31,20 @@ export class GithubPublisher implements PublisherBase {
|
||||
private readonly apiBaseUrl: string | undefined;
|
||||
private readonly repoVisibility: RepoVisibilityOptions;
|
||||
|
||||
constructor(config: Config, { logger }: { logger: Logger }) {
|
||||
static fromConfig(config: Config) {
|
||||
return new GithubPublisher(config);
|
||||
}
|
||||
constructor(config: Config) {
|
||||
this.integrations = readGitHubIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.github') ?? [],
|
||||
);
|
||||
|
||||
if (!this.integrations.length) {
|
||||
logger.warn(
|
||||
'Integrations for GitHub in Scaffolder are not set. This will cause errors in a future release. Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
);
|
||||
}
|
||||
|
||||
this.scaffolderToken = config.getOptionalString(
|
||||
'scaffolder.github.api.token',
|
||||
);
|
||||
|
||||
this.apiBaseUrl = config.getOptionalString('scaffolder.github.api.baseUrl');
|
||||
|
||||
if (this.scaffolderToken) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the token format under 'scaffolder.github.api.token' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
|
||||
if (this.apiBaseUrl) {
|
||||
logger.warn(
|
||||
"DEPRECATION: Using the apiBaseUrl format under 'scaffolder.github.api.baseUrl' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
|
||||
this.repoVisibility = (config.getOptionalString(
|
||||
'scaffolder.github.visibility',
|
||||
) ?? 'public') as RepoVisibilityOptions;
|
||||
|
||||
@@ -61,7 +61,6 @@ describe('GitLab Publisher', () => {
|
||||
],
|
||||
},
|
||||
}),
|
||||
{ logger },
|
||||
);
|
||||
|
||||
mockGitlabClient.Namespaces.show.mockResolvedValue({
|
||||
@@ -109,7 +108,6 @@ describe('GitLab Publisher', () => {
|
||||
],
|
||||
},
|
||||
}),
|
||||
{ logger },
|
||||
);
|
||||
|
||||
mockGitlabClient.Namespaces.show.mockResolvedValue({});
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
import { PublisherBase, PublisherOptions, PublisherResult } from './types';
|
||||
import { Gitlab } from '@gitbeaker/node';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Logger } from 'winston';
|
||||
import { initRepoAndPush } from './helpers';
|
||||
import gitUrlParse from 'git-url-parse';
|
||||
|
||||
@@ -30,37 +29,20 @@ export class GitlabPublisher implements PublisherBase {
|
||||
private readonly integrations: GitLabIntegrationConfig[];
|
||||
private readonly scaffolderToken: string | undefined;
|
||||
private readonly apiBaseUrl: string | undefined;
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(config: Config, { logger }: { logger: Logger }) {
|
||||
this.logger = logger;
|
||||
constructor(config: Config) {
|
||||
this.integrations = readGitLabIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.gitlab') ?? [],
|
||||
);
|
||||
|
||||
if (!this.integrations.length) {
|
||||
this.logger.warn(
|
||||
'Integrations for GitLab in Scaffolder are not set. This will cause errors in a future release. Please migrate to using integrations config and specifying tokens under hostnames',
|
||||
);
|
||||
}
|
||||
|
||||
this.scaffolderToken = config.getOptionalString(
|
||||
'scaffolder.gitlab.api.token',
|
||||
);
|
||||
|
||||
this.apiBaseUrl = config.getOptionalString('scaffolder.gitlab.api.baseUrl');
|
||||
}
|
||||
|
||||
if (this.scaffolderToken) {
|
||||
this.logger.warn(
|
||||
"DEPRECATION: Using the token format under 'scaffolder.gitlab.api.token' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
|
||||
if (this.apiBaseUrl) {
|
||||
this.logger.warn(
|
||||
"DEPRECATION: Using the apiBaseUrl format under 'scaffolder.gitlab.api.baseUrl' will not be respected in future releases. Please consider using integrations config instead",
|
||||
);
|
||||
}
|
||||
static fromConfig(config: Config) {
|
||||
return new GitlabPublisher(config);
|
||||
}
|
||||
|
||||
async publish({
|
||||
|
||||
@@ -40,9 +40,7 @@ describe('Publishers', () => {
|
||||
});
|
||||
|
||||
it('should return the correct preparer when the source matches for github', async () => {
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}), {
|
||||
logger: getVoidLogger(),
|
||||
});
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}));
|
||||
|
||||
expect(
|
||||
publishers.get('https://github.com/org/repo', {
|
||||
@@ -52,9 +50,7 @@ describe('Publishers', () => {
|
||||
});
|
||||
|
||||
it('should return the correct preparer when the source matches for azure', async () => {
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}), {
|
||||
logger: getVoidLogger(),
|
||||
});
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}));
|
||||
|
||||
expect(
|
||||
publishers.get('https://dev.azure.com/org/project/_git/repo', {
|
||||
@@ -64,9 +60,7 @@ describe('Publishers', () => {
|
||||
});
|
||||
|
||||
it('should return the correct preparer when the source matches for bitbucket', async () => {
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}), {
|
||||
logger: getVoidLogger(),
|
||||
});
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}));
|
||||
|
||||
expect(
|
||||
publishers.get('https://bitbucket.org/owner/repo', {
|
||||
@@ -76,9 +70,7 @@ describe('Publishers', () => {
|
||||
});
|
||||
|
||||
it('should return the correct preparer when the source matches for gitlab', async () => {
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}), {
|
||||
logger: getVoidLogger(),
|
||||
});
|
||||
const publishers = await Publishers.fromConfig(new ConfigReader({}));
|
||||
|
||||
expect(
|
||||
publishers.get('https://gitlab.com/owner/repo', {
|
||||
@@ -96,9 +88,6 @@ describe('Publishers', () => {
|
||||
],
|
||||
},
|
||||
}),
|
||||
{
|
||||
logger: getVoidLogger(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(
|
||||
|
||||
@@ -62,24 +62,21 @@ export class Publishers implements PublisherBuilder {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
static async fromConfig(
|
||||
config: Config,
|
||||
{ logger }: { logger: Logger },
|
||||
): Promise<PublisherBuilder> {
|
||||
static async fromConfig(config: Config): Promise<PublisherBuilder> {
|
||||
const typeDetector = makeDeprecatedLocationTypeDetector(config);
|
||||
const publishers = new Publishers(typeDetector);
|
||||
|
||||
const githubPublisher = new GithubPublisher(config, { logger });
|
||||
const githubPublisher = GithubPublisher.fromConfig(config);
|
||||
publishers.register('file', githubPublisher);
|
||||
publishers.register('github', githubPublisher);
|
||||
|
||||
const gitLabPublisher = new GitlabPublisher(config, { logger });
|
||||
const gitLabPublisher = GitlabPublisher.fromConfig(config);
|
||||
publishers.register('gitlab', gitLabPublisher);
|
||||
|
||||
const azurePublisher = new AzurePublisher(config, { logger });
|
||||
const azurePublisher = AzurePublisher.fromConfig(config);
|
||||
publishers.register('azure', azurePublisher);
|
||||
|
||||
const bitbucketPublisher = new BitbucketPublisher(config, { logger });
|
||||
const bitbucketPublisher = BitbucketPublisher.fromConfig(config);
|
||||
publishers.register('bitbucket', bitbucketPublisher);
|
||||
|
||||
return publishers;
|
||||
|
||||
Reference in New Issue
Block a user