-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move authz lib out of snapshot restore (#63947)
Created the first entry for the new __packages_do_no_import__ folder that will house ESUIs private packages.
- Loading branch information
1 parent
2f363ba
commit 1deb5d6
Showing
39 changed files
with
335 additions
and
159 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
..._ui_shared/__packages_do_not_import__/authorization/components/authorization_provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
import { HttpSetup } from 'kibana/public'; | ||
import React, { createContext, useContext } from 'react'; | ||
|
||
import { useRequest } from '../../../public'; | ||
|
||
import { Error as CustomError } from './section_error'; | ||
|
||
import { Privileges } from '../types'; | ||
|
||
interface Authorization { | ||
isLoading: boolean; | ||
apiError: CustomError | null; | ||
privileges: Privileges; | ||
} | ||
|
||
const initialValue: Authorization = { | ||
isLoading: true, | ||
apiError: null, | ||
privileges: { | ||
hasAllPrivileges: true, | ||
missingPrivileges: {}, | ||
}, | ||
}; | ||
|
||
export const AuthorizationContext = createContext<Authorization>(initialValue); | ||
|
||
export const useAuthorizationContext = () => { | ||
const ctx = useContext(AuthorizationContext); | ||
if (!ctx) { | ||
throw new Error('AuthorizationContext can only be used inside of AuthorizationProvider!'); | ||
} | ||
return ctx; | ||
}; | ||
|
||
interface Props { | ||
privilegesEndpoint: string; | ||
children: React.ReactNode; | ||
httpClient: HttpSetup; | ||
} | ||
|
||
export const AuthorizationProvider = ({ privilegesEndpoint, httpClient, children }: Props) => { | ||
const { isLoading, error, data: privilegesData } = useRequest<any, CustomError>(httpClient, { | ||
path: privilegesEndpoint, | ||
method: 'get', | ||
}); | ||
|
||
const value = { | ||
isLoading, | ||
privileges: isLoading ? { hasAllPrivileges: true, missingPrivileges: {} } : privilegesData, | ||
apiError: error ? error : null, | ||
} as Authorization; | ||
|
||
return <AuthorizationContext.Provider value={value}>{children}</AuthorizationContext.Provider>; | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/plugins/es_ui_shared/__packages_do_not_import__/authorization/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
export { | ||
AuthorizationProvider, | ||
AuthorizationContext, | ||
useAuthorizationContext, | ||
} from './authorization_provider'; | ||
|
||
export { WithPrivileges } from './with_privileges'; | ||
|
||
export { NotAuthorizedSection } from './not_authorized_section'; | ||
|
||
export { Error, SectionError } from './section_error'; |
30 changes: 30 additions & 0 deletions
30
..._ui_shared/__packages_do_not_import__/authorization/components/not_authorized_section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiEmptyPrompt } from '@elastic/eui'; | ||
|
||
interface Props { | ||
title: React.ReactNode; | ||
message: React.ReactNode | string; | ||
} | ||
|
||
export const NotAuthorizedSection = ({ title, message }: Props) => ( | ||
<EuiEmptyPrompt iconType="securityApp" title={<h2>{title}</h2>} body={<p>{message}</p>} /> | ||
); |
19 changes: 16 additions & 3 deletions
19
.../application/components/section_error.tsx → ...uthorization/components/section_error.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/plugins/es_ui_shared/__packages_do_not_import__/authorization/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
export { | ||
WithPrivileges, | ||
NotAuthorizedSection, | ||
AuthorizationProvider, | ||
AuthorizationContext, | ||
SectionError, | ||
Error, | ||
useAuthorizationContext, | ||
} from './components'; | ||
|
||
export { Privileges, MissingPrivileges } from './types'; |
27 changes: 27 additions & 0 deletions
27
src/plugins/es_ui_shared/__packages_do_not_import__/authorization/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
export interface MissingPrivileges { | ||
[key: string]: string[] | undefined; | ||
} | ||
|
||
export interface Privileges { | ||
hasAllPrivileges: boolean; | ||
missingPrivileges: MissingPrivileges; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
export * from '../../__packages_do_not_import__/authorization'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
x-pack/plugins/snapshot_restore/common/types/privileges.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.