Skip to content

Commit 1aa9b45

Browse files
Revert "STORIF-330: refactored handling of Quotas. Introduced a service definition that allows to quickly introduce new services. Added service selector."
This reverts commit da0a602.
1 parent e5b0511 commit 1aa9b45

36 files changed

Lines changed: 1006 additions & 1420 deletions
Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11
import { BETA_API_ROOT } from '../constants';
22
import Request, { setMethod, setParams, setURL, setXFilter } from '../request';
33

4-
import type { Quota, QuotaServiceType, QuotaUsage } from './types';
4+
import type { Quota, QuotaType, QuotaUsage } from './types';
55
import type { Filter, ResourcePage as Page, Params } from 'src/types';
66

77
/**
88
* getQuota
99
*
1010
* Returns the details for a single quota within a particular service specified by `type`.
1111
*
12-
* @param quotaService { QuotaServiceType } retrieve a quota within this service type.
12+
* @param type { QuotaType } retrieve a quota within this service type.
1313
* @param id { number } the quota ID to look up.
14-
* @param apiCollection { string } quota collection name (quotas/global-quotas).
14+
* @param collection { string } quota collection name (quotas/global-quotas).
1515
*/
16-
export const getQuota = (
17-
quotaService: QuotaServiceType,
18-
apiCollection: string,
19-
id: number,
20-
) =>
16+
export const getQuota = (type: QuotaType, collection: string, id: number) =>
2117
Request<Quota>(
22-
setURL(`${BETA_API_ROOT}/${quotaService}/${apiCollection}/${id}`),
18+
setURL(`${BETA_API_ROOT}/${type}/${collection}/${id}`),
2319
setMethod('GET'),
2420
);
2521

2622
/**
2723
* getQuotas
2824
*
29-
* Returns a paginated list of quotas for a particular service specified by `quotaService`.
25+
* Returns a paginated list of quotas for a particular service specified by `type`.
3026
*
3127
* This request can be filtered on `quota_name`, `service_name` and `scope`.
3228
*
33-
* @param quotaService { QuotaServiceType } retrieve quotas within this service quotaService.
34-
* @param apiCollection { string } quota API collection name (e.g. quotas, global-quotas, etc.).
35-
* @param params { Params } query params to include in the request.
36-
* @param filter { Filter } filters to include in the request.
29+
* @param type { QuotaType } retrieve quotas within this service type.
30+
* @param collection { string } quota collection name (quotas/global-quotas).
3731
*/
3832
export const getQuotas = (
39-
quotaService: QuotaServiceType,
40-
apiCollection: string,
33+
type: QuotaType,
34+
collection: string,
4135
params: Params = {},
4236
filter: Filter = {},
4337
) =>
4438
Request<Page<Quota>>(
45-
setURL(`${BETA_API_ROOT}/${quotaService}/${apiCollection}`),
39+
setURL(`${BETA_API_ROOT}/${type}/${collection}`),
4640
setMethod('GET'),
4741
setXFilter(filter),
4842
setParams(params),
@@ -53,16 +47,16 @@ export const getQuotas = (
5347
*
5448
* Returns the usage for a single quota within a particular service specified by `type`.
5549
*
56-
* @param quotaService { QuotaServiceType } retrieve a quota within this service type.
57-
* @param apiCollection { string } quota collection name (quotas/global-quotas).
50+
* @param type { QuotaType } retrieve a quota within this service type.
51+
* @param collection { string } quota collection name (quotas/global-quotas).
5852
* @param id { string } the quota ID to look up.
5953
*/
6054
export const getQuotaUsage = (
61-
quotaService: QuotaServiceType,
62-
apiCollection: string,
55+
type: QuotaType,
56+
collection: string,
6357
id: string,
6458
) =>
6559
Request<QuotaUsage>(
66-
setURL(`${BETA_API_ROOT}/${quotaService}/${apiCollection}/${id}/usage`),
60+
setURL(`${BETA_API_ROOT}/${type}/${collection}/${id}/usage`),
6761
setMethod('GET'),
6862
);
Lines changed: 42 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
import type { ObjectStorageEndpointTypes } from 'src/object-storage';
22
import type { Region } from 'src/regions';
33

4-
export type LinodeQuotaResourceMetric = 'CPU' | 'GPU' | 'VPU';
5-
export type LkeQuotaResourceMetric = 'cluster';
6-
export type ObjectStorageEndpointQuotaResourceMetric =
7-
| 'bucket'
8-
| 'byte'
9-
| 'byte_per_second'
10-
| 'object'
11-
| 'request';
12-
export type ObjectStorageGlobalQuotaResourceMetric = 'key';
4+
export enum QuotaResourceMetrics {
5+
BUCKET = 'bucket',
6+
BYTE = 'byte',
7+
BYTE_PER_SECOND = 'byte_per_second',
8+
CLUSTER = 'cluster',
9+
CPU = 'CPU',
10+
GPU = 'GPU',
11+
OBJECT = 'object',
12+
REQUEST = 'request',
13+
VPU = 'VPU',
14+
}
1315

14-
interface QuotaCommon<T> {
16+
/**
17+
* A Quota is a service used limit that is rated based on service metrics such
18+
* as vCPUs used, instances or storage size.
19+
*/
20+
export interface Quota {
1521
/**
1622
* Longer explanatory description for the quota.
1723
*/
1824
description: string;
1925

26+
/**
27+
* The OBJ endpoint type to which this limit applies.
28+
*
29+
* For OBJ limits only.
30+
*/
31+
endpoint_type?: ObjectStorageEndpointTypes;
32+
33+
/**
34+
* Sets usage column to be n/a when value is false.
35+
*/
36+
has_usage?: boolean;
37+
2038
/**
2139
* A unique identifier for the quota.
2240
*/
@@ -34,80 +52,31 @@ interface QuotaCommon<T> {
3452
quota_name: string;
3553

3654
/**
37-
* The unit of measurement for this service limit.
55+
* Customer facing id describing the quota.
3856
*/
39-
resource_metric: T;
40-
}
57+
quota_type: string;
4158

42-
interface QuotaCommonWithRegionApplied<T> extends QuotaCommon<T> {
4359
/**
4460
* The region slug to which this limit applies.
4561
*
4662
* OBJ limits are applied by endpoint, not region.
4763
* This below really just is a `string` type but being verbose helps with reading comprehension.
4864
*/
49-
region_applied: 'global' | Region['id'];
50-
}
51-
52-
interface QuotaCommonWithUsage<T> extends QuotaCommon<T> {
53-
/**
54-
* Determines whether usage information is provided for this quota.
55-
*/
56-
has_usage: boolean;
57-
}
58-
59-
export type LinodeQuota =
60-
QuotaCommonWithRegionApplied<LinodeQuotaResourceMetric>;
61-
62-
export type LkeQuota = QuotaCommonWithRegionApplied<LkeQuotaResourceMetric>;
63-
64-
export interface ObjectStorageGlobalQuota
65-
extends QuotaCommon<ObjectStorageGlobalQuotaResourceMetric> {
66-
/**
67-
* Represents the quota type.
68-
*/
69-
quota_type: 'keys';
70-
}
71-
72-
export interface ObjectStorageEndpointQuota
73-
extends QuotaCommonWithUsage<ObjectStorageEndpointQuotaResourceMetric> {
74-
/**
75-
* The OBJ endpoint type to which this limit applies.
76-
*
77-
*/
78-
endpoint_type: ObjectStorageEndpointTypes;
65+
region_applied?: 'global' | Region['id'];
7966

8067
/**
81-
* Represents the quota type.
68+
* The unit of measurement for this service limit.
8269
*/
83-
quota_type:
84-
| 'obj-buckets'
85-
| 'obj-bytes'
86-
| 'obj-objects'
87-
| 'obj-per-ip-concurrent-requests'
88-
| 'obj-per-ip-egress-throughput'
89-
| 'obj-per-ip-ingress-throughput'
90-
| 'obj-total-concurrent-requests'
91-
| 'obj-total-egress-throughput'
92-
| 'obj-total-ingress-throughput';
70+
resource_metric: QuotaResourceMetrics;
9371

9472
/**
9573
* The S3 endpoint URL to which this limit applies.
9674
*
75+
* For OBJ limits only.
9776
*/
98-
s3_endpoint: string;
77+
s3_endpoint?: string;
9978
}
10079

101-
/**
102-
* A Quota is a service used limit that is rated based on service metrics such
103-
* as vCPUs used, instances or storage size.
104-
*/
105-
export type Quota =
106-
| LinodeQuota
107-
| LkeQuota
108-
| ObjectStorageEndpointQuota
109-
| ObjectStorageGlobalQuota;
110-
11180
/**
11281
* A usage limit for a given Quota based on service metrics such
11382
* as vCPUs, instances or storage size.
@@ -128,8 +97,10 @@ export interface QuotaUsage {
12897
usage: null | number;
12998
}
13099

131-
/**
132-
* Represents the type of service for a given quota, e.g. Linodes, Object Storage, etc.
133-
* The type must match the service part of the quota endpoint paths.
134-
*/
135-
export type QuotaServiceType = 'linode' | 'lke' | 'object-storage';
100+
export const quotaTypes = {
101+
linode: 'Linodes',
102+
lke: 'Kubernetes',
103+
'object-storage': 'Object Storage',
104+
} as const;
105+
106+
export type QuotaType = keyof typeof quotaTypes;

0 commit comments

Comments
 (0)