-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [UIE-8128] - add new account api with (#11181)
- Loading branch information
1 parent
8ee5281
commit 1d0051e
Showing
14 changed files
with
232 additions
and
3 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"@linode/api-v4": Added | ||
--- | ||
|
||
New IAM endpoints and types ([#11181](https://github.com/linode/manager/pull/11181)) |
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
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,3 @@ | ||
export * from './resources'; | ||
|
||
export * from './types'; |
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,16 @@ | ||
import { BETA_API_ROOT } from '../constants'; | ||
import Request, { setMethod, setURL } from '../request'; | ||
import { IamAccountResource } from './types'; | ||
|
||
/** | ||
* getAccountResources | ||
* | ||
* Return all resources for account. | ||
* | ||
*/ | ||
export const getAccountResources = () => { | ||
return Request<IamAccountResource>( | ||
setURL(`${BETA_API_ROOT}/resources`), | ||
setMethod('GET') | ||
); | ||
}; |
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,21 @@ | ||
type ResourceType = | ||
| 'linode' | ||
| 'firewall' | ||
| 'nodebalancer' | ||
| 'longview' | ||
| 'domain' | ||
| 'stackscript' | ||
| 'image' | ||
| 'volume' | ||
| 'database' | ||
| 'vpc'; | ||
|
||
export type IamAccountResource = { | ||
resource_type: ResourceType; | ||
resources: Resource[]; | ||
}[]; | ||
|
||
export interface Resource { | ||
name: string; | ||
id: number; | ||
} |
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,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
mock data and query for new account api ([#11181](https://github.com/linode/manager/pull/11181)) |
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,66 @@ | ||
import { IamAccountPermissions } from '@linode/api-v4'; | ||
import Factory from 'src/factories/factoryProxy'; | ||
|
||
export const accountPermissionsFactory = Factory.Sync.makeFactory<IamAccountPermissions>( | ||
{ | ||
account_access: [ | ||
{ | ||
resource_type: 'account', | ||
roles: [ | ||
{ | ||
name: 'account_admin', | ||
description: | ||
'Access to perform any supported action on all resources in the account', | ||
permissions: ['create_linode', 'update_linode', 'update_firewall'], | ||
}, | ||
], | ||
}, | ||
{ | ||
resource_type: 'linode', | ||
roles: [ | ||
{ | ||
name: 'account_linode_admin', | ||
description: | ||
'Access to perform any supported action on all linode instances in the account', | ||
permissions: ['create_linode', 'update_linode', 'delete_linode'], | ||
}, | ||
], | ||
}, | ||
{ | ||
resource_type: 'firewall', | ||
roles: [ | ||
{ | ||
name: 'firewall_creator', | ||
description: 'Access to create a firewall instance', | ||
}, | ||
], | ||
}, | ||
], | ||
resource_access: [ | ||
{ | ||
resource_type: 'linode', | ||
roles: [ | ||
{ | ||
name: 'linode_contributor', | ||
description: 'Access to update a linode instance', | ||
permissions: ['update_linode', 'view_linode'], | ||
}, | ||
], | ||
}, | ||
{ | ||
resource_type: 'firewall', | ||
roles: [ | ||
{ | ||
name: 'firewall_viewer', | ||
description: 'Access to view a firewall instance', | ||
}, | ||
{ | ||
name: 'firewall_admin', | ||
description: | ||
'Access to perform any supported action on a firewall instance', | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
); |
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,29 @@ | ||
import { IamAccountResource } from '@linode/api-v4'; | ||
import Factory from 'src/factories/factoryProxy'; | ||
|
||
export const accountResourcesFactory = Factory.Sync.makeFactory<IamAccountResource>( | ||
[ | ||
{ | ||
resource_type: 'linode', | ||
resources: [ | ||
{ | ||
name: 'debian-us-123', | ||
id: 12345678, | ||
}, | ||
{ | ||
name: 'linode-uk-123', | ||
id: 23456789, | ||
}, | ||
], | ||
}, | ||
{ | ||
resource_type: 'firewall', | ||
resources: [ | ||
{ | ||
name: 'firewall-us-123', | ||
id: 45678901, | ||
}, | ||
], | ||
}, | ||
] | ||
); |
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 |
---|---|---|
@@ -1,9 +1,26 @@ | ||
import { APIError, IamUserPermissions } from '@linode/api-v4'; | ||
import { | ||
APIError, | ||
IamUserPermissions, | ||
IamAccountPermissions, | ||
} from '@linode/api-v4'; | ||
import { iamQueries } from './queries'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useProfile } from 'src/queries/profile/profile'; | ||
import { queryPresets } from '../base'; | ||
|
||
export const useAccountUserPermissions = (username: string) => { | ||
return useQuery<IamUserPermissions, APIError[]>( | ||
iamQueries.user(username)._ctx.permissions | ||
); | ||
}; | ||
|
||
export const useAccountPermissions = () => { | ||
const { data: profile } = useProfile(); | ||
|
||
return useQuery<IamAccountPermissions, APIError[]>({ | ||
...iamQueries.permissions, | ||
...queryPresets.oneTimeFetch, | ||
...queryPresets.noRetry, | ||
enabled: !profile?.restricted, | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getAccountResources } from '@linode/api-v4'; | ||
import { createQueryKeys } from '@lukemorales/query-key-factory'; | ||
|
||
export const resourcesQueries = createQueryKeys('resources', { | ||
resources: { | ||
queryFn: getAccountResources, | ||
queryKey: null, | ||
}, | ||
}); |
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,16 @@ | ||
import { IamAccountResource, APIError } from '@linode/api-v4'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useProfile } from 'src/queries/profile/profile'; | ||
import { queryPresets } from '../base'; | ||
import { resourcesQueries } from './queries'; | ||
|
||
export const useAccountResources = () => { | ||
const { data: profile } = useProfile(); | ||
|
||
return useQuery<IamAccountResource, APIError[]>({ | ||
...resourcesQueries.resources, | ||
...queryPresets.oneTimeFetch, | ||
...queryPresets.noRetry, | ||
enabled: !profile?.restricted, | ||
}); | ||
}; |