Skip to content

Commit

Permalink
feat: [M3-7535] – Update OBJ types to support Multicluster changes (l…
Browse files Browse the repository at this point in the history
  • Loading branch information
dwiley-akamai authored Jan 4, 2024
1 parent 6292d01 commit 5473231
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 11 deletions.
5 changes: 5 additions & 0 deletions packages/api-v4/.changeset/pr-9996-changed-1702508393416.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Changed
---

Adjusted several OBJ types to accommodate forthcoming API changes ([#9996](https://github.com/linode/manager/pull/9996))
47 changes: 38 additions & 9 deletions packages/api-v4/src/object-storage/types.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,58 @@
export interface RegionS3EndpointAndID {
id: string;
s3_endpoint: string;
}

export interface ObjectStorageKey {
access_key: string;
bucket_access: Scope[] | null;
id: number;
label: string;
secret_key: string;
limited: boolean;
bucket_access: Scope[] | null;
regions: RegionS3EndpointAndID[];
secret_key: string;
}

export type AccessType = 'read_only' | 'read_write' | 'none';

export interface Scope {
bucket_name: string;
cluster: string;
permissions: AccessType;
cluster: string;
region?: string; // @TODO OBJ Multicluster: Remove optional indicator when API changes get released to prod
}

export interface ScopeRequest extends Omit<Scope, 'cluster'> {
// @TODO OBJ Multicluster: Omit 'region' as well when API changes get released to prod
cluster?: string;
region?: string;
}

export interface ObjectStorageKeyRequest {
label: string;
bucket_access: Scope[] | null;
regions?: string[];
}

export interface UpdateObjectStorageKeyRequest {
label: string;
label?: string;
regions?: string[];
}

export interface ObjectStorageBucketRequestPayload {
label: string;
region?: string; // @TODO OBJ Multicluster - This field will become required, and the 'cluster' field will be deprecated once the feature is fully rolled out in production as part of the process of cleaning up the 'objMultiCluster' feature flag.
cluster?: string;
acl?: 'private' | 'public-read' | 'authenticated-read' | 'public-read-write';
cluster?: string;
cors_enabled?: boolean;
label: string;
region?: string;
/*
@TODO OBJ Multicluster: 'region' will become required, and the 'cluster' field will be deprecated
once the feature is fully rolled out in production as part of the process of cleaning up the 'objMultiCluster'
feature flag.
Until then, the API will accept either cluster or region, or both (provided they are the same value).
The payload requires at least one of them though, which will be enforced via validation.
*/
}

export interface ObjectStorageDeleteBucketRequestPayload {
Expand All @@ -37,13 +61,18 @@ export interface ObjectStorageDeleteBucketRequestPayload {
}

export interface ObjectStorageBucket {
region?: string; // @TODO OBJ Multicluster - This field will become required, and the 'cluster' field will be deprecated once the feature is fully rolled out in production as part of the process of cleaning up the 'objMultiCluster' feature flag.
/*
@TODO OBJ Multicluster: 'region' will become required, and the 'cluster' field will be deprecated
once the feature is fully rolled out in production as part of the process of cleaning up the 'objMultiCluster'
feature flag.
*/
region?: string;
label: string;
created: string;
cluster: string;
hostname: string;
size: number; // Size of bucket in bytes
objects: number;
size: number; // Size of bucket in bytes
}

export interface ObjectStorageObject {
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-9996-changed-1702508487859.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Changed
---

Updated OBJ types used in several Object Storage components ([#9996](https://github.com/linode/manager/pull/9996))
2 changes: 2 additions & 0 deletions packages/manager/src/__data__/buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const buckets: ObjectStorageBucket[] = [
hostname: 'test-bucket-001.alpha.linodeobjects.com',
label: 'test-bucket-001',
objects: 2,
region: 'us-east',
size: 5418860544,
},
{
Expand All @@ -15,6 +16,7 @@ export const buckets: ObjectStorageBucket[] = [
hostname: 'test-bucket-002.alpha.linodeobjects.com',
label: 'test-bucket-002',
objects: 4,
region: 'us-east',
size: 1240,
},
];
3 changes: 3 additions & 0 deletions packages/manager/src/__data__/objectStorageKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const objectStorageKey1: ObjectStorageKey = {
id: 1,
label: 'test-obj-storage-key-01',
limited: false,
regions: [{ id: 'us-east', s3_endpoint: 'us-east.com' }],
secret_key: '[REDACTED]',
};

Expand All @@ -15,6 +16,7 @@ export const objectStorageKey2: ObjectStorageKey = {
id: 2,
label: 'test-obj-storage-key-02',
limited: false,
regions: [{ id: 'us-east', s3_endpoint: 'us-east.com' }],
secret_key: '[REDACTED]',
};

Expand All @@ -24,6 +26,7 @@ export const objectStorageKey3: ObjectStorageKey = {
id: 3,
label: 'test-obj-storage-key-03',
limited: false,
regions: [{ id: 'us-east', s3_endpoint: 'us-east.com' }],
secret_key: '[REDACTED]',
};

Expand Down
1 change: 1 addition & 0 deletions packages/manager/src/factories/objectStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const objectStorageKeyFactory = Factory.Sync.makeFactory<ObjectStorageKey
id: Factory.each((id) => id),
label: Factory.each((id) => `access-key-${id}`),
limited: false,
regions: [{ id: 'us-east', s3_endpoint: 'us-east.com' }],
secret_key: 'PYiAB02QRb53JeUge872CM6wEvBUyRhl3vHn31Ol',
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('AccessKeyDrawer', () => {
bucket_name: bucket.label,
cluster: bucket.cluster,
permissions: 'none',
region: 'us-east',
});
});

Expand All @@ -62,15 +63,21 @@ describe('AccessKeyDrawer', () => {
const mockScopes = getDefaultScopes(mockBuckets);

it('should update the correct scope', () => {
const newScope = { ...mockScopes[2], permissions: 'read_write' } as Scope;
const newScope = {
...mockScopes[2],
permissions: 'read_write',
} as Scope;
expect(getUpdatedScopes(mockScopes, newScope)[2]).toHaveProperty(
'permissions',
'read_write'
);
});

it('should leave other scopes unchanged', () => {
const newScope = { ...mockScopes[2], access: 'read_write' } as Scope;
const newScope = {
...mockScopes[2],
access: 'read_write',
} as Scope;
const updatedScopes = getUpdatedScopes(mockScopes, newScope);
expect(updatedScopes[0]).toEqual(mockScopes[0]);
expect(updatedScopes[1]).toEqual(mockScopes[1]);
Expand All @@ -82,6 +89,7 @@ describe('AccessKeyDrawer', () => {
bucket_name: 'not-real',
cluster: 'totally-fake',
permissions: 'read_only',
region: 'us-east',
} as Scope;
expect(getUpdatedScopes(mockScopes, newScope)).toEqual(mockScopes);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const getDefaultScopes = (buckets: ObjectStorageBucket[]): Scope[] =>
bucket_name: thisBucket.label,
cluster: thisBucket.cluster,
permissions: 'none' as AccessType,
region: thisBucket.region ?? '',
}))
.sort(sortByCluster);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('BucketTableRow', () => {
objects: bucket.objects,
onDetails: vi.fn(),
onRemove: mockOnRemove,
region: bucket.region,
size: bucket.size,
};

Expand Down

0 comments on commit 5473231

Please sign in to comment.