diff --git a/ui/src/authorizations/actions/index.ts b/ui/src/authorizations/actions/index.ts index b840fe82dcf..ab11b51a65a 100644 --- a/ui/src/authorizations/actions/index.ts +++ b/ui/src/authorizations/actions/index.ts @@ -2,8 +2,8 @@ import {Dispatch} from 'react' // API -import {client} from 'src/utils/api' import * as authAPI from 'src/authorizations/apis' +import * as api from 'src/client' // Actions import {notify} from 'src/shared/actions/notifications' @@ -20,8 +20,12 @@ import { } from 'src/shared/copy/notifications' // Types -import {RemoteDataState, GetState, NotificationAction} from 'src/types' -import {Authorization} from '@influxdata/influx' +import { + RemoteDataState, + GetState, + NotificationAction, + Authorization, +} from 'src/types' export type Action = | SetAuthorizations @@ -97,7 +101,13 @@ export const getAuthorizations = () => async ( orgs: {org}, } = getState() - const authorizations = await client.authorizations.getAll(org.id) + const resp = await api.getAuthorizations({query: {orgID: org.id}}) + + if (resp.status !== 200) { + throw new Error(resp.data.message) + } + + const {authorizations} = resp.data dispatch(setAuthorizations(RemoteDataState.Done, authorizations)) } catch (e) { @@ -107,10 +117,15 @@ export const getAuthorizations = () => async ( } } -export const getAuthorization = async (authorizationID: string) => { +export const getAuthorization = async (authID: string) => { try { - const authorization = await client.authorizations.get(authorizationID) - return authorization + const resp = await api.getAuthorization({authID}) + + if (resp.status !== 200) { + throw new Error(resp.data.message) + } + + return resp.data } catch (e) { console.error(e) } @@ -134,7 +149,14 @@ export const updateAuthorization = (authorization: Authorization) => async ( dispatch: Dispatch ) => { try { - await client.authorizations.update(authorization.id, authorization) + const resp = await api.patchAuthorization({ + authID: authorization.id, + data: authorization, + }) + + if (resp.status !== 200) { + throw new Error(resp.data.message) + } dispatch(getAuthorizations()) dispatch(notify(authorizationUpdateSuccess())) @@ -148,7 +170,11 @@ export const deleteAuthorization = (id: string, name: string = '') => async ( dispatch: Dispatch ) => { try { - await client.authorizations.delete(id) + const resp = await api.deleteAuthorization({authID: id}) + + if (resp.status !== 204) { + throw new Error(resp.data.message) + } dispatch(removeAuthorization(id)) dispatch(notify(authorizationDeleteSuccess())) diff --git a/ui/src/authorizations/components/AllAccessTokenOverlay.tsx b/ui/src/authorizations/components/AllAccessTokenOverlay.tsx index 9cdd2bcb96b..873c0bc8d26 100644 --- a/ui/src/authorizations/components/AllAccessTokenOverlay.tsx +++ b/ui/src/authorizations/components/AllAccessTokenOverlay.tsx @@ -26,7 +26,9 @@ import {allAccessPermissions} from 'src/authorizations/utils/permissions' // Decorators import {ErrorHandling} from 'src/shared/decorators/errors' -import {Authorization} from '@influxdata/influx' + +// Types +import {Authorization} from 'src/types' interface DispatchProps { onCreateAuthorization: typeof createAuthorization diff --git a/ui/src/authorizations/components/BucketsTokenOverlay.tsx b/ui/src/authorizations/components/BucketsTokenOverlay.tsx index 471202d87ed..ce51d036860 100644 --- a/ui/src/authorizations/components/BucketsTokenOverlay.tsx +++ b/ui/src/authorizations/components/BucketsTokenOverlay.tsx @@ -36,8 +36,7 @@ import {createAuthorization} from 'src/authorizations/actions' import {ErrorHandling} from 'src/shared/decorators/errors' // Types -import {AppState, Bucket} from 'src/types' -import {Permission, Authorization} from '@influxdata/influx' +import {AppState, Bucket, Permission, Authorization} from 'src/types' interface StateProps { buckets: Bucket[] @@ -236,7 +235,7 @@ class BucketsTokenOverlay extends PureComponent { return buckets.find(b => b.name === bucketName) }) - return specificBucketsPermissions(writeBuckets, Permission.ActionEnum.Write) + return specificBucketsPermissions(writeBuckets, 'write') } private get readBucketPermissions(): Permission[] { @@ -246,7 +245,7 @@ class BucketsTokenOverlay extends PureComponent { return buckets.find(b => b.name === bucketName) }) - return specificBucketsPermissions(readBuckets, Permission.ActionEnum.Read) + return specificBucketsPermissions(readBuckets, 'read') } private get allReadBucketPermissions(): Permission[] { @@ -254,7 +253,7 @@ class BucketsTokenOverlay extends PureComponent { params: {orgID}, } = this.props - return allBucketsPermissions(orgID, Permission.ActionEnum.Read) + return allBucketsPermissions(orgID, 'read') } private get allWriteBucketPermissions(): Permission[] { @@ -262,7 +261,7 @@ class BucketsTokenOverlay extends PureComponent { params: {orgID}, } = this.props - return allBucketsPermissions(orgID, Permission.ActionEnum.Write) + return allBucketsPermissions(orgID, 'write') } private handleInputChange = (e: ChangeEvent) => { diff --git a/ui/src/authorizations/components/TokenList.tsx b/ui/src/authorizations/components/TokenList.tsx index 2c31f6abef7..744f5f1bcf4 100644 --- a/ui/src/authorizations/components/TokenList.tsx +++ b/ui/src/authorizations/components/TokenList.tsx @@ -9,7 +9,7 @@ import TokenRow from 'src/authorizations/components/TokenRow' import ViewTokenOverlay from 'src/authorizations/components/ViewTokenOverlay' // Types -import {Authorization} from '@influxdata/influx' +import {Authorization} from 'src/types' import {SortTypes} from 'src/shared/utils/sort' import {ComponentSize, Sort} from '@influxdata/clockface' diff --git a/ui/src/authorizations/components/TokenRow.tsx b/ui/src/authorizations/components/TokenRow.tsx index f9596843b32..3d48e1c6bdf 100644 --- a/ui/src/authorizations/components/TokenRow.tsx +++ b/ui/src/authorizations/components/TokenRow.tsx @@ -21,7 +21,7 @@ import { import EditableName from 'src/shared/components/EditableName' // Types -import {Authorization, AuthorizationUpdateRequest} from '@influxdata/influx' +import {Authorization} from 'src/types' import {DEFAULT_TOKEN_DESCRIPTION} from 'src/dashboards/constants' interface OwnProps { @@ -78,15 +78,15 @@ class TokenRow extends PureComponent { private get isTokenEnabled(): boolean { const {auth} = this.props - return auth.status === AuthorizationUpdateRequest.StatusEnum.Active + return auth.status === 'active' } private changeToggle = () => { const {auth, onUpdate} = this.props - if (auth.status === AuthorizationUpdateRequest.StatusEnum.Active) { - auth.status = AuthorizationUpdateRequest.StatusEnum.Inactive + if (auth.status === 'active') { + auth.status = 'inactive' } else { - auth.status = AuthorizationUpdateRequest.StatusEnum.Active + auth.status = 'active' } onUpdate(auth) } diff --git a/ui/src/authorizations/components/TokensTab.tsx b/ui/src/authorizations/components/TokensTab.tsx index 26d5085e8db..86a878fbfa4 100644 --- a/ui/src/authorizations/components/TokensTab.tsx +++ b/ui/src/authorizations/components/TokensTab.tsx @@ -12,8 +12,7 @@ import TabbedPageHeader from 'src/shared/components/tabbed_page/TabbedPageHeader import GenerateTokenDropdown from 'src/authorizations/components/GenerateTokenDropdown' // Types -import {Authorization} from '@influxdata/influx' -import {AppState} from 'src/types' +import {AppState, Authorization} from 'src/types' import {SortTypes} from 'src/shared/utils/sort' enum AuthSearchKeys { diff --git a/ui/src/authorizations/components/ViewTokenOverlay.tsx b/ui/src/authorizations/components/ViewTokenOverlay.tsx index bdb1af833e7..15a7326c461 100644 --- a/ui/src/authorizations/components/ViewTokenOverlay.tsx +++ b/ui/src/authorizations/components/ViewTokenOverlay.tsx @@ -11,7 +11,7 @@ import PermissionsWidget, { import CodeSnippet from 'src/shared/components/CodeSnippet' // Types -import {Authorization, Permission} from '@influxdata/influx' +import {Authorization, Permission} from 'src/types' interface Props { auth: Authorization @@ -58,7 +58,7 @@ export default class ViewTokenOverlay extends PureComponent { ) } - private get permissions(): {[x: string]: Permission.ActionEnum[]} { + private get permissions(): {[x: string]: Permission['action'][]} { const p = this.props.auth.permissions.reduce((acc, {action, resource}) => { const {type} = resource const name = get(resource, 'name', '') @@ -82,7 +82,7 @@ export default class ViewTokenOverlay extends PureComponent { private itemID = ( permission: string, - action: Permission.ActionEnum + action: Permission['action'] ): string => { return `${permission}-${action}-${permission || '*'}-${permission || '*'}` } diff --git a/ui/src/authorizations/reducers/index.ts b/ui/src/authorizations/reducers/index.ts index 1e5b7a75f54..8cc19ba041b 100644 --- a/ui/src/authorizations/reducers/index.ts +++ b/ui/src/authorizations/reducers/index.ts @@ -2,9 +2,8 @@ import {produce} from 'immer' // Types -import {RemoteDataState} from 'src/types' +import {RemoteDataState, Authorization} from 'src/types' import {Action} from 'src/authorizations/actions' -import {Authorization} from '@influxdata/influx' const initialState = (): AuthorizationsState => ({ status: RemoteDataState.NotStarted, diff --git a/ui/src/authorizations/utils/permissions.ts b/ui/src/authorizations/utils/permissions.ts index ad2d88b4b2c..901cccbd6d0 100644 --- a/ui/src/authorizations/utils/permissions.ts +++ b/ui/src/authorizations/utils/permissions.ts @@ -1,126 +1,125 @@ -import {Permission, PermissionResource, Authorization} from '@influxdata/influx' -import {Bucket} from 'src/types' +import {Bucket, Permission, Authorization} from 'src/types' -export const allAccessPermissions = (orgID: string) => [ +export const allAccessPermissions = (orgID: string): Permission[] => [ { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Orgs, id: orgID}, + action: 'read', + resource: {type: 'orgs', id: orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Authorizations, orgID}, + action: 'read', + resource: {type: 'authorizations', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Authorizations, orgID}, + action: 'write', + resource: {type: 'authorizations', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Buckets, orgID}, + action: 'read', + resource: {type: 'buckets', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Buckets, orgID}, + action: 'write', + resource: {type: 'buckets', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Dashboards, orgID}, + action: 'read', + resource: {type: 'dashboards', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Dashboards, orgID}, + action: 'write', + resource: {type: 'dashboards', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Sources, orgID}, + action: 'read', + resource: {type: 'sources', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Sources, orgID}, + action: 'write', + resource: {type: 'sources', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Tasks, orgID}, + action: 'read', + resource: {type: 'tasks', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Tasks, orgID}, + action: 'write', + resource: {type: 'tasks', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Telegrafs, orgID}, + action: 'read', + resource: {type: 'telegrafs', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Telegrafs, orgID}, + action: 'write', + resource: {type: 'telegrafs', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Users, orgID}, + action: 'read', + resource: {type: 'users', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Users, orgID}, + action: 'write', + resource: {type: 'users', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Variables, orgID}, + action: 'read', + resource: {type: 'variables', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Variables, orgID}, + action: 'write', + resource: {type: 'variables', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Scrapers, orgID}, + action: 'read', + resource: {type: 'scrapers', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Scrapers, orgID}, + action: 'write', + resource: {type: 'scrapers', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Secrets, orgID}, + action: 'read', + resource: {type: 'secrets', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Secrets, orgID}, + action: 'write', + resource: {type: 'secrets', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Labels, orgID}, + action: 'read', + resource: {type: 'labels', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Labels, orgID}, + action: 'write', + resource: {type: 'labels', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Views, orgID}, + action: 'read', + resource: {type: 'views', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Views, orgID}, + action: 'write', + resource: {type: 'views', orgID}, }, { - action: Permission.ActionEnum.Read, - resource: {type: PermissionResource.TypeEnum.Documents, orgID}, + action: 'read', + resource: {type: 'documents', orgID}, }, { - action: Permission.ActionEnum.Write, - resource: {type: PermissionResource.TypeEnum.Documents, orgID}, + action: 'write', + resource: {type: 'documents', orgID}, }, ] export const specificBucketsPermissions = ( buckets: Bucket[], - permission: Permission.ActionEnum + permission: Permission['action'] ): Permission[] => { return buckets.map(b => { return { action: permission, resource: { - type: PermissionResource.TypeEnum.Buckets, + type: 'buckets' as 'buckets', orgID: b.orgID, id: b.id, }, @@ -130,12 +129,12 @@ export const specificBucketsPermissions = ( export const allBucketsPermissions = ( orgID: string, - permission: Permission.ActionEnum + permission: Permission['action'] ): Permission[] => { return [ { action: permission, - resource: {type: PermissionResource.TypeEnum.Buckets, orgID}, + resource: {type: 'buckets', orgID}, }, ] } diff --git a/ui/src/dataExplorer/components/SaveAsTaskForm.tsx b/ui/src/dataExplorer/components/SaveAsTaskForm.tsx index c68219da8ce..70164267944 100644 --- a/ui/src/dataExplorer/components/SaveAsTaskForm.tsx +++ b/ui/src/dataExplorer/components/SaveAsTaskForm.tsx @@ -30,14 +30,13 @@ import { } from 'src/utils/taskOptionsToFluxScript' // Types -import {AppState, TimeRange, RemoteDataState} from 'src/types' +import {AppState, TimeRange, RemoteDataState, Authorization} from 'src/types' import { TaskSchedule, TaskOptions, TaskOptionKeys, } from 'src/utils/taskOptionsToFluxScript' import {DashboardDraftQuery} from 'src/types/dashboards' -import {Authorization} from '@influxdata/influx' import {SpinnerContainer, TechnoSpinner} from '@influxdata/clockface' interface OwnProps { diff --git a/ui/src/tasks/actions/index.ts b/ui/src/tasks/actions/index.ts index c8d71102cf5..524bfa4baf7 100644 --- a/ui/src/tasks/actions/index.ts +++ b/ui/src/tasks/actions/index.ts @@ -3,7 +3,7 @@ import {push, goBack} from 'react-router-redux' import _ from 'lodash' // APIs -import {LogEvent, ITask as Task, Authorization} from '@influxdata/influx' +import {LogEvent, ITask as Task} from '@influxdata/influx' import {client} from 'src/utils/api' import {notify} from 'src/shared/actions/notifications' import { @@ -33,7 +33,7 @@ import {setExportTemplate} from 'src/templates/actions' import * as copy from 'src/shared/copy/notifications' // Types -import {AppState, Label, TaskTemplate} from 'src/types' +import {AppState, Label, TaskTemplate, Authorization} from 'src/types' import {RemoteDataState} from '@influxdata/clockface' import {Run} from 'src/tasks/components/TaskRunsPage' diff --git a/ui/src/tasks/components/TaskForm.tsx b/ui/src/tasks/components/TaskForm.tsx index eb109a100b4..21f939d7e18 100644 --- a/ui/src/tasks/components/TaskForm.tsx +++ b/ui/src/tasks/components/TaskForm.tsx @@ -20,7 +20,7 @@ import { ComponentSize, } from '@influxdata/clockface' import {TaskOptions, TaskSchedule} from 'src/utils/taskOptionsToFluxScript' -import {Authorization} from '@influxdata/influx' +import {Authorization} from 'src/types' import TaskTokenDropdown from './TaskTokenDropdown' interface Props { diff --git a/ui/src/tasks/components/TaskTokenDropdown.tsx b/ui/src/tasks/components/TaskTokenDropdown.tsx index e88d641b3f4..ea4c8138a84 100644 --- a/ui/src/tasks/components/TaskTokenDropdown.tsx +++ b/ui/src/tasks/components/TaskTokenDropdown.tsx @@ -4,7 +4,7 @@ import React, {PureComponent} from 'react' // Types import {Dropdown} from '@influxdata/clockface' -import {Authorization} from '@influxdata/influx' +import {Authorization} from 'src/types' interface Props { tokens: Authorization[] diff --git a/ui/src/tasks/containers/TaskEditPage.tsx b/ui/src/tasks/containers/TaskEditPage.tsx index 5e476713005..a1eb6ab1261 100644 --- a/ui/src/tasks/containers/TaskEditPage.tsx +++ b/ui/src/tasks/containers/TaskEditPage.tsx @@ -28,8 +28,7 @@ import { TaskOptionKeys, TaskSchedule, } from 'src/utils/taskOptionsToFluxScript' -import {AppState, Task, RemoteDataState} from 'src/types' -import {Authorization} from '@influxdata/influx' +import {AppState, Task, RemoteDataState, Authorization} from 'src/types' import {getAuthorizations} from 'src/authorizations/actions' import {SpinnerContainer, TechnoSpinner} from '@influxdata/clockface' diff --git a/ui/src/tasks/containers/TaskPage.tsx b/ui/src/tasks/containers/TaskPage.tsx index 6176b922c26..e76bcb0f109 100644 --- a/ui/src/tasks/containers/TaskPage.tsx +++ b/ui/src/tasks/containers/TaskPage.tsx @@ -26,14 +26,14 @@ import { addDestinationToFluxScript, } from 'src/utils/taskOptionsToFluxScript' -import {AppState} from 'src/types' +// Types +import {AppState, Authorization} from 'src/types' import { TaskOptions, TaskOptionKeys, TaskSchedule, } from 'src/utils/taskOptionsToFluxScript' import {getAuthorizations} from 'src/authorizations/actions' -import {Authorization} from '@influxdata/influx' import { RemoteDataState, SpinnerContainer, diff --git a/ui/src/tasks/reducers/index.ts b/ui/src/tasks/reducers/index.ts index cd4aad3b2a2..08fa66e299f 100644 --- a/ui/src/tasks/reducers/index.ts +++ b/ui/src/tasks/reducers/index.ts @@ -1,11 +1,12 @@ import {TaskOptions, TaskSchedule} from 'src/utils/taskOptionsToFluxScript' -import {LogEvent, Authorization} from '@influxdata/influx' +import {LogEvent} from '@influxdata/influx' -//Types +// Types import {Action} from 'src/tasks/actions' import {ITask as Task} from '@influxdata/influx' import {RemoteDataState} from '@influxdata/clockface' import {Run} from 'src/tasks/components/TaskRunsPage' +import {Authorization} from 'src/types' export interface TasksState { status: RemoteDataState diff --git a/ui/src/types/auth.ts b/ui/src/types/auth.ts new file mode 100644 index 00000000000..b31140ce1b2 --- /dev/null +++ b/ui/src/types/auth.ts @@ -0,0 +1 @@ +export {Authorization, Permission} from 'src/client' diff --git a/ui/src/types/index.ts b/ui/src/types/index.ts index a0550302cac..8b316f64c9f 100644 --- a/ui/src/types/index.ts +++ b/ui/src/types/index.ts @@ -31,3 +31,4 @@ export * from './autoRefresh' export * from './arguments' export * from './timeZones' export * from './alerting' +export * from './auth'