|
| 1 | +# ApplicationConfig Plugin |
| 2 | + |
| 3 | +An OpenSearch Dashboards plugin for application configuration and a default implementation based on OpenSearch as storage. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +This plugin introduces the support of dynamic application configurations as opposed to the existing static configuration in OSD YAML file `opensearch_dashboards.yml`. It stores the configuration in an index whose default name is `.opensearch_dashboards_config` and could be customized through the key `opensearchDashboards.configIndex` in OSD YAML file. Initially the new index does not exist. Only OSD users who need dynamic configurations will create it. |
| 10 | + |
| 11 | +It also provides an interface `ConfigurationClient` for future extensions of external configuration clients. A default implementation based on OpenSearch as database is used. |
| 12 | + |
| 13 | +This plugin is disabled by default. |
| 14 | + |
| 15 | +## Configuration |
| 16 | + |
| 17 | +OSD users who want to set up application configurations will first need to enable this plugin by the following line in OSD YML. |
| 18 | + |
| 19 | +``` |
| 20 | +application_config.enabled: true |
| 21 | +
|
| 22 | +``` |
| 23 | + |
| 24 | +Then they can perform configuration operations through CURL the OSD APIs. |
| 25 | + |
| 26 | +(Note that the commands following could be first obtained from a copy as curl option from the network tab of a browser development tool and then replaced with the API names) |
| 27 | + |
| 28 | +Below is the CURL command to view all configurations. |
| 29 | + |
| 30 | +``` |
| 31 | +curl '{osd endpoint}/api/appconfig' -X GET |
| 32 | +``` |
| 33 | + |
| 34 | +Below is the CURL command to view the configuration of an entity. |
| 35 | + |
| 36 | +``` |
| 37 | +curl '{osd endpoint}/api/appconfig/{entity}' -X GET |
| 38 | +
|
| 39 | +``` |
| 40 | + |
| 41 | +Below is the CURL command to update the configuration of an entity. |
| 42 | + |
| 43 | +``` |
| 44 | +curl '{osd endpoint}/api/appconfig/{entity}' -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty' --data-raw '{"newValue":"{new value}"}' |
| 45 | +``` |
| 46 | + |
| 47 | +Below is the CURL command to delete the configuration of an entity. |
| 48 | + |
| 49 | +``` |
| 50 | +curl '{osd endpoint}/api/appconfig/{entity}' -X DELETE -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty' |
| 51 | +
|
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +## External Configuration Clients |
| 56 | + |
| 57 | +While a default OpenSearch based client is implemented, OSD users can use external configuration clients through an OSD plugin (outside OSD). |
| 58 | + |
| 59 | +Let's call this plugin `MyConfigurationClientPlugin`. |
| 60 | + |
| 61 | +First, this plugin will need to implement a class `MyConfigurationClient` based on interface `ConfigurationClient` defined in the `types.ts` under directory `src/plugins/application_config/server/types.ts`. Below are the functions inside the interface. |
| 62 | + |
| 63 | +``` |
| 64 | + getConfig(): Promise<Map<string, string>>; |
| 65 | +
|
| 66 | + getEntityConfig(entity: string): Promise<string>; |
| 67 | +
|
| 68 | + updateEntityConfig(entity: string, newValue: string): Promise<string>; |
| 69 | +
|
| 70 | + deleteEntityConfig(entity: string): Promise<string>; |
| 71 | +``` |
| 72 | + |
| 73 | +Second, this plugin needs to declare `applicationConfig` as its dependency by adding it to `requiredPlugins` in its own `opensearch_dashboards.json`. |
| 74 | + |
| 75 | +Third, the plugin will define a new type called `AppPluginSetupDependencies` as follows in its own `types.ts`. |
| 76 | + |
| 77 | +``` |
| 78 | +export interface AppPluginSetupDependencies { |
| 79 | + applicationConfig: ApplicationConfigPluginSetup; |
| 80 | +} |
| 81 | +
|
| 82 | +``` |
| 83 | + |
| 84 | +Then the plugin will import the new type `AppPluginSetupDependencies` and add to its own setup input. Below is the skeleton of the class `MyConfigurationClientPlugin`. |
| 85 | + |
| 86 | +``` |
| 87 | +// MyConfigurationClientPlugin |
| 88 | + public setup(core: CoreSetup, { applicationConfig }: AppPluginSetupDependencies) { |
| 89 | +
|
| 90 | + ... |
| 91 | + // The function createClient provides an instance of ConfigurationClient which |
| 92 | + // could have a underlying DynamoDB or Postgres implementation. |
| 93 | + const myConfigurationClient: ConfigurationClient = this.createClient(); |
| 94 | +
|
| 95 | + applicationConfig.registerConfigurationClient(myConfigurationClient); |
| 96 | + ... |
| 97 | + return {}; |
| 98 | + } |
| 99 | +
|
| 100 | +``` |
| 101 | + |
| 102 | +## Onboarding Configurations |
| 103 | + |
| 104 | +Since the APIs and interfaces can take an entity, a new use case to this plugin could just pass their entity into the parameters. There is no need to implement new APIs or interfaces. To programmatically call the functions in `ConfigurationClient` from a plugin (the caller plugin), below is the code example. |
| 105 | + |
| 106 | +Similar to [section](#external-configuration-clients), a new type `AppPluginSetupDependencies` which encapsulates `ApplicationConfigPluginSetup` is needed. Then it can be imported into the `setup` function of the caller plugin. Then the caller plugin will have access to the `getConfigurationClient` and `registerConfigurationClient` exposed by `ApplicationConfigPluginSetup`. |
| 107 | + |
| 108 | +## Development |
| 109 | + |
| 110 | +See the [OpenSearch Dashboards contributing |
| 111 | +guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/CONTRIBUTING.md) for instructions |
| 112 | +setting up your development environment. |
0 commit comments