Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes incorrect bitbucket cloud auth options #285

Merged
merged 2 commits into from Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
114 changes: 37 additions & 77 deletions cli/src/bitbucket/run.ts
Expand Up @@ -11,7 +11,6 @@ import {
Emoji,
errorLog,
parseIntegerPositive,
terminalLink,
toStringList,
} from '../utils';
import {
Expand Down Expand Up @@ -41,13 +40,8 @@ interface BitbucketConfig {
export function makeBitbucketCommand(): Command {
const cmd = new Command()
.name('bitbucket')
.option(
'--server-url <server-url>',
'API URL, defaults to https://api.bitbucket.org/2.0'
)
.option('--username <username>', 'Username')
.option('--password <password>', 'Password')
.option('--token <token>', 'Personal Access Token')
.option('--password <password>', 'App Password')
.option('--workspace <workspace>', 'Workspace')
.addOption(
new Option(
Expand Down Expand Up @@ -78,76 +72,43 @@ export function makeBitbucketCommand(): Command {
export async function runBitbucket(cfg: BitbucketConfig): Promise<void> {
await cfg.airbyte.waitUntilHealthy();

const serverUrl =
cfg.serverUrl ||
(await runInput({
name: 'server_url',
message: 'Enter the API URL, defaults to https://api.bitbucket.org/2.0',
})) ||
DEFAULT_API_URL;

let authenticationMethod;
if (cfg.token) {
authenticationMethod = 'Personal Access Token';
} else if (cfg.username || cfg.password) {
authenticationMethod = 'Username/Password';
} else {
authenticationMethod = await runSelect({
name: 'authenticationMethod',
message: 'Choose your authentication method',
choices: ['Username/Password', 'Personal Access Token'],
});
}

let bitbucket = new Bitbucket({});
let username, password, token;
const serverUrl = DEFAULT_API_URL;

switch (authenticationMethod) {
case 'Username/Password':
username =
cfg.username ||
(await runInput({
name: 'username',
message: 'Username?',
}));
password =
cfg.password ||
(await runPassword({
name: 'password',
message: 'Password?',
}));
bitbucket = new Bitbucket({
auth: {
username,
password,
},
});
break;
case 'Personal Access Token':
if (!cfg.password) {
display(
`Visit our ${await terminalLink(
'docs',
'https://community.faros.ai/docs/faros-essentials#api-token-requirements'
)} for token requirements`
);
}
token =
cfg.password ||
(await runPassword({
name: 'token',
message: 'Enter your Personal Access Token',
}));
bitbucket = new Bitbucket({
auth: {
token,
},
});
break;
const username =
cfg.username ||
(await runInput({
name: 'username',
message: 'Username?',
}));

if (!cfg.password) {
display(
`Provide Bitbucket "App Password" with read permissions:
Account: read
Pull Requests: read
Issues: read
Workspace membership: read
Projects: read
Repositories: read
Pipelines: read`
);
display('Note: Bitbucket Server not yet supported');
}
const password =
cfg.password ||
(await runPassword({
name: 'token',
message: 'Enter your App Password',
}));
const bitbucket = new Bitbucket({
auth: {
username,
password,
},
});

const workspaces = cfg.workspace;
const repos = cfg.repoList;
let workspaces = cfg.workspace;
let repos = cfg.repoList;

try {
if (!repos || repos.length === 0) {
Expand All @@ -164,15 +125,15 @@ export async function runBitbucket(cfg: BitbucketConfig): Promise<void> {
}
let done = false;
while (!done) {
const workspaces =
workspaces =
cfg.workspace ||
(await runSelect({
name: 'workspaces',
message: 'Select your favorite workspace',
choices: await getWorkspaces(bitbucket),
}));

const repos =
repos =
cfg.repoList ||
(await runMultiSelect({
name: 'repos',
Expand Down Expand Up @@ -214,7 +175,6 @@ export async function runBitbucket(cfg: BitbucketConfig): Promise<void> {
cutoff_days: cfg.cutoffDays || DEFAULT_CUTOFF_DAYS,
username,
password,
token,
pagelen: 10,
},
name: 'Bitbucket',
Expand Down
22 changes: 18 additions & 4 deletions cli/src/cli.ts
Expand Up @@ -8,7 +8,7 @@ import {makeGitlabCommand, runGitlab} from './gitlab/run';
import {makeJiraCommand, runJira} from './jira/run';
import {Metabase} from './metabase/metabase-client';
import {makeRefreshCommand, runRefresh} from './refresh/run';
import {display, terminalLink} from './utils';
import {display, Emoji, terminalLink} from './utils';
import {runSelect} from './utils/prompts';

const DEFAULT_AIRBYTE_URL = 'http://localhost:8000';
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function main(): Promise<void> {
choices: [
'GitHub (Cloud)',
'GitLab (Cloud / Server)',
'Bitbucket (Cloud / Server)',
'Bitbucket (Cloud)',
'Jira (Cloud)',
'Refresh existing sources',
'I\'m done!',
Expand All @@ -65,7 +65,7 @@ export async function main(): Promise<void> {
case 'GitLab (Cloud / Server)':
await runGitlab({airbyte, metabase});
break;
case 'Bitbucket (Cloud / Server)':
case 'Bitbucket (Cloud)':
await runBitbucket({airbyte, metabase});
break;
case 'Jira (Cloud)':
Expand Down Expand Up @@ -94,6 +94,15 @@ export async function main(): Promise<void> {
'Metabase password',
DEFAULT_METABASE_PASSWORD
)
.hook('preAction', async () => {
display('%s Welcome to Faros Essentials!', Emoji.HELLO);
display(
`For documentation, please see this ${await terminalLink(
'page',
'https://community.faros.ai/docs/faros-essentials'
)}.`
);
})
.hook('postAction', async (thisCommand) => {
display(
`Check out your metrics in ${await terminalLink(
Expand All @@ -116,7 +125,12 @@ export async function main(): Promise<void> {
);
display('You can run this CLI again with ./run_cli.sh');
display('You can stop Faros with ./stop.sh');
display('For more help, go to https://community.faros.ai/docs/faros-essentials');
display(
`For help, go to this ${await terminalLink(
'page',
'https://community.faros.ai/docs/faros-essentials'
)}.`
);
});
});

Expand Down
8 changes: 3 additions & 5 deletions cli/src/github/run.ts
Expand Up @@ -10,7 +10,6 @@ import {
Emoji,
errorLog,
parseIntegerPositive,
terminalLink,
toStringList,
} from '../utils';
import {
Expand Down Expand Up @@ -69,11 +68,10 @@ export async function runGithub(cfg: GithubConfig): Promise<void> {
await cfg.airbyte.waitUntilHealthy();
if (!cfg.token) {
display(
`Visit our ${await terminalLink(
'docs',
'https://community.faros.ai/docs/faros-essentials#api-token-requirements'
)} for token requirements`
`Provide GitHub API token with read permissions:
repo, read:org, read:user`
);
display('Note: GitHub Enterprise Server not yet supported');
}
const token =
cfg.token ||
Expand Down
6 changes: 1 addition & 5 deletions cli/src/gitlab/run.ts
Expand Up @@ -10,7 +10,6 @@ import {
Emoji,
errorLog,
parseIntegerPositive,
terminalLink,
toStringList,
} from '../utils';
import {
Expand Down Expand Up @@ -73,10 +72,7 @@ export async function runGitlab(cfg: GitLabConfig): Promise<void> {
await cfg.airbyte.waitUntilHealthy();
if (!cfg.token) {
display(
`Visit our ${await terminalLink(
'docs',
'https://community.faros.ai/docs/faros-essentials#api-token-requirements'
)} for token requirements`
'Provide GitLab personal access token with read permissions: read_api'
);
}
const api_url =
Expand Down
10 changes: 5 additions & 5 deletions cli/src/jira/run.ts
Expand Up @@ -10,7 +10,6 @@ import {
Emoji,
errorLog,
parseIntegerPositive,
terminalLink,
toStringList,
} from '../utils';
import {
Expand Down Expand Up @@ -73,11 +72,12 @@ export async function runJira(cfg: JiraConfig): Promise<void> {
await cfg.airbyte.waitUntilHealthy();
if (!cfg.token) {
display(
`Visit our ${await terminalLink(
'docs',
'https://community.faros.ai/docs/faros-essentials#api-token-requirements'
)} for token requirements`
`The integration user needs application access to Jira,
the 'Browse Users' global permission,
the 'Browse Project' permission for each project,
and the 'View Development Tools' permission for each project`
);
display('Note: Jira Server/DC not yet supported');
}
const domain =
cfg.domain ||
Expand Down
1 change: 1 addition & 0 deletions cli/src/utils/index.ts
Expand Up @@ -13,6 +13,7 @@ export enum Emoji {
PROGRESS = '⏳',
EMPTY = '🪹',
STOPWATCH = '⏱',
HELLO = '👋',
}

function processEmoji(...args: any[]): any[] {
Expand Down