feat: CORS enable button...ish still now understanding this
This commit is contained in:
@@ -5,6 +5,7 @@ import type {
|
||||
CloudServiceType,
|
||||
CreateDatabaseSnapshotInput,
|
||||
KmsEncryptionAlgorithm,
|
||||
S3BucketWebsiteConfiguration,
|
||||
SqlConnectionInput,
|
||||
} from '../cloud-spi/types'
|
||||
import {clampLimit, type PageQuery} from '../cloud-spi/childCollections'
|
||||
@@ -554,6 +555,22 @@ export function createCloudRoutes(injectedService?: CloudProxyService) {
|
||||
})
|
||||
})
|
||||
|
||||
app.post('/:cloud/services/apigateway/resources/:id/cors', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
return withRuntime(c, async () => {
|
||||
const input = await c.req.json<Record<string, unknown>>()
|
||||
const result = await svc(c).enableApiGatewayCors(cloud, c.req.param('id'), {
|
||||
resourceId: typeof input.resourceId === 'string' ? input.resourceId : '',
|
||||
stage: typeof input.stage === 'string' ? input.stage : '',
|
||||
origin: typeof input.origin === 'string' ? input.origin : '',
|
||||
headers: typeof input.headers === 'string' ? input.headers : '',
|
||||
methods: Array.isArray(input.methods) ? input.methods.filter((method): method is string => typeof method === 'string') : [],
|
||||
})
|
||||
return c.json(result)
|
||||
})
|
||||
})
|
||||
|
||||
app.post('/:cloud/services/apigateway/resources/:id/routes/test', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
@@ -602,6 +619,32 @@ export function createCloudRoutes(injectedService?: CloudProxyService) {
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/:cloud/services/storage/resources/:id/website', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
return withRuntime(c, async () => c.json(await svc(c).getS3BucketWebsite(cloud, c.req.param('id'))))
|
||||
})
|
||||
|
||||
app.put('/:cloud/services/storage/resources/:id/website', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
return withRuntime(c, async () => {
|
||||
const input = await jsonBody<{mode?: unknown; indexDocument?: unknown; errorDocument?: unknown; hostName?: unknown; protocol?: unknown}>(c)
|
||||
const configuration = s3WebsiteConfiguration(input)
|
||||
await svc(c).putS3BucketWebsite(cloud, c.req.param('id'), configuration)
|
||||
return c.json({ok: true})
|
||||
})
|
||||
})
|
||||
|
||||
app.delete('/:cloud/services/storage/resources/:id/website', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
return withRuntime(c, async () => {
|
||||
await svc(c).deleteS3BucketWebsite(cloud, c.req.param('id'))
|
||||
return c.json({ok: true})
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/:cloud/services/serverless/resources/:id/eventbridge-triggers', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
@@ -1052,6 +1095,36 @@ function isCloudProvider(value: string): value is CloudProvider {
|
||||
return value === 'aws' || value === 'azure' || value === 'gcp'
|
||||
}
|
||||
|
||||
function s3WebsiteConfiguration(input: {mode?: unknown; indexDocument?: unknown; errorDocument?: unknown; hostName?: unknown; protocol?: unknown}): S3BucketWebsiteConfiguration {
|
||||
if (input.mode === 'index') {
|
||||
if (typeof input.indexDocument !== 'string' || !input.indexDocument.trim()) {
|
||||
throw new ValidationError('indexDocument is required for index website hosting')
|
||||
}
|
||||
if (input.errorDocument !== undefined && typeof input.errorDocument !== 'string' && input.errorDocument !== null) {
|
||||
throw new ValidationError('errorDocument must be a string or null')
|
||||
}
|
||||
return {
|
||||
mode: 'index',
|
||||
indexDocument: input.indexDocument.trim(),
|
||||
errorDocument: typeof input.errorDocument === 'string' && input.errorDocument.trim() ? input.errorDocument.trim() : null,
|
||||
}
|
||||
}
|
||||
if (input.mode === 'redirect') {
|
||||
if (typeof input.hostName !== 'string' || !input.hostName.trim()) {
|
||||
throw new ValidationError('hostName is required for redirect website hosting')
|
||||
}
|
||||
if (input.protocol !== undefined && input.protocol !== null && input.protocol !== 'http' && input.protocol !== 'https') {
|
||||
throw new ValidationError('protocol must be http, https, or null')
|
||||
}
|
||||
return {
|
||||
mode: 'redirect',
|
||||
hostName: input.hostName.trim(),
|
||||
protocol: input.protocol === 'http' || input.protocol === 'https' ? input.protocol : null,
|
||||
}
|
||||
}
|
||||
throw new ValidationError('mode must be index or redirect')
|
||||
}
|
||||
|
||||
async function jsonBody<T>(c: Context): Promise<T> {
|
||||
try {
|
||||
const body = await c.req.json<unknown>()
|
||||
|
||||
Reference in New Issue
Block a user