Skip to content

Commit 3e33857

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
style(oci-compute): apply GitHub lint diagnostics
1 parent 272fd9a commit 3e33857

19 files changed

Lines changed: 924 additions & 260 deletions

apps/sim/blocks/blocks/oci_compute.ts

Lines changed: 797 additions & 175 deletions
Large diffs are not rendered by default.

apps/sim/lib/internal/oci-compute/operations.ts

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,13 @@ export async function executeOciComputeOperation(
683683
(values.metadata !== undefined || values.extendedMetadata !== undefined)
684684
) {
685685
const current = await client.request({
686-
endpoint, method: 'GET', encodedPath: `/20160918/instances/${encodeURIComponent(String(values.instanceId))}`,
687-
timeoutMs: 30_000, maxResponseBytes: 2_000_000, signal, retry: { kind: 'safe', maxAttempts: 2 },
686+
endpoint,
687+
method: 'GET',
688+
encodedPath: `/20160918/instances/${encodeURIComponent(String(values.instanceId))}`,
689+
timeoutMs: 30_000,
690+
maxResponseBytes: 2_000_000,
691+
signal,
692+
retry: { kind: 'safe', maxAttempts: 2 },
688693
})
689694
const existing = parseResource(current.body)
690695
if (!isPlainRecord(existing)) throw new Error('OCI returned an invalid instance')
@@ -693,48 +698,65 @@ export async function executeOciComputeOperation(
693698
const before = isPlainRecord(existing[field]) ? existing[field] : {}
694699
const after = isPlainRecord(values[field]) ? values[field] : {}
695700
for (const key of ['user_data', 'ssh_authorized_keys']) {
696-
if (JSON.stringify(before[key]) !== JSON.stringify(after[key])) throw new Error(`Updating ${field} must preserve existing user_data and ssh_authorized_keys`)
701+
if (JSON.stringify(before[key]) !== JSON.stringify(after[key]))
702+
throw new Error(
703+
`Updating ${field} must preserve existing user_data and ssh_authorized_keys`
704+
)
697705
}
698706
}
699707
validateOciComputeMetadata({
700708
metadata: values.metadata ?? existing.metadata,
701709
extendedMetadata: values.extendedMetadata ?? existing.extendedMetadata,
702710
})
703711
if (!headers['if-match']) {
704-
if (!current.headers.etag) throw new Error('OCI did not return an ETag for the metadata update')
712+
if (!current.headers.etag)
713+
throw new Error('OCI did not return an ETag for the metadata update')
705714
headers['if-match'] = current.headers.etag
706715
}
707716
}
708717
const path = definition.path.replace(/\{(\w+)\}/g, (_match, key: string) => {
709-
const value = operation === 'instance_pool_action' && key === 'action'
710-
? String(values[key]).toLowerCase()
711-
: String(values[key])
718+
const value =
719+
operation === 'instance_pool_action' && key === 'action'
720+
? String(values[key]).toLowerCase()
721+
: String(values[key])
712722
return encodeURIComponent(value)
713723
})
714724
const queryPairs: [string, string][] = []
715725
for (const key of definition.query ?? []) {
716726
if (values[key] !== undefined) queryPairs.push([key, String(values[key])])
717727
}
718728
const base = {
719-
endpoint, encodedPath: `/20160918${path}`, queryPairs, headers,
720-
timeoutMs: 30_000, maxResponseBytes: 2_000_000, signal,
729+
endpoint,
730+
encodedPath: `/20160918${path}`,
731+
queryPairs,
732+
headers,
733+
timeoutMs: 30_000,
734+
maxResponseBytes: 2_000_000,
735+
signal,
721736
responseHeaders: [
722737
...(definition.query?.includes('page') ? ['opc-next-page'] : []),
723738
...(definition.work ? ['opc-work-request-id'] : []),
724739
...(definition.location ? ['location'] : []),
725740
],
726741
}
727742
const body = requestBody(operation, values, definition)
728-
const request: OciRequest = definition.method === 'GET'
729-
? { ...base, method: 'GET', retry: { kind: 'safe', maxAttempts: 2 } }
730-
: definition.method === 'DELETE'
731-
? { ...base, method: 'DELETE' }
732-
: {
733-
...base, method: definition.method as 'POST' | 'PUT',
734-
body: body === undefined ? new Uint8Array() : new TextEncoder().encode(JSON.stringify(body)),
735-
contentType: 'application/json',
736-
...(retryToken ? { retry: { kind: 'tokenized' as const, maxAttempts: 2, retryToken } } : {}),
737-
}
743+
const request: OciRequest =
744+
definition.method === 'GET'
745+
? { ...base, method: 'GET', retry: { kind: 'safe', maxAttempts: 2 } }
746+
: definition.method === 'DELETE'
747+
? { ...base, method: 'DELETE' }
748+
: {
749+
...base,
750+
method: definition.method as 'POST' | 'PUT',
751+
body:
752+
body === undefined
753+
? new Uint8Array()
754+
: new TextEncoder().encode(JSON.stringify(body)),
755+
contentType: 'application/json',
756+
...(retryToken
757+
? { retry: { kind: 'tokenized' as const, maxAttempts: 2, retryToken } }
758+
: {}),
759+
}
738760
signal?.throwIfAborted()
739761
dispatched = true
740762
const response = await client.request(request)
@@ -744,29 +766,37 @@ export async function executeOciComputeOperation(
744766
status: response.status,
745767
requestId: response.opcRequestId ?? response.headers['opc-request-id'] ?? null,
746768
etag: response.headers.etag ?? null,
747-
...(definition.query?.includes('page') ? { nextPage: response.headers['opc-next-page'] ?? null } : {}),
748-
...(definition.work ? { workRequestId: response.headers['opc-work-request-id'] ?? null } : {}),
769+
...(definition.query?.includes('page')
770+
? { nextPage: response.headers['opc-next-page'] ?? null }
771+
: {}),
772+
...(definition.work
773+
? { workRequestId: response.headers['opc-work-request-id'] ?? null }
774+
: {}),
749775
...(definition.location ? { location: response.headers.location ?? null } : {}),
750776
...(retryToken ? { retryToken } : {}),
751777
}
752778
if (definition.output && definition.projection) {
753779
const data = parseResource(response.body)
754-
if (definition.list && (!Array.isArray(data) || data.length > 100)) throw new Error('OCI returned an invalid or oversized resource page')
755-
const resource = definition.list && Array.isArray(data)
756-
? data.map((entry) => projectOciComputeResource(entry, definition.projection ?? {}))
757-
: projectOciComputeResource(data, definition.projection)
780+
if (definition.list && (!Array.isArray(data) || data.length > 100))
781+
throw new Error('OCI returned an invalid or oversized resource page')
782+
const resource =
783+
definition.list && Array.isArray(data)
784+
? data.map((entry) => projectOciComputeResource(entry, definition.projection ?? {}))
785+
: projectOciComputeResource(data, definition.projection)
758786
Object.assign(output, { [definition.output]: resource })
759787
}
760788
return { success: true, output }
761789
} catch (error) {
762790
const providerError = error instanceof OciClientError ? error : undefined
763-
const rejected = !dispatched || (providerError?.status !== undefined && providerError.status < 500)
791+
const rejected =
792+
!dispatched || (providerError?.status !== undefined && providerError.status < 500)
764793
return {
765794
success: false,
766795
retryable: definition.method === 'GET',
767-
error: providerError?.status === 412
768-
? 'The resource changed. Read its current state and ETag before submitting another update.'
769-
: getErrorMessage(error, 'OCI Compute operation failed'),
796+
error:
797+
providerError?.status === 412
798+
? 'The resource changed. Read its current state and ETag before submitting another update.'
799+
: getErrorMessage(error, 'OCI Compute operation failed'),
770800
output: {
771801
status: providerError?.status ?? receivedStatus ?? 0,
772802
requestId: providerError?.opcRequestId ?? receivedRequestId ?? null,

apps/sim/lib/internal/oci-compute/schema.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,40 @@ const placement = z
224224
})
225225
.strict()
226226

227-
const common = z.object({
228-
oauthCredential: id,
229-
region: name.refine((region) => OCI_REGION_IDS.includes(region), 'Unrecognized OCI region'),
230-
deliveryIdentity: z.object({ executionId: name, blockId: name, invocationId: name }).strict().optional(),
231-
}).strict()
232-
const paging = { limit: z.number().int().min(1).max(100).default(50), page: z.string().min(1).max(4096).optional() }
233-
const sorting = { sortBy: z.enum(['TIMECREATED', 'DISPLAYNAME']).optional(), sortOrder: z.enum(['ASC', 'DESC']).optional() }
227+
const common = z
228+
.object({
229+
oauthCredential: id,
230+
region: name.refine((region) => OCI_REGION_IDS.includes(region), 'Unrecognized OCI region'),
231+
deliveryIdentity: z
232+
.object({ executionId: name, blockId: name, invocationId: name })
233+
.strict()
234+
.optional(),
235+
})
236+
.strict()
237+
const paging = {
238+
limit: z.number().int().min(1).max(100).default(50),
239+
page: z.string().min(1).max(4096).optional(),
240+
}
241+
const sorting = {
242+
sortBy: z.enum(['TIMECREATED', 'DISPLAYNAME']).optional(),
243+
sortOrder: z.enum(['ASC', 'DESC']).optional(),
244+
}
234245
const listing = { compartmentId: id, ...paging }
235246
const namedListing = { ...listing, ...sorting, displayName: name.optional() }
236247
const match = { ifMatch: z.string().min(1).max(1024).optional() }
237-
const token = { retryToken: z.string().min(1).max(64).regex(/^[\x21-\x7e]+$/, 'Retry token must use printable ASCII').optional() }
238-
const resourceTags = { displayName: name.optional(), freeformTags: json(tags).optional(), definedTags: json(definedTags).optional() }
248+
const token = {
249+
retryToken: z
250+
.string()
251+
.min(1)
252+
.max(64)
253+
.regex(/^[\x21-\x7e]+$/, 'Retry token must use printable ASCII')
254+
.optional(),
255+
}
256+
const resourceTags = {
257+
displayName: name.optional(),
258+
freeformTags: json(tags).optional(),
259+
definedTags: json(definedTags).optional(),
260+
}
239261
const instance = { instanceId: id }
240262
const image = { imageId: id }
241263
const configuration = { instanceConfigurationId: id }
@@ -253,7 +275,12 @@ const source = {
253275

254276
/** Only documented fields belonging to the selected operation are accepted. */
255277
export const ociComputeSchemas = {
256-
list_instances: common.extend({ ...namedListing, availabilityDomain: name.optional(), lifecycleState: name.optional(), capacityReservationId: id.optional() }),
278+
list_instances: common.extend({
279+
...namedListing,
280+
availabilityDomain: name.optional(),
281+
lifecycleState: name.optional(),
282+
capacityReservationId: id.optional(),
283+
}),
257284
get_instance: common.extend(instance),
258285
launch_instance: common.extend({
259286
compartmentId: id, availabilityDomain: name, shape: name, ...source, ...resourceTags, ...token,

apps/sim/lib/selectors/server/providers/oci-compute.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,18 @@ describe('OCI Compute selectors', () => {
169169
nextPage: 'next',
170170
},
171171
})
172-
expect(await execute(args({
173-
selectorKey: 'oci_compute.subnets',
174-
context: { region: 'us-ashburn-1', compartmentId: 'compartment', availabilityDomain: 'selected' },
175-
}))).toEqual({ kind: 'list', items: [], nextCursor: 'next' })
172+
expect(
173+
await execute(
174+
args({
175+
selectorKey: 'oci_compute.subnets',
176+
context: {
177+
region: 'us-ashburn-1',
178+
compartmentId: 'compartment',
179+
availabilityDomain: 'selected',
180+
},
181+
})
182+
)
183+
).toEqual({ kind: 'list', items: [], nextCursor: 'next' })
176184
expect(mocks.execute.mock.calls[0][2]).not.toHaveProperty('availabilityDomain')
177185
})
178186

apps/sim/tools/oci_compute/attach_instance_pool_instance.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
type OciComputeAttachInstancePoolInstanceParams,
33
type OciComputeResponse,
4-
POOL_INSTANCE_OUTPUT_PROPERTIES,
54
ociComputeOperationInput,
5+
POOL_INSTANCE_OUTPUT_PROPERTIES,
66
} from '@/tools/oci_compute/types'
77
import type { InternalToolConfig } from '@/tools/types'
88

@@ -56,11 +56,7 @@ export const ociComputeAttachInstancePoolInstanceTool: InternalToolConfig<
5656
},
5757
operation: {
5858
input: (params) =>
59-
ociComputeOperationInput(params, [
60-
'instancePoolId',
61-
'instanceId',
62-
'retryToken',
63-
]),
59+
ociComputeOperationInput(params, ['instancePoolId', 'instanceId', 'retryToken']),
6460
},
6561
outputs: {
6662
status: { type: 'number', description: 'OCI HTTP response status' },

apps/sim/tools/oci_compute/change_image_compartment.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ export const ociComputeChangeImageCompartmentTool: InternalToolConfig<
6363
},
6464
operation: {
6565
input: (params) =>
66-
ociComputeOperationInput(params, [
67-
'imageId',
68-
'ifMatch',
69-
'compartmentId',
70-
'retryToken',
71-
]),
66+
ociComputeOperationInput(params, ['imageId', 'ifMatch', 'compartmentId', 'retryToken']),
7267
},
7368
outputs: {
7469
status: { type: 'number', description: 'OCI HTTP response status' },

apps/sim/tools/oci_compute/change_instance_compartment.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ export const ociComputeChangeInstanceCompartmentTool: InternalToolConfig<
6363
},
6464
operation: {
6565
input: (params) =>
66-
ociComputeOperationInput(params, [
67-
'instanceId',
68-
'ifMatch',
69-
'compartmentId',
70-
'retryToken',
71-
]),
66+
ociComputeOperationInput(params, ['instanceId', 'ifMatch', 'compartmentId', 'retryToken']),
7267
},
7368
outputs: {
7469
status: { type: 'number', description: 'OCI HTTP response status' },

apps/sim/tools/oci_compute/get_instance_pool_instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
type OciComputeGetInstancePoolInstanceParams,
33
type OciComputeResponse,
4-
POOL_INSTANCE_OUTPUT_PROPERTIES,
54
ociComputeOperationInput,
5+
POOL_INSTANCE_OUTPUT_PROPERTIES,
66
} from '@/tools/oci_compute/types'
77
import type { InternalToolConfig } from '@/tools/types'
88

apps/sim/tools/oci_compute/get_subnet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
type OciComputeGetSubnetParams,
33
type OciComputeResponse,
4-
SUBNET_OUTPUT_PROPERTIES,
54
ociComputeOperationInput,
5+
SUBNET_OUTPUT_PROPERTIES,
66
} from '@/tools/oci_compute/types'
77
import type { InternalToolConfig } from '@/tools/types'
88

apps/sim/tools/oci_compute/get_vnic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
type OciComputeGetVnicParams,
33
type OciComputeResponse,
4-
VNIC_OUTPUT_PROPERTIES,
54
ociComputeOperationInput,
5+
VNIC_OUTPUT_PROPERTIES,
66
} from '@/tools/oci_compute/types'
77
import type { InternalToolConfig } from '@/tools/types'
88

0 commit comments

Comments
 (0)