Skip to content

Commit

Permalink
Create common plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed May 20, 2024
1 parent 6e56a42 commit 6ac1fea
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 57 deletions.
79 changes: 79 additions & 0 deletions server/backend/opensearch_security_common_plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// eslint-disable-next-line import/no-default-export
export default function (Client: any, config: any, components: any) {
const ca = components.clientAction.factory;

if (!Client.prototype.opensearch_security) {
Client.prototype.opensearch_security = components.clientAction.namespaceFactory();
}

/**
* Updates a resource.
* Resource identification is expected to computed from headers. Eg: auth headers.
*
* Sample response:
* {
* "status": "OK",
* "message": "Username updated."
* }
*/
Client.prototype.opensearch_security.prototype.saveResourceWithoutId = ca({
method: 'PUT',
needBody: true,
url: {
fmt: '/_plugins/_security/api/<%=resourceName%>',
req: {
resourceName: {
type: 'string',
required: true,
},
},
},
});

/**
* Returns a Security resource configuration.
*
* Sample response:
*
* {
* "user": {
* "hash": "#123123"
* }
* }
*/
Client.prototype.opensearch_security.prototype.listResource = ca({
url: {
fmt: '/_plugins/_security/api/<%=resourceName%>',
req: {
resourceName: {
type: 'string',
required: true,
},
},
},
});

/**
* Gets auth info.
*/
Client.prototype.opensearch_security.prototype.authinfo = ca({
url: {
fmt: '/_plugins/_security/authinfo',
},
});
}
56 changes: 0 additions & 56 deletions server/backend/opensearch_security_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,6 @@ export default function (Client: any, config: any, components: any) {
},
});

/**
* Updates a resource.
* Resource identification is expected to computed from headers. Eg: auth headers.
*
* Sample response:
* {
* "status": "OK",
* "message": "Username updated."
* }
*/
Client.prototype.opensearch_security.prototype.saveResourceWithoutId = ca({
method: 'PUT',
needBody: true,
url: {
fmt: '/_plugins/_security/api/<%=resourceName%>',
req: {
resourceName: {
type: 'string',
required: true,
},
},
},
});

/**
* Returns a Security resource configuration.
*
* Sample response:
*
* {
* "user": {
* "hash": "#123123"
* }
* }
*/
Client.prototype.opensearch_security.prototype.listResource = ca({
url: {
fmt: '/_plugins/_security/api/<%=resourceName%>',
req: {
resourceName: {
type: 'string',
required: true,
},
},
},
});

/**
* Gets auth info.
*/
Client.prototype.opensearch_security.prototype.authinfo = ca({
url: {
fmt: '/_plugins/_security/authinfo',
},
});

Client.prototype.opensearch_security.prototype.dashboardsinfo = ca({
url: {
fmt: '/_plugins/_security/dashboardsinfo',
Expand Down
3 changes: 2 additions & 1 deletion server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { defineRoutes, defineSecurityConfigurationRoutes } from './routes';
import { SecurityPluginConfigType } from '.';
import opensearchSecurityConfigurationPlugin from './backend/opensearch_security_configuration_plugin';
import opensearchSecurityPlugin from './backend/opensearch_security_plugin';
import opensearchSecurityCommonPlugin from './backend/opensearch_security_common_plugin';
import { SecuritySessionCookie, getSecurityCookieOptions } from './session/security_cookie';
import { SecurityClient } from './backend/opensearch_security_client';
import {
Expand Down Expand Up @@ -97,7 +98,7 @@ export class SecurityPlugin implements Plugin<SecurityPluginSetup, SecurityPlugi

const router = core.http.createRouter();

const plugins = [];
const plugins = [opensearchSecurityCommonPlugin];
if (config.configuration.session_management_enabled) {
plugins.push(opensearchSecurityPlugin);
}
Expand Down

0 comments on commit 6ac1fea

Please sign in to comment.