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

Address comments in #28 #43

Merged
merged 3 commits into from
Dec 17, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ devhtml/**
.yalc/**
.storybook/**
jest.config.js
.test-extensions/**
19 changes: 15 additions & 4 deletions src/atlclients/clientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ export class ClientManager implements Disposable {
} else {
result = {
repositories: isBasicAuthInfo(info)
? new ServerRepositoriesApi(this.createBasicHTTPClient(site, info.username, info.password))
? new ServerRepositoriesApi(this.createHTTPClient(site, info))
: undefined!,
pullrequests: isBasicAuthInfo(info)
? new ServerPullRequestApi(this.createBasicHTTPClient(site, info.username, info.password))
? new ServerPullRequestApi(this.createHTTPClient(site, info))
: undefined!,
issues: undefined,
pipelines: undefined,
Expand Down Expand Up @@ -216,10 +216,21 @@ export class ClientManager implements Disposable {
);
}

private createBasicHTTPClient(site: DetailedSiteInfo, username: string, password: string): HTTPClient {
private createHTTPClient(site: DetailedSiteInfo, info: AuthInfo): HTTPClient {
let auth = '';
if (isBasicAuthInfo(info)) {
Logger.info('Using Username and Password Auth');
auth = `Basic ${Buffer.from(info.username + ':' + info.password).toString('base64')}`;
} else if (isPATAuthInfo(info)) {
Logger.info('Using PAT Auth');
auth = `Bearer ${info.token}`;
} else {
Logger.warn('Auth format not recognized');
}

return new HTTPClient(
site.baseApiUrl,
`Basic ${Buffer.from(username + ':' + password).toString('base64')}`,
auth,
getAgent(site),
async (response: AxiosResponse): Promise<Error> => {
let errString = 'Unknown error';
Expand Down
21 changes: 12 additions & 9 deletions src/atlclients/loginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import { Logger } from '../logger';
import { OAuthDancer } from './oauthDancer';
import { SiteManager } from '../siteManager';

const slugRegex = /[\[\:\/\?#@\!\$&'\(\)\*\+,;\=%\\\[\]]/gi;

export class LoginManager {
private _dancer: OAuthDancer = OAuthDancer.Instance;
private _jiraAuthenticator: JiraAuthenticator;
Expand Down Expand Up @@ -156,24 +154,29 @@ export class LoginManager {
let apiUrl = '';
const protocol = site.protocol ? site.protocol : 'https:';
const contextPath = site.contextPath ? site.contextPath : '';
const transport = getAxiosInstance();
switch (site.product.key) {
case ProductJira.key:
siteDetailsUrl = `${protocol}//${site.host}${contextPath}/rest/api/2/myself`;
avatarUrl = `${protocol}//${site.host}${contextPath}/images/fav-jcore.png`;
apiUrl = `${protocol}//${site.host}${contextPath}/rest`;
break;
case ProductBitbucket.key:
const bbCredentials = credentials as BasicAuthInfo;
siteDetailsUrl = `${protocol}//${
site.host
}${contextPath}/rest/api/1.0/users/${bbCredentials.username.replace(slugRegex, '_')}?avatarSize=64`;
avatarUrl = '';
apiUrl = `${protocol}//${site.host}${contextPath}`;
// Needed when using a API key to login (credentials is PATAuthInfo):
const res = await transport(`${apiUrl}/rest/api/latest/build/capabilities`, {
method: 'GET',
headers: {
Authorization: authHeader,
},
...getAgent(site),
});
let ausername = res.headers['x-ausername'];
siteDetailsUrl = `${apiUrl}/rest/api/1.0/users/${ausername}`;
avatarUrl = `${apiUrl}/users/${ausername}/avatar.png?s=64`;
break;
}

const transport = getAxiosInstance();

const res = await transport(siteDetailsUrl, {
method: 'GET',
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/react/atlascode/config/auth/AuthDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@
[],
);

const registerUrl = useCallback(register(validateStartsWithProtocol), []);

Check warning on line 206 in src/react/atlascode/config/auth/AuthDialog.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
const registerRequiredString = useCallback(register(validateRequiredString), []);

Check warning on line 207 in src/react/atlascode/config/auth/AuthDialog.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
return (
<Dialog fullWidth maxWidth="md" open={open} onExited={onExited}>
<DialogTitle>
Expand Down Expand Up @@ -278,7 +278,7 @@
}}
>
<Tab label="Username and Password" />
{product.key === ProductJira.key && <Tab label="Personal Access Token" />}
<Tab label="Personal Access Token" />
</Tabs>
<TabPanel value={authTypeTabIndex} index={0}>
<Grid item>
Expand Down
Loading