forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds method to register credential provider during data source plugin…
… setup Signed-off-by: Bandini Bhopi <[email protected]>
- Loading branch information
1 parent
ba298c7
commit 3ae69b9
Showing
5 changed files
with
107 additions
and
11 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/plugins/data_source/server/auth_registry/authentication_methods_registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { AuthMethodValues } from '../../server/types'; | ||
|
||
export type IAuthenticationMethodRegistery = Omit< | ||
AuthenticationMethodRegistery, | ||
'registerAuthenticationMethod' | ||
>; | ||
|
||
export class AuthenticationMethodRegistery { | ||
private readonly authMethods = new Map<string, AuthMethodValues>(); | ||
/** | ||
* Register a authMethods with function to return credentials inside the registry. | ||
* Authentication Method can only be registered once. subsequent calls with the same method name will throw an error. | ||
*/ | ||
public registerAuthenticationMethod(name: string, authMethodValues: AuthMethodValues) { | ||
if (this.authMethods.has(name)) { | ||
throw new Error(`Authentication method '${name}' is already registered`); | ||
} | ||
this.authMethods.set(name, authMethodValues); | ||
} | ||
|
||
public getAllAuthenticationMethods() { | ||
return [...this.authMethods.values()]; | ||
} | ||
|
||
public getAuthenticationMethod(name: string) { | ||
return this.authMethods.get(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { | ||
IAuthenticationMethodRegistery, | ||
AuthenticationMethodRegistery, | ||
} from './authentication_methods_registry'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters