Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Upcoming Features
---

Add endpoints for `/v4/images/sharegroups/members` and `/v4/images/sharegroups/tokens` ([#12984](https://github.com/linode/manager/pull/12984))
237 changes: 237 additions & 0 deletions packages/api-v4/src/images/sharegroup.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be consistent with the file naming as well (all lower caps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did find nodePool.ts to follow the camelCasing though πŸ€”

Copy link
Contributor

Choose a reason for hiding this comment

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

Right but nodePool is camel case everywhere. this file name is the only instance of shareGroups being camel case

It's not a big deal, just a consistency nit. does not matter much to me

Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
import {
addSharegroupMemberSchema,
generateSharegroupTokenSchema,
updateSharegroupMemberSchema,
updateSharegroupTokenSchema,
} from '@linode/validation/lib/images.schema';

import { BETA_API_ROOT } from '../constants';
import Request, {
setData,
setMethod,
setParams,
setURL,
setXFilter,
} from '../request';

import type { Filter, ResourcePage as Page, Params } from '../types';
import type {
AddSharegroupMemberPayload,
GenerateSharegroupTokenPayload,
Image,
Sharegroup,
SharegroupMember,
SharegroupToken,
UpdateSharegroupMemberPayload,
} from './types';

/**
* Add Member to the Sharegroup
*
* @param sharegroupId {string} ID of the Sharegroup to add member
* @param data {AddSharegroupMemberPayload} the Member details
*/
export const addMembersToSharegroup = (
sharegroupId: number,
data: AddSharegroupMemberPayload,
) => {
return Request<Sharegroup>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/${encodeURIComponent(sharegroupId)}/images`,
),
setMethod('POST'),
setData(data, addSharegroupMemberSchema),
);
};

/**
* Generate user token for the Sharegroup
*
* @param data {GenerateSharegroupTokenPayload} the token details
*/
export const generateSharegroupToken = (
data: GenerateSharegroupTokenPayload,
) => {
return Request<SharegroupToken>(
setURL(`${BETA_API_ROOT}/images/sharegroups/tokens`),
setMethod('POST'),
setData(data, generateSharegroupTokenSchema),
);
};

/**
* Get details of the Sharegroup the token has been accepted into
*
* @param token_uuid {string} Token UUID of the user
*/
export const getSharegroupFromToken = (token_uuid: string) => {

Check warning on line 67 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":67,"column":40,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":67,"endColumn":58}
Request<Sharegroup>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/tokens/${encodeURIComponent(token_uuid)}/sharegroup`,
),
setMethod('GET'),
);
};

/**
* Get a paginated list of Sharegroup Images the token has been accepted into
*
* @param token_uuid {string} Token UUID of the user
*/
export const getSharegroupImagesFromToken = (
token_uuid: string,

Check warning on line 82 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":82,"column":3,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":82,"endColumn":21}
params: Params = {},
filters: Filter = {},
) => {
Request<Page<Image>>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/tokens/${encodeURIComponent(token_uuid)}/sharegroups/images`,
),
setMethod('GET'),
setParams(params),
setXFilter(filters),
);
};

/**
* Get a paginated list of members part of the Sharegroup
*
* @param sharegroupId {string} ID of the Sharegroup to look up
*/
export const getSharegroupMembers = (
sharegroupId: string,
params: Params = {},
filters: Filter = {},
) => {
Request<Page<SharegroupMember>>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/${encodeURIComponent(sharegroupId)}/members`,
),
setMethod('GET'),
setParams(params),
setXFilter(filters),
);
};

/**
* Get member details of a user from the Sharegroup
*
* @param sharegroupId {string} ID of the Sharegroup to look up
* @param token_uuid {string} Token UUID of the user to look up
*/
export const getSharegroupMember = (
sharegroupId: string,
token_uuid: string,

Check warning on line 124 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":124,"column":3,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":124,"endColumn":21}
) => {
Request<SharegroupMember>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/${encodeURIComponent(sharegroupId)}/members/${encodeURIComponent(token_uuid)}`,
),
setMethod('GET'),
);
};

/**
* Returns a paginated list of tokens created by the user
*/
export const getUserSharegroupTokens = (
params: Params = {},
filters: Filter = {},
) => {
Request<Page<SharegroupToken>>(
setURL(`${BETA_API_ROOT}/images/sharegroups/tokens`),
setMethod('GET'),
setParams(params),
setXFilter(filters),
);
};

/**
* Get details about a specific token created by the user
*
* @param token_uuid Token UUID of the user to look up
*/
export const getUserSharegroupToken = (token_uuid: string) => {

Check warning on line 154 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":154,"column":40,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":154,"endColumn":58}
Request<SharegroupToken>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/tokens/${encodeURIComponent(token_uuid)}`,
),
setMethod('GET'),
);
};

/**
* Update a user token's label
*
* @param token_uuid {string} token UUID of the user
* @param data {UpdateSharegroupMemberPayload} the updated label
*/
export const updateSharegroupToken = (
token_uuid: string,

Check warning on line 170 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":170,"column":3,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":170,"endColumn":21}
data: UpdateSharegroupMemberPayload,
) => {
return Request<SharegroupToken>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/tokens/${encodeURIComponent(token_uuid)}`,
),
setMethod('PUT'),
setData(data, updateSharegroupTokenSchema),
);
};

/**
* Update a Sharegroup member's label
*
* @param token_uuid {string} token UUID of the user
* @param data {UpdateSharegroupMemberPayload} the updated label
*/
interface UpdateSharegroupMember {
data: UpdateSharegroupMemberPayload;
sharegroupId: string;
token_uuid: string;
}

export const updateSharegroupMember = ({
sharegroupId,
token_uuid,

Check warning on line 196 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":196,"column":3,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":196,"endColumn":13}
data,
}: UpdateSharegroupMember) => {
return Request<SharegroupMember>(
setURL(
`${BETA_API_ROOT}/images/sharegroups/${encodeURIComponent(sharegroupId)}/members/${encodeURIComponent(token_uuid)}`,
),
setMethod('PUT'),
setData(data, updateSharegroupMemberSchema),
);
};

/**
* Delete a user token
*
* @param token_uuid {string} Token UUID of the user to delete
*/
export const deleteSharegroupToken = (token_uuid: string) => {

Check warning on line 213 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":213,"column":39,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":213,"endColumn":57}
return Request<{}>(

Check warning on line 214 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 The `{}` ("empty object") type allows any non-nullish value, including literals like `0` and `""`. - If that's what you want, disable this lint rule with an inline comment or configure the 'allowObjectTypes' rule option. - If you want a type meaning "any object", you probably want `object` instead. - If you want a type meaning "any value", you probably want `unknown` instead. Raw Output: {"ruleId":"@typescript-eslint/no-empty-object-type","severity":1,"message":"The `{}` (\"empty object\") type allows any non-nullish value, including literals like `0` and `\"\"`.
setURL(
`${BETA_API_ROOT}/images/sharegroups/tokens/${encodeURIComponent(token_uuid)}`,
),
setMethod('DELETE'),
);
};

/**
* Delete a sharegroup Member
*
* @param token_uuid {string} Token UUID of the member to delete
*/
export const deleteSharegroupMember = (
sharegroupId: string,
token_uuid: string,

Check warning on line 229 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 Parameter name `token_uuid` must match one of the following formats: camelCase Raw Output: {"ruleId":"@typescript-eslint/naming-convention","severity":1,"message":"Parameter name `token_uuid` must match one of the following formats: camelCase","line":229,"column":3,"nodeType":"Identifier","messageId":"doesNotMatchFormat","endLine":229,"endColumn":21}
) => {
return Request<{}>(

Check warning on line 231 in packages/api-v4/src/images/sharegroup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (api-v4)

[eslint] reported by reviewdog 🐢 The `{}` ("empty object") type allows any non-nullish value, including literals like `0` and `""`. - If that's what you want, disable this lint rule with an inline comment or configure the 'allowObjectTypes' rule option. - If you want a type meaning "any object", you probably want `object` instead. - If you want a type meaning "any value", you probably want `unknown` instead. Raw Output: {"ruleId":"@typescript-eslint/no-empty-object-type","severity":1,"message":"The `{}` (\"empty object\") type allows any non-nullish value, including literals like `0` and `\"\"`.
setURL(
`${BETA_API_ROOT}/images/sharegroups/${encodeURIComponent(sharegroupId)}/members/${encodeURIComponent(token_uuid)}`,
),
setMethod('DELETE'),
);
};
Loading
Loading