-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add API Keys app to Management > Security. #45740
Changes from all commits
96f97b6
236d81c
8afd388
0704baa
5988691
07d2786
e4b3d84
43698ce
f0298cd
be05d8d
14a5839
8d725a4
3296f33
e58ab8e
56167df
27be6e6
86ff3aa
5da0a8f
4ad8055
8e6b934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { SectionLoading } from './section_loading'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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, | ||
EuiLoadingSpinner, | ||
EuiText, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiTextColor, | ||
} from '@elastic/eui'; | ||
|
||
interface Props { | ||
inline?: boolean; | ||
children: React.ReactNode; | ||
[key: string]: any; | ||
} | ||
|
||
export const SectionLoading: React.FunctionComponent<Props> = ({ inline, children, ...rest }) => { | ||
if (inline) { | ||
return ( | ||
<EuiFlexGroup justifyContent="flexStart" alignItems="center" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiLoadingSpinner size="m" /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText {...rest}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: do we really want to allow consumers to set any props for the
FWIW, this is my first time using type inference in conditional types, so I very well might be doing this wrong. Type-checking passes, so 🤷♂ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not experienced enough with TS to assess this suggestion so I'm going to defer it to later. |
||
<EuiTextColor color="subdued">{children}</EuiTextColor> | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} | ||
|
||
return ( | ||
<EuiEmptyPrompt | ||
title={<EuiLoadingSpinner size="xl" />} | ||
body={<EuiText color="subdued">{children}</EuiText>} | ||
data-test-subj="sectionLoading" | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export interface ApiKey { | ||
id: string; | ||
name: string; | ||
username: string; | ||
realm: string; | ||
creation: number; | ||
expiration: number; | ||
invalidated: boolean; | ||
} | ||
|
||
export interface ApiKeyToInvalidate { | ||
id: string; | ||
name: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { kfetch } from 'ui/kfetch'; | ||
import { ApiKey, ApiKeyToInvalidate } from '../../common/model/api_key'; | ||
import { INTERNAL_API_BASE_PATH } from '../../common/constants'; | ||
|
||
interface CheckPrivilegesResponse { | ||
areApiKeysEnabled: boolean; | ||
isAdmin: boolean; | ||
} | ||
|
||
interface InvalidateApiKeysResponse { | ||
itemsInvalidated: ApiKeyToInvalidate[]; | ||
errors: any[]; | ||
} | ||
|
||
interface GetApiKeysResponse { | ||
apiKeys: ApiKey[]; | ||
} | ||
|
||
const apiKeysUrl = `${INTERNAL_API_BASE_PATH}/api_key`; | ||
|
||
export class ApiKeysApi { | ||
public static async checkPrivileges(): Promise<CheckPrivilegesResponse> { | ||
return kfetch({ pathname: `${apiKeysUrl}/privileges` }); | ||
} | ||
|
||
public static async getApiKeys(isAdmin: boolean = false): Promise<GetApiKeysResponse> { | ||
const query = { | ||
isAdmin, | ||
}; | ||
|
||
return kfetch({ pathname: apiKeysUrl, query }); | ||
} | ||
|
||
public static async invalidateApiKeys( | ||
apiKeys: ApiKeyToInvalidate[], | ||
isAdmin: boolean = false | ||
): Promise<InvalidateApiKeysResponse> { | ||
const pathname = `${apiKeysUrl}/invalidate`; | ||
const body = JSON.stringify({ apiKeys, isAdmin }); | ||
return kfetch({ pathname, method: 'POST', body }); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<kbn-management-app section="security/api_keys"> | ||
<div id="apiKeysGridReactRoot" /> | ||
</kbn-management-app> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import routes from 'ui/routes'; | ||
import template from './api_keys.html'; | ||
import { API_KEYS_PATH } from '../management_urls'; | ||
import { getApiKeysBreadcrumbs } from '../breadcrumbs'; | ||
import { I18nContext } from 'ui/i18n'; | ||
import { ApiKeysGridPage } from './components'; | ||
|
||
routes.when(API_KEYS_PATH, { | ||
template, | ||
k7Breadcrumbs: getApiKeysBreadcrumbs, | ||
controller($scope) { | ||
$scope.$$postDigest(() => { | ||
const domNode = document.getElementById('apiKeysGridReactRoot'); | ||
|
||
render( | ||
<I18nContext> | ||
<ApiKeysGridPage /> | ||
</I18nContext>, domNode); | ||
|
||
// unmount react on controller destroy | ||
$scope.$on('$destroy', () => { | ||
unmountComponentAtNode(domNode); | ||
}); | ||
}); | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding this to
es_ui_shared
👍