Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Branch] Define variables and functions #1145

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 23 additions & 35 deletions server/saved_objects/saved_objects_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,20 @@ export class SecuritySavedObjectsClientWrapper {
(this.httpStart!.auth.get(wrapperOptions.request).state as OpenSearchDashboardsAuthState) ||
{};

const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
const globalTenant = '';
const defaultTenant = 'default';
const privateTenant = '__user__';

let namespaceValue = selectedTenant;

const createWithNamespace = async <T = unknown>(
type: string,
attributes: T,
options?: SavedObjectsCreateOptions
) => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -65,10 +70,7 @@ export class SecuritySavedObjectsClientWrapper {
objects: SavedObjectsBulkGetObject[] = [],
options: SavedObjectsBaseOptions = {}
): Promise<SavedObjectsBulkResponse<T>> => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -80,9 +82,9 @@ export class SecuritySavedObjectsClientWrapper {
): Promise<SavedObjectsFindResponse<T>> => {
const tenants = state.authInfo?.tenants;
const availableTenantNames = Object.keys(tenants!);
availableTenantNames.push('default');
availableTenantNames.push('');
availableTenantNames.push('__user__' + state.authInfo?.user_name);
availableTenantNames.push(defaultTenant);
availableTenantNames.push(globalTenant);
availableTenantNames.push(privateTenant + state.authInfo?.user_name);
_.assign(options, { namespaces: availableTenantNames });
return await wrapperOptions.client.find(options);
};
Expand All @@ -92,10 +94,7 @@ export class SecuritySavedObjectsClientWrapper {
id: string,
options: SavedObjectsBaseOptions = {}
): Promise<SavedObject<T>> => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -108,10 +107,7 @@ export class SecuritySavedObjectsClientWrapper {
attributes: Partial<T>,
options: SavedObjectsUpdateOptions = {}
): Promise<SavedObjectsUpdateResponse<T>> => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -122,10 +118,7 @@ export class SecuritySavedObjectsClientWrapper {
objects: Array<SavedObjectsBulkCreateObject<T>>,
options?: SavedObjectsCreateOptions
): Promise<SavedObjectsBulkResponse<T>> => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -136,10 +129,7 @@ export class SecuritySavedObjectsClientWrapper {
objects: Array<SavedObjectsBulkUpdateObject<T>>,
options?: SavedObjectsBulkUpdateOptions
): Promise<SavedObjectsBulkUpdateResponse<T>> => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -151,10 +141,7 @@ export class SecuritySavedObjectsClientWrapper {
id: string,
options: SavedObjectsDeleteOptions = {}
) => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -165,10 +152,7 @@ export class SecuritySavedObjectsClientWrapper {
objects: SavedObjectsCheckConflictsObject[] = [],
options: SavedObjectsBaseOptions = {}
): Promise<SavedObjectsCheckConflictsResponse> => {
const selectedTenant = state.selectedTenant;
const username = state.authInfo?.user_name;
let namespaceValue = selectedTenant;
if (selectedTenant === '__user__') {
if (selectedTenant !== undefined && isPrivateTenant(selectedTenant)) {
namespaceValue = selectedTenant + username;
}
_.assign(options, { namespace: [namespaceValue] });
Expand All @@ -192,3 +176,7 @@ export class SecuritySavedObjectsClientWrapper {
};
};
}

function isPrivateTenant(selectedTenant: string | undefined) {
return selectedTenant === '__user__';
}