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 auth registry to store auth details passed by plugin and adds ap…
…i in datasource plugin start Signed-off-by: Bandini Bhopi <bandinib@amazon.com>
- Loading branch information
1 parent
3b96379
commit fd91205
Showing
5 changed files
with
90 additions
and
14 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/plugins/data_source/common/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,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// eslint-disable-next-line @osd/eslint/no-restricted-paths | ||
import { DataSourceCredentialsProvider } from '../../server/types'; | ||
|
||
export type IAuthenticationMethodRegistery = Omit< | ||
AuthenticationMethodRegistery, | ||
'registerAuthenticationMethod' | ||
>; | ||
|
||
export class AuthenticationMethodRegistery { | ||
private readonly authMethods = new Map<string, DataSourceCredentialsProvider>(); | ||
|
||
/** | ||
* 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( | ||
type: string, | ||
credentialProvider: DataSourceCredentialsProvider | ||
) { | ||
if (this.authMethods.has(type)) { | ||
throw new Error(`Authentication method '${type}' is already registered`); | ||
} | ||
this.authMethods.set(type, credentialProvider); | ||
} | ||
|
||
public getAllAuthenticationMethods() { | ||
return [...this.authMethods.values()]; | ||
} | ||
|
||
public getAuthenticationMethod(authType: string) { | ||
return this.authMethods.get(authType); | ||
} | ||
} |
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