@vegan-friendly/strapi-plugin-elasticsearch 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vegan-friendly/strapi-plugin-elasticsearch",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "A Strapi plugin to enable using Elasticsearch with Strapi CMS.",
5
5
  "homepage": "https://github.com/vegan-friendly/strapi-plugin-elasticsearch",
6
6
  "strapi": {
@@ -16,10 +16,10 @@ exports.default = async ({ strapi }) => {
16
16
  console.warn('The plugin strapi-plugin-elasticsearch is enabled but the searchConnector is not configured.');
17
17
  else {
18
18
  const connector = pluginConfig['searchConnector'];
19
+ const auth = getAuth(connector);
19
20
  await esInterface.initializeSearchEngine({
20
21
  host: connector.host,
21
- uname: connector.username,
22
- password: connector.password,
22
+ auth,
23
23
  cert: connector.certificate,
24
24
  });
25
25
  strapi.cron.add({
@@ -152,3 +152,27 @@ exports.default = async ({ strapi }) => {
152
152
  console.error(err);
153
153
  }
154
154
  };
155
+ function getAuth(connector) {
156
+ const { apiKey, username, password, bearer } = connector;
157
+ let auth;
158
+ let configTypes = [];
159
+ if (username && password) {
160
+ auth = { username, password };
161
+ configTypes.push('username/password');
162
+ }
163
+ if (bearer) {
164
+ auth = { bearer };
165
+ configTypes.push('bearer');
166
+ }
167
+ if (apiKey) {
168
+ auth = { apiKey };
169
+ configTypes.push('apiKey');
170
+ }
171
+ if (configTypes.length > 1) {
172
+ throw new Error('You cannot provide more than one authentication method. Please choose one of the following: ' + configTypes.join(', '));
173
+ }
174
+ if (!auth) {
175
+ throw new Error('No authentication method provided. Please provide one of the following: apiKey, bearer, username+password');
176
+ }
177
+ return auth;
178
+ }
@@ -3,14 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const elasticsearch_1 = require("@elastic/elasticsearch");
4
4
  let client = null;
5
5
  exports.default = ({ strapi }) => ({
6
- async initializeSearchEngine({ host, uname, password, cert }) {
6
+ async initializeSearchEngine({ host, auth, cert }) {
7
7
  try {
8
8
  client = new elasticsearch_1.Client({
9
9
  node: host,
10
- auth: {
11
- username: uname,
12
- password: password,
13
- },
10
+ auth: auth,
14
11
  tls: {
15
12
  ca: cert,
16
13
  rejectUnauthorized: false,
@@ -1,4 +1,6 @@
1
1
  import { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types';
2
+ import { ApiKeyAuth, BasicAuth, BearerAuth } from '@elastic/transport/lib/types';
3
+ export type EsAuth = BasicAuth | ApiKeyAuth | BearerAuth;
2
4
  export interface EsInterfaceService {
3
5
  /**
4
6
  * Initializes the search engine connection.
@@ -7,8 +9,7 @@ export interface EsInterfaceService {
7
9
  */
8
10
  initializeSearchEngine(params: {
9
11
  host: string;
10
- uname: string;
11
- password: string;
12
+ auth?: EsAuth;
12
13
  cert: string;
13
14
  }): Promise<void>;
14
15
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vegan-friendly/strapi-plugin-elasticsearch",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "A Strapi plugin to enable using Elasticsearch with Strapi CMS.",
5
5
  "homepage": "https://github.com/vegan-friendly/strapi-plugin-elasticsearch",
6
6
  "strapi": {