Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into yiyi/fix_rest_server_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyione committed Jul 15, 2020
2 parents 6c018a9 + a594ea4 commit 928ba6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/api/v2/clients/authnClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { IAuthnInfo, ILoginInfo, IPAICluster, IPAIResponse } from '@api/v2';
import { ILoginInfo, IPAICluster, IPAIResponse } from '@api/v2';
import { Util } from '@pai/commom/util';

import { OpenPAIBaseClient } from './baseClient';
Expand Down Expand Up @@ -32,9 +32,10 @@ export class AuthnClient extends OpenPAIBaseClient {
* Get an access token using username and password.
* @param username Username, set undefined to use the username in cluster setting.
* @param password Password, set undefined to use the password in cluster setting.
* @param expiration Expiration time in seconds, default 4000s.
*/
public async basicLogin(username?: string, password?: string): Promise<ILoginInfo> {
return await this.httpClient.login(username, password);
public async basicLogin(username?: string, password?: string, expiration?: number): Promise<ILoginInfo> {
return await this.httpClient.login(username, password, expiration);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/commom/paiHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ import { processResponse, IPAIResponseProcessor } from './paiResponseProcessor';
*/
export class PAIHttpClient {
protected static readonly TIMEOUT: number = 10 * 1000;
protected static readonly EXPIRATION: number = 4000;
private readonly cluster: IPAICluster;

constructor(cluster: IPAICluster) {
this.cluster = cluster;
}

public async login(username?: string, password?: string): Promise<ILoginInfo> {
/**
* Login by username and password.
* @param username Username, set undefined to use the username in cluster setting.
* @param password Password, set undefined to use the password in cluster setting.
* @param expiration Expiration time in seconds, default 4000s.
*/
public async login(username?: string, password?: string, expiration?: number): Promise<ILoginInfo> {
const url: string = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/authn/basic/login`,
this.cluster.https
Expand All @@ -30,7 +37,7 @@ export class PAIHttpClient {
const res: AxiosResponse<ILoginInfo> = await axios.post(
url,
querystring.stringify({
expiration: 4000,
expiration: expiration || PAIHttpClient.EXPIRATION,
password: password ? password : this.cluster.password,
username: username ? username : this.cluster.username
}),
Expand Down

0 comments on commit 928ba6e

Please sign in to comment.