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

feat: add authenticationType method to authenticators #169

Merged
merged 2 commits into from
Oct 15, 2021
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
62 changes: 36 additions & 26 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "package-lock.json|^.secrets.baseline$",
"lines": null
},
"generated_at": "2021-08-17T20:14:30Z",
"generated_at": "2021-10-15T14:47:01Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -119,20 +119,30 @@
"verified_result": null
}
],
"auth/authenticators/authenticator.ts": [
{
"hashed_secret": "fdee05598fdd57ff8e9ae29e92c25a04f2c52fa6",
"is_secret": false,
"is_verified": false,
"line_number": 39,
"type": "Secret Keyword",
"verified_result": null
}
],
"auth/authenticators/cloud-pak-for-data-authenticator.ts": [
{
"hashed_secret": "d5ff02fa48e492fac0a245ad63d1ae608e705c05",
"is_secret": false,
"is_verified": false,
"line_number": 70,
"line_number": 71,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "8f4bfc22c4fd7cb884f94ec175ff4a3284a174a1",
"is_secret": false,
"is_verified": false,
"line_number": 71,
"line_number": 72,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -142,7 +152,7 @@
"hashed_secret": "8f4bfc22c4fd7cb884f94ec175ff4a3284a174a1",
"is_secret": false,
"is_verified": false,
"line_number": 69,
"line_number": 70,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -312,23 +322,23 @@
"hashed_secret": "2863fa4b5510c46afc2bd2998dfbc0cf3d6df032",
"is_secret": false,
"is_verified": false,
"line_number": 27,
"line_number": 32,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "407bb564bd0e4d31368cb53004c9c42adf8f7be8",
"is_secret": false,
"is_verified": false,
"line_number": 29,
"line_number": 34,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "e38ad214943daad1d64c102faec29de4afe9da3d",
"is_secret": false,
"is_verified": false,
"line_number": 36,
"line_number": 41,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down Expand Up @@ -364,7 +374,7 @@
"hashed_secret": "09f798553f7c035c2915bf8c59b46b6c285d2d84",
"is_secret": false,
"is_verified": false,
"line_number": 4,
"line_number": 20,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -374,7 +384,7 @@
"hashed_secret": "5c5a15a8b0b3e154d77746945e563ba40100681b",
"is_secret": false,
"is_verified": false,
"line_number": 19,
"line_number": 35,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -384,15 +394,15 @@
"hashed_secret": "85dd3fb12cb0dcae03f1bba6fb61f4edd90d986d",
"is_secret": false,
"is_verified": false,
"line_number": 5,
"line_number": 21,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "0c910ad3070d996b37a1c65f542b17adc3f962bc",
"is_secret": false,
"is_verified": false,
"line_number": 6,
"line_number": 22,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -402,15 +412,15 @@
"hashed_secret": "1572bd30ac06678a82df42b5913e5e52e27f9a12",
"is_secret": false,
"is_verified": false,
"line_number": 15,
"line_number": 31,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "16856d955c788df03735a24feb2e3ffefd91f3dc",
"is_secret": false,
"is_verified": false,
"line_number": 16,
"line_number": 32,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -420,39 +430,39 @@
"hashed_secret": "257368587362aab7f1180b4a5fe550ec26053e05",
"is_secret": false,
"is_verified": false,
"line_number": 14,
"line_number": 30,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "5c5a15a8b0b3e154d77746945e563ba40100681b",
"is_secret": false,
"is_verified": false,
"line_number": 17,
"line_number": 33,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "a3bf8418470bbb21ecdb24c28e38b446a3ab9b75",
"is_secret": false,
"is_verified": false,
"line_number": 48,
"line_number": 65,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "2c208e466e476d4d8cbe055832f40f04e4d5dd23",
"is_secret": false,
"is_verified": false,
"line_number": 53,
"line_number": 70,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "945db841c03e42eef2f3d0a4ff310e2f3b3e59ec",
"is_secret": false,
"is_verified": false,
"line_number": 77,
"line_number": 94,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -462,7 +472,7 @@
"hashed_secret": "43ed4c2d8375dfc89e3dc8c917f404b9481d355b",
"is_secret": false,
"is_verified": false,
"line_number": 5,
"line_number": 21,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -472,7 +482,7 @@
"hashed_secret": "43ed4c2d8375dfc89e3dc8c917f404b9481d355b",
"is_secret": false,
"is_verified": false,
"line_number": 13,
"line_number": 29,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -482,7 +492,7 @@
"hashed_secret": "a7ef1be18bb8d37af79f3d87761a203378bf26a2",
"is_secret": false,
"is_verified": false,
"line_number": 129,
"line_number": 145,
"type": "Secret Keyword",
"verified_result": null
}
Expand All @@ -492,37 +502,37 @@
"hashed_secret": "4c65cd3f160d60f7ca28ca04fa60b9035132781c",
"is_secret": false,
"is_verified": false,
"line_number": 7,
"line_number": 23,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "407bb564bd0e4d31368cb53004c9c42adf8f7be8",
"is_secret": false,
"is_verified": false,
"line_number": 174,
"line_number": 204,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "2863fa4b5510c46afc2bd2998dfbc0cf3d6df032",
"is_secret": false,
"is_verified": false,
"line_number": 200,
"line_number": 230,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "ed8c99e906cf3fdbae90a71e06142ebc72b4c056",
"is_secret": false,
"is_verified": false,
"line_number": 218,
"line_number": 248,
"type": "Secret Keyword",
"verified_result": null
}
]
},
"version": "0.13.1+ibm.40.dss",
"version": "0.13.1+ibm.46.dss",
"word_list": {
"file": null,
"hash": null
Expand Down
5 changes: 5 additions & 0 deletions auth/authenticators/authenticator-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ export interface AuthenticatorInterface {
* authentication information will be added to.
*/
authenticate(requestOptions: AuthenticateOptions): Promise<void | Error>;

/**
* Returns a string that indicates the authentication type.
*/
authenticationType(): string;
}
32 changes: 32 additions & 0 deletions auth/authenticators/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ import { AuthenticateOptions, AuthenticatorInterface } from './authenticator-int
* to be used as a stand-alone authenticator.
*/
export class Authenticator implements AuthenticatorInterface {
/**
* Constants that define the various authenticator types.
*/
static AUTHTYPE_BASIC = 'basic';

static AUTHTYPE_BEARERTOKEN = 'bearertoken';

static AUTHTYPE_IAM = 'iam';

static AUTHTYPE_CONTAINER = 'container';

static AUTHTYPE_CP4D = 'cp4d';

static AUTHTYPE_NOAUTH = 'noauth';

static AUTHTYPE_UNKNOWN = 'unknown';

/**
* Create a new Authenticator instance.
*
Expand All @@ -48,4 +65,19 @@ export class Authenticator implements AuthenticatorInterface {
const error = new Error('Should be implemented by subclass!');
return Promise.reject(error);
}

/**
* Retrieves the authenticator's type.
* The returned value will be the same string that is used
* when configuring an instance of the authenticator with the
* "<service_name>_AUTH_TYPE" configuration property
* (e.g. "basic", "iam", etc.).
* This function should be overridden in each authenticator
* implementation class that extends this class.
*
* @returns a string that indicates the authenticator's type
*/
public authenticationType(): string {
return Authenticator.AUTHTYPE_UNKNOWN;
}
}
10 changes: 10 additions & 0 deletions auth/authenticators/basic-authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,14 @@ export class BasicAuthenticator extends Authenticator {
resolve();
});
}

/**
* Returns the authenticator's type ('basic').
*
* @returns a string that indicates the authenticator's type
*/
// eslint-disable-next-line class-methods-use-this
public authenticationType(): string {
return Authenticator.AUTHTYPE_BASIC;
}
}
10 changes: 10 additions & 0 deletions auth/authenticators/bearer-token-authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,14 @@ export class BearerTokenAuthenticator extends Authenticator {
resolve();
});
}

/**
* Returns the authenticator's type ('bearertoken').
*
* @returns a string that indicates the authenticator's type
*/
// eslint-disable-next-line class-methods-use-this
public authenticationType(): string {
return Authenticator.AUTHTYPE_BEARERTOKEN;
}
}
11 changes: 11 additions & 0 deletions auth/authenticators/cloud-pak-for-data-authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Authenticator } from './authenticator';
import { Cp4dTokenManager } from '../token-managers';
import { BaseOptions, TokenRequestBasedAuthenticator } from './token-request-based-authenticator';

Expand Down Expand Up @@ -75,4 +76,14 @@ export class CloudPakForDataAuthenticator extends TokenRequestBasedAuthenticator
// also, the token manager will handle input validation
this.tokenManager = new Cp4dTokenManager(options);
}

/**
* Returns the authenticator's type ('cp4d').
*
* @returns a string that indicates the authenticator's type
*/
// eslint-disable-next-line class-methods-use-this
public authenticationType(): string {
return Authenticator.AUTHTYPE_CP4D;
}
}
11 changes: 11 additions & 0 deletions auth/authenticators/container-authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Authenticator } from './authenticator';
import { ContainerTokenManager } from '../token-managers';
import { IamRequestOptions, IamRequestBasedAuthenticator } from './iam-request-based-authenticator';

Expand Down Expand Up @@ -113,4 +114,14 @@ export class ContainerAuthenticator extends IamRequestBasedAuthenticator {
// update properties in token manager
this.tokenManager.setIamProfileId(iamProfileId);
}

/**
* Returns the authenticator's type ('container').
*
* @returns a string that indicates the authenticator's type
*/
// eslint-disable-next-line class-methods-use-this
public authenticationType(): string {
return Authenticator.AUTHTYPE_CONTAINER;
}
}
11 changes: 11 additions & 0 deletions auth/authenticators/iam-authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { Authenticator } from './authenticator';
import { IamTokenManager } from '../token-managers';
import { validateInput } from '../utils';
import { IamRequestOptions, IamRequestBasedAuthenticator } from './iam-request-based-authenticator';
Expand Down Expand Up @@ -82,4 +83,14 @@ export class IamAuthenticator extends IamRequestBasedAuthenticator {
public getRefreshToken(): string {
return this.tokenManager.getRefreshToken();
}

/**
* Returns the authenticator's type ('iam').
*
* @returns a string that indicates the authenticator's type
*/
// eslint-disable-next-line class-methods-use-this
public authenticationType(): string {
return Authenticator.AUTHTYPE_IAM;
}
}
Loading