plugin-search-backend-module-elasticsearch: Opensearch provider
This patch continues the work started by jinnjwu on https://github.com/backstage/backstage/pull/14988 It creates a new provider, opensearch, allowing the usage of it outside of managed aws solutions. Signed-off-by: Renan Mendes Carvalho <aitherios@gmail.com>
This commit is contained in:
@@ -421,7 +421,7 @@ export interface OpenSearchElasticSearchClientOptions
|
||||
// (undocumented)
|
||||
nodes?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];
|
||||
// (undocumented)
|
||||
provider?: 'aws';
|
||||
provider?: 'aws' | 'opensearch';
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
+3
-2
@@ -138,10 +138,11 @@ export interface Config {
|
||||
bearer: string;
|
||||
};*/
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS = In house hosting Open Search
|
||||
*/
|
||||
| {
|
||||
| {
|
||||
provider: 'opensearch';
|
||||
/**
|
||||
* Node configuration.
|
||||
@@ -166,7 +167,7 @@ export interface Config {
|
||||
| {
|
||||
apiKey: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import type { ConnectionOptions as TLSConnectionOptions } from 'tls';
|
||||
export const isOpenSearchCompatible = (
|
||||
opts: ElasticSearchClientOptions,
|
||||
): opts is OpenSearchElasticSearchClientOptions => {
|
||||
return opts?.provider === 'aws';
|
||||
return ['aws', 'opensearch'].includes(opts?.provider ?? '');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ export type ElasticSearchClientOptions =
|
||||
*/
|
||||
export interface OpenSearchElasticSearchClientOptions
|
||||
extends BaseElasticSearchClientOptions {
|
||||
provider?: 'aws';
|
||||
provider?: 'aws' | 'opensearch';
|
||||
auth?: OpenSearchAuth;
|
||||
connection?: OpenSearchConnectionConstructor;
|
||||
node?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];
|
||||
|
||||
+19
@@ -336,5 +336,24 @@ describe('ElasticSearchClientWrapper', () => {
|
||||
body: { actions: input.actions },
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts provider "opensearch"', async () => {
|
||||
osOptions = {
|
||||
provider: 'opensearch',
|
||||
node: 'https://my-opensearch-instance.address.com',
|
||||
// todo(backstage/techdocs-core): Remove the following ts-ignore when
|
||||
// @short.io/opensearch-mock is updated to work w/opensearch >= 2.0.0
|
||||
// @ts-ignore
|
||||
connection: mock.getConnection(),
|
||||
};
|
||||
|
||||
const wrapper = ElasticSearchClientWrapper.fromClientOptions(osOptions);
|
||||
expect(OpenSearchClient).toHaveBeenCalledWith(osOptions);
|
||||
|
||||
const searchInput = { index: 'xyz', body: { eg: 'etc' } };
|
||||
const result = (await wrapper.search(searchInput)) as any;
|
||||
expect(result.client).toBe('os');
|
||||
expect(result.args).toStrictEqual(searchInput);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -150,6 +150,8 @@ export class ElasticSearchSearchEngine implements SearchEngine {
|
||||
logger.info('Initializing Elastic.co ElasticSearch search engine.');
|
||||
} else if (options.provider === 'aws') {
|
||||
logger.info('Initializing AWS OpenSearch search engine.');
|
||||
} else if (options.provider === 'opensearch') {
|
||||
logger.info('Initializing OpenSearch search engine.');
|
||||
} else {
|
||||
logger.info('Initializing ElasticSearch search engine.');
|
||||
}
|
||||
@@ -452,6 +454,24 @@ export async function createElasticSearchClientOptions(
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
if (config.getOptionalString('provider') === 'opensearch') {
|
||||
const authConfig = config.getConfig('auth');
|
||||
return {
|
||||
provider: 'opensearch',
|
||||
auth: {
|
||||
username: authConfig.getString('username'),
|
||||
password: authConfig.getString('password'),
|
||||
},
|
||||
...(sslConfig
|
||||
? {
|
||||
ssl: {
|
||||
rejectUnauthorized:
|
||||
sslConfig?.getOptionalBoolean('rejectUnauthorized'),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
const authConfig = config.getOptionalConfig('auth');
|
||||
const auth =
|
||||
authConfig &&
|
||||
|
||||
Reference in New Issue
Block a user