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

[Enterprise Search] Update config data endpoint to v2 #76970

Merged
merged 4 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
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',
roleType: 'owner',
cee-chen marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brian moved this to a top-level setting, not just nested under a Workplace Search specific key - I agree with him in this case since it affects both AS & WS.

So just an FYI @scottybollinger that the location of isFederatedAuth has moved, if that's okay

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,
},
},
Comment on lines +72 to +79
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self:

There's a couple other configured limits for App Search that Bmac added to this endpoint:

Screen Shot 2020-09-08 at 11 49 39 AM

I left them out for now because the App Search UI doesn't indicate using/displaying those values (at least in AppLogic), but they're there if we ever need to ✨

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,
},
},
Comment on lines +80 to +88
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottybollinger Not sure if Workplace Search actually uses this configured limit data anywhere in the UI but I figured I might as well add it!

},
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?.roleType,
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: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottybollinger - FYI, Brian renamed fpAccount to just account and I followed suit, mostly because I think the distinction is no longer really necessary in the new Kibana world (theoretically since it's client-facing only, it shouldn't need to hold references to our old code names).

That being said, this change only affects the initial data/config endpoint & doesn't preclude you from using fpAccount in the rest of Workplace Search if your team strongly prefers to do so - just a thought that you could probably clean that var name up moving forward if you wanted to.

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scottybollinger FYI - canCreateInvitations moved from being a top-level WS key to nested under 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