Migrate to Provisioning API nested root

This commit is contained in:
Ondrej Ezr 2023-08-10 17:05:57 +02:00 committed by Thomas Lavocat
parent f147d5f4fe
commit 1e37a6ece9
4 changed files with 360 additions and 181 deletions

View file

@ -111,7 +111,7 @@
"value": { "value": {
"amount": 1, "amount": 1,
"image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8", "image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8",
"launch_template_name": "", "launch_template_id": "",
"machine_type": "e2-micro", "machine_type": "e2-micro",
"name_pattern": "my-instance", "name_pattern": "my-instance",
"poweroff": false, "poweroff": false,
@ -134,7 +134,7 @@
"instance_id": "3003942005876582747" "instance_id": "3003942005876582747"
} }
], ],
"launch_template_name": "template-1", "launch_template_id": "4883371230199373111",
"machine_type": "e2-micro", "machine_type": "e2-micro",
"name_pattern": "my-instance", "name_pattern": "my-instance",
"poweroff": false, "poweroff": false,
@ -150,7 +150,7 @@
"gcp_operation_name": "operation-1686646674436-5fdff07e43209-66146b7e-f3f65ec5", "gcp_operation_name": "operation-1686646674436-5fdff07e43209-66146b7e-f3f65ec5",
"image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8", "image_id": "08a48fed-de87-40ab-a571-f64e30bd0aa8",
"instances": [], "instances": [],
"launch_template_name": "template-1", "launch_template_id": "4883371230199373111",
"machine_type": "e2-micro", "machine_type": "e2-micro",
"name_pattern": "my-instance", "name_pattern": "my-instance",
"poweroff": false, "poweroff": false,
@ -179,7 +179,8 @@
} }
}, },
"v1.GenericReservationResponsePayloadListExample": { "v1.GenericReservationResponsePayloadListExample": {
"value": [ "value": {
"data": [
{ {
"created_at": "2013-05-13T19:20:15Z", "created_at": "2013-05-13T19:20:15Z",
"error": "", "error": "",
@ -229,6 +230,7 @@
"success": false "success": false
} }
] ]
}
}, },
"v1.GenericReservationResponsePayloadPendingExample": { "v1.GenericReservationResponsePayloadPendingExample": {
"value": { "value": {
@ -267,7 +269,8 @@
} }
}, },
"v1.InstanceTypesAWSResponse": { "v1.InstanceTypesAWSResponse": {
"value": [ "value": {
"data": [
{ {
"arch": "x86_64", "arch": "x86_64",
"cores": 16, "cores": 16,
@ -278,9 +281,11 @@
"vcpus": 32 "vcpus": 32
} }
] ]
}
}, },
"v1.InstanceTypesAzureResponse": { "v1.InstanceTypesAzureResponse": {
"value": [ "value": {
"data": [
{ {
"arch": "x86_64", "arch": "x86_64",
"azure": { "azure": {
@ -295,9 +300,11 @@
"vcpus": 128 "vcpus": 128
} }
] ]
}
}, },
"v1.InstanceTypesGCPResponse": { "v1.InstanceTypesGCPResponse": {
"value": [ "value": {
"data": [
{ {
"arch": "x86_64", "arch": "x86_64",
"cores": 0, "cores": 0,
@ -308,14 +315,17 @@
"vcpus": 16 "vcpus": 16
} }
] ]
}
}, },
"v1.LaunchTemplateListResponse": { "v1.LaunchTemplateListResponse": {
"value": [ "value": {
"data": [
{ {
"id": "lt-9843797432897342", "id": "lt-9843797432897342",
"name": "XXL large backend API" "name": "XXL large backend API"
} }
] ]
}
}, },
"v1.NoopReservationResponsePayloadExample": { "v1.NoopReservationResponsePayloadExample": {
"value": { "value": {
@ -323,7 +333,8 @@
} }
}, },
"v1.PubkeyListResponseExample": { "v1.PubkeyListResponseExample": {
"value": [ "value": {
"data": [
{ {
"body": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEhnn80ZywmjeBFFOGm+cm+5HUwm62qTVnjKlOdYFLHN lzap", "body": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEhnn80ZywmjeBFFOGm+cm+5HUwm62qTVnjKlOdYFLHN lzap",
"fingerprint": "gL/y6MvNmJ8jDXtsL/oMmK8jUuIefN39BBuvYw/Rndk=", "fingerprint": "gL/y6MvNmJ8jDXtsL/oMmK8jUuIefN39BBuvYw/Rndk=",
@ -333,6 +344,7 @@
"type": "ssh-ed25519" "type": "ssh-ed25519"
} }
] ]
}
}, },
"v1.PubkeyRequestExample": { "v1.PubkeyRequestExample": {
"value": { "value": {
@ -351,7 +363,8 @@
} }
}, },
"v1.SourceListResponseExample": { "v1.SourceListResponseExample": {
"value": [ "value": {
"data": [
{ {
"id": "654321", "id": "654321",
"name": "My AWS account", "name": "My AWS account",
@ -365,6 +378,7 @@
"uid": "" "uid": ""
} }
] ]
}
}, },
"v1.SourceUploadInfoAWSResponse": { "v1.SourceUploadInfoAWSResponse": {
"value": { "value": {
@ -676,7 +690,7 @@
"image_id": { "image_id": {
"type": "string" "type": "string"
}, },
"launch_template_name": { "launch_template_id": {
"type": "string" "type": "string"
}, },
"machine_type": { "machine_type": {
@ -735,7 +749,7 @@
}, },
"type": "array" "type": "array"
}, },
"launch_template_name": { "launch_template_id": {
"type": "string" "type": "string"
}, },
"machine_type": { "machine_type": {
@ -764,7 +778,7 @@
}, },
"type": "object" "type": "object"
}, },
"v1.GenericReservationResponsePayload": { "v1.GenericReservationResponse": {
"properties": { "properties": {
"created_at": { "created_at": {
"format": "date-time", "format": "date-time",
@ -861,6 +875,184 @@
}, },
"type": "object" "type": "object"
}, },
"v1.ListGenericReservationResponse": {
"properties": {
"data": {
"items": {
"properties": {
"created_at": {
"format": "date-time",
"type": "string"
},
"error": {
"type": "string"
},
"finished_at": {
"format": "date-time",
"nullable": true,
"type": "string"
},
"id": {
"format": "int64",
"type": "integer"
},
"provider": {
"type": "integer"
},
"status": {
"type": "string"
},
"step": {
"format": "int32",
"type": "integer"
},
"step_titles": {
"items": {
"type": "string"
},
"type": "array"
},
"steps": {
"format": "int32",
"type": "integer"
},
"success": {
"nullable": true,
"type": "boolean"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListInstaceTypeResponse": {
"properties": {
"data": {
"items": {
"properties": {
"architecture": {
"type": "string"
},
"azure": {
"properties": {
"gen_v1": {
"type": "boolean"
},
"gen_v2": {
"type": "boolean"
}
},
"type": "object"
},
"cores": {
"format": "int32",
"type": "integer"
},
"memory_mib": {
"format": "int64",
"type": "integer"
},
"name": {
"type": "string"
},
"storage_gb": {
"format": "int64",
"type": "integer"
},
"supported": {
"type": "boolean"
},
"vcpus": {
"format": "int32",
"type": "integer"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListLaunchTemplateResponse": {
"properties": {
"data": {
"items": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListPubkeyResponse": {
"properties": {
"data": {
"items": {
"properties": {
"body": {
"type": "string"
},
"fingerprint": {
"type": "string"
},
"fingerprint_legacy": {
"type": "string"
},
"id": {
"format": "int64",
"type": "integer"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.ListSourceResponse": {
"properties": {
"data": {
"items": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"source_type_id": {
"type": "string"
},
"uid": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"v1.NoopReservationResponse": { "v1.NoopReservationResponse": {
"properties": { "properties": {
"reservation_id": { "reservation_id": {
@ -994,7 +1186,7 @@
"name": "GPL-3.0" "name": "GPL-3.0"
}, },
"title": "provisioning-api", "title": "provisioning-api",
"version": "1.2.0" "version": "1.4.0"
}, },
"openapi": "3.0.0", "openapi": "3.0.0",
"paths": { "paths": {
@ -1076,10 +1268,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListInstaceTypeResponse"
"$ref": "#/components/schemas/v1.InstanceTypeResponse"
},
"type": "array"
} }
} }
}, },
@ -1111,10 +1300,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListPubkeyResponse"
"$ref": "#/components/schemas/v1.PubkeyResponse"
},
"type": "array"
} }
} }
}, },
@ -1260,10 +1446,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListGenericReservationResponse"
"$ref": "#/components/schemas/v1.GenericReservationResponsePayload"
},
"type": "array"
} }
} }
}, },
@ -1587,7 +1770,7 @@
} }
}, },
"schema": { "schema": {
"$ref": "#/components/schemas/v1.GenericReservationResponsePayload" "$ref": "#/components/schemas/v1.GenericReservationResponse"
} }
} }
}, },
@ -1633,10 +1816,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListSourceResponse"
"$ref": "#/components/schemas/v1.SourceResponse"
},
"type": "array"
} }
} }
}, },
@ -1722,10 +1902,7 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListInstaceTypeResponse"
"$ref": "#/components/schemas/v1.InstanceTypeResponse"
},
"type": "array"
} }
} }
}, },
@ -1778,10 +1955,7 @@
} }
}, },
"schema": { "schema": {
"items": { "$ref": "#/components/schemas/v1.ListLaunchTemplateResponse"
"$ref": "#/components/schemas/v1.LaunchTemplatesResponse"
},
"type": "array"
} }
} }
}, },

View file

@ -1,5 +1,4 @@
import type { V1SourceResponse } from './provisioningApi'; import type { V1ListSourceResponse } from './provisioningApi';
export const extractProvisioningList = ( export const extractProvisioningList = (list: V1ListSourceResponse) =>
list: V1SourceResponse[] | { data: V1SourceResponse[] } list?.data;
) => (Array.isArray(list) ? list : list?.data);

View file

@ -18,7 +18,7 @@ const injectedRtkApi = api.injectEndpoints({
}); });
export { injectedRtkApi as provisioningApi }; export { injectedRtkApi as provisioningApi };
export type GetSourceListApiResponse = export type GetSourceListApiResponse =
/** status 200 Returned on success. */ V1SourceResponse[]; /** status 200 Returned on success. */ V1ListSourceResponse;
export type GetSourceListApiArg = { export type GetSourceListApiArg = {
provider?: "aws" | "azure" | "gcp"; provider?: "aws" | "azure" | "gcp";
}; };
@ -28,11 +28,13 @@ export type GetSourceUploadInfoApiArg = {
/** Source ID from Sources Database */ /** Source ID from Sources Database */
id: number; id: number;
}; };
export type V1SourceResponse = { export type V1ListSourceResponse = {
data?: {
id?: string; id?: string;
name?: string; name?: string;
source_type_id?: string; source_type_id?: string;
uid?: string; uid?: string;
}[];
}; };
export type V1ResponseError = { export type V1ResponseError = {
build_time?: string; build_time?: string;

View file

@ -7,7 +7,8 @@ export const mockSourcesByProvider = (
provider: string provider: string
): GetSourceListApiResponse => { ): GetSourceListApiResponse => {
const mockSources: { [key: string]: GetSourceListApiResponse } = { const mockSources: { [key: string]: GetSourceListApiResponse } = {
aws: [ aws: {
data: [
{ {
id: '123', id: '123',
name: 'my_source', name: 'my_source',
@ -15,7 +16,9 @@ export const mockSourcesByProvider = (
uid: 'de5e35d4-4c1f-49d7-9ef3-7d08e6b9c76a', uid: 'de5e35d4-4c1f-49d7-9ef3-7d08e6b9c76a',
}, },
], ],
azure: [ },
azure: {
data: [
{ {
id: '666', id: '666',
name: 'azureSource1', name: 'azureSource1',
@ -29,6 +32,7 @@ export const mockSourcesByProvider = (
uid: '73d5694c-7a28-417e-9fca-55840084f508', uid: '73d5694c-7a28-417e-9fca-55840084f508',
}, },
], ],
},
}; };
return mockSources[provider]; return mockSources[provider];
}; };