diff --git a/packages/cli/src/commands/onboard/auth/github/index.ts b/packages/cli/src/commands/onboard/auth/github/index.ts index ce53d23ad3..7e1e63a8fe 100644 --- a/packages/cli/src/commands/onboard/auth/github/index.ts +++ b/packages/cli/src/commands/onboard/auth/github/index.ts @@ -18,32 +18,18 @@ import { OAuthApp } from '@octokit/oauth-app'; import chalk from 'chalk'; import * as fs from 'fs-extra'; import inquirer from 'inquirer'; -import fetch from 'node-fetch'; import { Task } from '../../../../lib/tasks'; -import { addUserEntity, updateConfigFile } from '../../config'; -import { APP_CONFIG_FILE, PATCH_FOLDER, USER_ENTITY_FILE } from '../../files'; +import { updateConfigFile } from '../../config'; +import { APP_CONFIG_FILE, PATCH_FOLDER } from '../../files'; import { patch } from '../patch'; type Answers = { - username: string; clientSecret: string; clientId: string; hasEnterprise: boolean; enterpriseInstanceUrl?: string; }; -const catalogUserLocation = { - catalog: { - locations: [ - { - type: 'file', - target: '../../user-info.yaml', - rules: [{ allow: ['User'] }], - }, - ], - }, -}; - const validateCredentials = async (clientId: string, clientSecret: string) => { try { const app = new OAuthApp({ @@ -108,18 +94,6 @@ export const github = async () => { `); const answers = await inquirer.prompt([ - { - type: 'input', - name: 'username', - message: 'What is your GitHub username?', - validate: async (input: string) => { - const response = await fetch(`https://api.github.com/users/${input}`); - if (!response.ok) { - return chalk.red('Unknown user. Please try again.'); - } - return true; - }, - }, { type: 'input', name: 'clientId', @@ -146,7 +120,7 @@ export const github = async () => { }, ]); - const { username, clientId, clientSecret } = answers; + const { clientId, clientSecret } = answers; const config = getConfig(answers); Task.log('Setting up GitHub Authentication for you...'); @@ -159,19 +133,7 @@ export const github = async () => { await Task.forItem( 'Updating', APP_CONFIG_FILE, - async () => - await updateConfigFile(APP_CONFIG_FILE, { - ...config, - ...catalogUserLocation, - }), - ); - await Task.forItem( - 'Creating', - USER_ENTITY_FILE, - async () => - await addUserEntity(USER_ENTITY_FILE, username, { - 'github.com/user-login': username, - }), + async () => await updateConfigFile(APP_CONFIG_FILE, config), ); const patches = await fs.readdir(PATCH_FOLDER); diff --git a/packages/cli/src/commands/onboard/auth/gitlab/index.ts b/packages/cli/src/commands/onboard/auth/gitlab/index.ts index 702537fe70..1940f66017 100644 --- a/packages/cli/src/commands/onboard/auth/gitlab/index.ts +++ b/packages/cli/src/commands/onboard/auth/gitlab/index.ts @@ -18,8 +18,8 @@ import chalk from 'chalk'; import * as fs from 'fs-extra'; import inquirer from 'inquirer'; import { Task } from '../../../../lib/tasks'; -import { addUserEntity, updateConfigFile } from '../../config'; -import { APP_CONFIG_FILE, PATCH_FOLDER, USER_ENTITY_FILE } from '../../files'; +import { updateConfigFile } from '../../config'; +import { APP_CONFIG_FILE, PATCH_FOLDER } from '../../files'; import { patch } from '../patch'; const getConfig = (answers: Answers) => { @@ -43,7 +43,6 @@ const getConfig = (answers: Answers) => { }; type Answers = { - username: string; clientSecret: string; clientId: string; hasAudience: boolean; @@ -69,12 +68,6 @@ export const gitlab = async () => { `); const answers = await inquirer.prompt([ - { - type: 'input', - name: 'username', - message: 'What is your GitLab username?', - validate: (input: string) => (input.length ? true : false), - }, { type: 'input', name: 'clientId', @@ -101,7 +94,6 @@ export const gitlab = async () => { }, ]); - const { username } = answers; const config = getConfig(answers); Task.log('Setting up GitLab Authentication for you...'); @@ -111,11 +103,6 @@ export const gitlab = async () => { APP_CONFIG_FILE, async () => await updateConfigFile(APP_CONFIG_FILE, config), ); - await Task.forItem( - 'Creating', - USER_ENTITY_FILE, - async () => await addUserEntity(USER_ENTITY_FILE, username), - ); const patches = await fs.readdir(PATCH_FOLDER); for (const patchFile of patches.filter(p => p.includes('gitlab'))) { diff --git a/packages/cli/src/commands/onboard/auth/patches/02-github.Use-signIn-resolver.patch b/packages/cli/src/commands/onboard/auth/patches/02-github.Use-signIn-resolver.patch deleted file mode 100644 index 2baaff7cf9..0000000000 --- a/packages/cli/src/commands/onboard/auth/patches/02-github.Use-signIn-resolver.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- a/packages/backend/src/plugins/auth.ts -+++ b/packages/backend/src/plugins/auth.ts -@@ -40,10 +40 @@ export default async function createPlugin( -- resolver(_, ctx) { -- const userRef = 'user:default/guest'; // Must be a full entity reference -- return ctx.issueToken({ -- claims: { -- sub: userRef, // The user's own identity -- ent: [userRef], // A list of identities that the user claims ownership through -- }, -- }); -- }, -- // resolver: providers.github.resolvers.usernameMatchingUserEntityName(), -+ resolver: providers.github.resolvers.usernameMatchingUserEntityName(), \ No newline at end of file diff --git a/packages/cli/src/commands/onboard/auth/patches/03-gitlab.Add-SignInPage.patch b/packages/cli/src/commands/onboard/auth/patches/02-gitlab.Add-SignInPage.patch similarity index 100% rename from packages/cli/src/commands/onboard/auth/patches/03-gitlab.Add-SignInPage.patch rename to packages/cli/src/commands/onboard/auth/patches/02-gitlab.Add-SignInPage.patch diff --git a/packages/cli/src/commands/onboard/auth/patches/03-gitlab.Change-signIn-resolver.patch b/packages/cli/src/commands/onboard/auth/patches/03-gitlab.Change-signIn-resolver.patch new file mode 100644 index 0000000000..7a69669674 --- /dev/null +++ b/packages/cli/src/commands/onboard/auth/patches/03-gitlab.Change-signIn-resolver.patch @@ -0,0 +1,5 @@ +--- a/packages/backend/src/plugins/auth.ts ++++ b/packages/backend/src/plugins/auth.ts +@@ -38 +38 @@ export default async function createPlugin( +- github: providers.github.create({ ++ gitlab: providers.gitlab.create({ \ No newline at end of file diff --git a/packages/cli/src/commands/onboard/auth/patches/04-gitlab.Use-signIn-resolver.patch b/packages/cli/src/commands/onboard/auth/patches/04-gitlab.Use-signIn-resolver.patch deleted file mode 100644 index 04b432c179..0000000000 --- a/packages/cli/src/commands/onboard/auth/patches/04-gitlab.Use-signIn-resolver.patch +++ /dev/null @@ -1,27 +0,0 @@ ---- a/packages/backend/src/plugins/auth.ts -+++ b/packages/backend/src/plugins/auth.ts -@@ -38 +38 @@ export default async function createPlugin( -- github: providers.github.create({ -+ gitlab: providers.gitlab.create({ -@@ -40,8 +40,11 @@ export default async function createPlugin( -- resolver(_, ctx) { -- const userRef = 'user:default/guest'; // Must be a full entity reference -- return ctx.issueToken({ -- claims: { -- sub: userRef, // The user's own identity -- ent: [userRef], // A list of identities that the user claims ownership through -- }, -- }); -+ async resolver(info, ctx) { -+ const { fullProfile } = info.result; -+ -+ const userId = fullProfile.username; -+ if (!userId) { -+ throw new Error( -+ `GitLab user profile does not contain a username`, -+ ); -+ } -+ -+ return ctx.signInWithCatalogUser({ entityRef: { name: userId } }); -@@ -49 +51,0 @@ export default async function createPlugin( -- // resolver: providers.github.resolvers.usernameMatchingUserEntityName(), \ No newline at end of file diff --git a/packages/cli/src/commands/onboard/config.ts b/packages/cli/src/commands/onboard/config.ts index b5a2336a0a..8d419dd71a 100644 --- a/packages/cli/src/commands/onboard/config.ts +++ b/packages/cli/src/commands/onboard/config.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { UserEntity } from '@backstage/catalog-model'; import * as fs from 'fs-extra'; import yaml from 'yaml'; @@ -35,29 +34,3 @@ export const updateConfigFile = async (file: string, config: T) => { 'utf8', ); }; - -export const addUserEntity = async ( - file: string, - username: string, - annotations?: Record, -) => { - const content: UserEntity = { - apiVersion: 'backstage.io/v1alpha1', - kind: 'User', - metadata: { - name: username, - annotations: { ...annotations }, - }, - spec: { - memberOf: [], - }, - }; - - return await fs.writeFile( - file, - yaml.stringify(content, { - indent: 2, - }), - 'utf8', - ); -}; diff --git a/packages/cli/src/commands/onboard/files.ts b/packages/cli/src/commands/onboard/files.ts index af07ef254b..17f8a0f85e 100644 --- a/packages/cli/src/commands/onboard/files.ts +++ b/packages/cli/src/commands/onboard/files.ts @@ -20,7 +20,6 @@ import * as path from 'path'; /* eslint-disable-next-line no-restricted-syntax */ const { targetRoot, ownDir } = findPaths(__dirname); export const APP_CONFIG_FILE = path.join(targetRoot, 'app-config.local.yaml'); -export const USER_ENTITY_FILE = path.join(targetRoot, 'user-info.yaml'); export const PATCH_FOLDER = path.join( ownDir, 'src',