Skip to content

Commit

Permalink
[Enterprise Search] Update config data endpoint to v2 (#76970)
Browse files Browse the repository at this point in the history
* Update our internal config/app data to v2 specs

- Update endpoint to v2
- Update data accordingly to new API structures
- Update types accordingly

* Fix failing type check for other endpoints that use IAccount

* Update role type casing

- ent search was fixed from camel to snake
  • Loading branch information
Constance authored Sep 9, 2020
1 parent 619108c commit a0defb8
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
export const DEFAULT_INITIAL_APP_DATA = {
readOnlyMode: false,
ilmEnabled: true,
isFederatedAuth: false,
configuredLimits: {
maxDocumentByteSize: 102400,
maxEnginesPerMetaEngine: 15,
appSearch: {
engine: {
maxDocumentByteSize: 102400,
maxEnginesPerMetaEngine: 15,
},
},
workplaceSearch: {
customApiSource: {
maxDocumentByteSize: 102400,
totalFields: 64,
},
},
},
appSearch: {
accountId: 'some-id-string',
Expand All @@ -29,17 +40,16 @@ export const DEFAULT_INITIAL_APP_DATA = {
},
},
workplaceSearch: {
canCreateInvitations: true,
isFederatedAuth: false,
organization: {
name: 'ACME Donuts',
defaultOrgName: 'My Organization',
},
fpAccount: {
account: {
id: 'some-id-string',
groups: ['Default', 'Cats'],
isAdmin: true,
canCreatePersonalSources: true,
canCreateInvitations: true,
isCurated: false,
viewedOnboardingPage: true,
},
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/enterprise_search/common/types/app_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ export interface IRole {
availableRoleTypes: string[];
};
}

export interface IConfiguredLimits {
engine: {
maxDocumentByteSize: number;
maxEnginesPerMetaEngine: number;
};
}
15 changes: 11 additions & 4 deletions x-pack/plugins/enterprise_search/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IAccount as IAppSearchAccount } from './app_search';
import { IWorkplaceSearchInitialData } from './workplace_search';
import {
IAccount as IAppSearchAccount,
IConfiguredLimits as IAppSearchConfiguredLimits,
} from './app_search';
import {
IWorkplaceSearchInitialData,
IConfiguredLimits as IWorkplaceSearchConfiguredLimits,
} from './workplace_search';

export interface IInitialAppData {
readOnlyMode?: boolean;
ilmEnabled?: boolean;
isFederatedAuth?: boolean;
configuredLimits?: IConfiguredLimits;
appSearch?: IAppSearchAccount;
workplaceSearch?: IWorkplaceSearchInitialData;
}

export interface IConfiguredLimits {
maxDocumentByteSize: number;
maxEnginesPerMetaEngine: number;
appSearch: IAppSearchConfiguredLimits;
workplaceSearch: IWorkplaceSearchConfiguredLimits;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IAccount {
isAdmin: boolean;
isCurated: boolean;
canCreatePersonalSources: boolean;
canCreateInvitations?: boolean;
viewedOnboardingPage: boolean;
}

Expand All @@ -19,8 +20,13 @@ export interface IOrganization {
}

export interface IWorkplaceSearchInitialData {
canCreateInvitations: boolean;
isFederatedAuth: boolean;
organization: IOrganization;
fpAccount: IAccount;
account: IAccount;
}

export interface IConfiguredLimits {
customApiSource: {
maxDocumentByteSize: number;
totalFields: number;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,51 +38,63 @@ describe('callEnterpriseSearchConfigAPI', () => {
external_url: 'http://some.vanity.url/',
read_only_mode: false,
ilm_enabled: true,
is_federated_auth: false,
configured_limits: {
max_document_byte_size: 102400,
max_engines_per_meta_engine: 15,
app_search: {
engine: {
document_size_in_bytes: 102400,
source_engines_per_meta_engine: 15,
},
},
workplace_search: {
custom_api_source: {
document_size_in_bytes: 102400,
total_fields: 64,
},
},
},
},
current_user: {
name: 'someuser',
access: {
app_search: true,
workplace_search: false,
},
app_search: {
account_id: 'some-id-string',
onboarding_complete: true,
account: {
id: 'some-id-string',
onboarding_complete: true,
},
role: {
id: 'account_id:somestring|user_oid:somestring',
role_type: 'owner',
ability: {
access_all_engines: true,
destroy: ['session'],
manage: ['account_credentials', 'account_engines'], // etc
edit: ['LocoMoco::Account'], // etc
view: ['Engine'], // etc
credential_types: ['admin', 'private', 'search'],
available_role_types: ['owner', 'admin'],
},
},
},
workplace_search: {
can_create_invitations: true,
is_federated_auth: false,
organization: {
name: 'ACME Donuts',
default_org_name: 'My Organization',
},
fp_account: {
account: {
id: 'some-id-string',
groups: ['Default', 'Cats'],
is_admin: true,
can_create_personal_sources: true,
can_create_invitations: true,
is_curated: false,
viewed_onboarding_page: true,
},
},
},
current_user: {
name: 'someuser',
access: {
app_search: true,
workplace_search: false,
},
app_search_role: {
id: 'account_id:somestring|user_oid:somestring',
role_type: 'owner',
ability: {
access_all_engines: true,
destroy: ['session'],
manage: ['account_credentials', 'account_engines'], // etc
edit: ['LocoMoco::Account'], // etc
view: ['Engine'], // etc
credential_types: ['admin', 'private', 'search'],
available_role_types: ['owner', 'admin'],
},
},
},
};

beforeEach(() => {
Expand All @@ -91,7 +103,7 @@ describe('callEnterpriseSearchConfigAPI', () => {

it('calls the config API endpoint', async () => {
fetchMock.mockImplementationOnce((url: string) => {
expect(url).toEqual('http://localhost:3002/api/ent/v1/internal/client_config');
expect(url).toEqual('http://localhost:3002/api/ent/v2/internal/client_config');
return Promise.resolve(new Response(JSON.stringify(mockResponse)));
});

Expand All @@ -116,9 +128,20 @@ describe('callEnterpriseSearchConfigAPI', () => {
publicUrl: undefined,
readOnlyMode: false,
ilmEnabled: false,
isFederatedAuth: false,
configuredLimits: {
maxDocumentByteSize: undefined,
maxEnginesPerMetaEngine: undefined,
appSearch: {
engine: {
maxDocumentByteSize: undefined,
maxEnginesPerMetaEngine: undefined,
},
},
workplaceSearch: {
customApiSource: {
maxDocumentByteSize: undefined,
totalFields: undefined,
},
},
},
appSearch: {
accountId: undefined,
Expand All @@ -138,17 +161,16 @@ describe('callEnterpriseSearchConfigAPI', () => {
},
},
workplaceSearch: {
canCreateInvitations: false,
isFederatedAuth: false,
organization: {
name: undefined,
defaultOrgName: undefined,
},
fpAccount: {
account: {
id: undefined,
groups: [],
isAdmin: false,
canCreatePersonalSources: false,
canCreateInvitations: false,
isCurated: false,
viewedOnboardingPage: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface IReturn extends IInitialAppData {
* useful various settings (e.g. product access, external URL)
* needed by the Kibana plugin at the setup stage
*/
const ENDPOINT = '/api/ent/v1/internal/client_config';
const ENDPOINT = '/api/ent/v2/internal/client_config';

export const callEnterpriseSearchConfigAPI = async ({
config,
Expand Down Expand Up @@ -67,44 +67,60 @@ export const callEnterpriseSearchConfigAPI = async ({
publicUrl: stripTrailingSlash(data?.settings?.external_url),
readOnlyMode: !!data?.settings?.read_only_mode,
ilmEnabled: !!data?.settings?.ilm_enabled,
isFederatedAuth: !!data?.settings?.is_federated_auth, // i.e., not standard auth
configuredLimits: {
maxDocumentByteSize: data?.settings?.configured_limits?.max_document_byte_size,
maxEnginesPerMetaEngine: data?.settings?.configured_limits?.max_engines_per_meta_engine,
appSearch: {
engine: {
maxDocumentByteSize:
data?.settings?.configured_limits?.app_search?.engine?.document_size_in_bytes,
maxEnginesPerMetaEngine:
data?.settings?.configured_limits?.app_search?.engine?.source_engines_per_meta_engine,
},
},
workplaceSearch: {
customApiSource: {
maxDocumentByteSize:
data?.settings?.configured_limits?.workplace_search?.custom_api_source
?.document_size_in_bytes,
totalFields:
data?.settings?.configured_limits?.workplace_search?.custom_api_source?.total_fields,
},
},
},
appSearch: {
accountId: data?.settings?.app_search?.account_id,
onBoardingComplete: !!data?.settings?.app_search?.onboarding_complete,
accountId: data?.current_user?.app_search?.account?.id,
onBoardingComplete: !!data?.current_user?.app_search?.account?.onboarding_complete,
role: {
id: data?.current_user?.app_search_role?.id,
roleType: data?.current_user?.app_search_role?.role_type,
id: data?.current_user?.app_search?.role?.id,
roleType: data?.current_user?.app_search?.role?.role_type,
ability: {
accessAllEngines: !!data?.current_user?.app_search_role?.ability?.access_all_engines,
destroy: data?.current_user?.app_search_role?.ability?.destroy || [],
manage: data?.current_user?.app_search_role?.ability?.manage || [],
edit: data?.current_user?.app_search_role?.ability?.edit || [],
view: data?.current_user?.app_search_role?.ability?.view || [],
credentialTypes: data?.current_user?.app_search_role?.ability?.credential_types || [],
accessAllEngines: !!data?.current_user?.app_search?.role?.ability?.access_all_engines,
destroy: data?.current_user?.app_search?.role?.ability?.destroy || [],
manage: data?.current_user?.app_search?.role?.ability?.manage || [],
edit: data?.current_user?.app_search?.role?.ability?.edit || [],
view: data?.current_user?.app_search?.role?.ability?.view || [],
credentialTypes: data?.current_user?.app_search?.role?.ability?.credential_types || [],
availableRoleTypes:
data?.current_user?.app_search_role?.ability?.available_role_types || [],
data?.current_user?.app_search?.role?.ability?.available_role_types || [],
},
},
},
workplaceSearch: {
canCreateInvitations: !!data?.settings?.workplace_search?.can_create_invitations,
isFederatedAuth: !!data?.settings?.workplace_search?.is_federated_auth,
organization: {
name: data?.settings?.workplace_search?.organization?.name,
defaultOrgName: data?.settings?.workplace_search?.organization?.default_org_name,
name: data?.current_user?.workplace_search?.organization?.name,
defaultOrgName: data?.current_user?.workplace_search?.organization?.default_org_name,
},
fpAccount: {
id: data?.settings?.workplace_search?.fp_account.id,
groups: data?.settings?.workplace_search?.fp_account.groups || [],
isAdmin: !!data?.settings?.workplace_search?.fp_account?.is_admin,
canCreatePersonalSources: !!data?.settings?.workplace_search?.fp_account
account: {
id: data?.current_user?.workplace_search?.account?.id,
groups: data?.current_user?.workplace_search?.account?.groups || [],
isAdmin: !!data?.current_user?.workplace_search?.account?.is_admin,
canCreatePersonalSources: !!data?.current_user?.workplace_search?.account
?.can_create_personal_sources,
isCurated: !!data?.settings?.workplace_search?.fp_account.is_curated,
viewedOnboardingPage: !!data?.settings?.workplace_search?.fp_account
.viewed_onboarding_page,
canCreateInvitations: !!data?.current_user?.workplace_search?.account
?.can_create_invitations,
isCurated: !!data?.current_user?.workplace_search?.account?.is_curated,
viewedOnboardingPage: !!data?.current_user?.workplace_search?.account
?.viewed_onboarding_page,
},
},
};
Expand Down

0 comments on commit a0defb8

Please sign in to comment.