Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 82 additions & 1 deletion src/core/gateway.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
ListGatewayRulesCommand,
ListGatewaysCommand,
ListGatewayTargetsCommand,
UpdateGatewayCommand,
UpdateGatewayRuleCommand,
UpdateGatewayTargetCommand,
type BedrockAgentCoreControlClient,
type CreateGatewayResponse,
type CreateGatewayRuleResponse,
Expand All @@ -20,9 +23,15 @@ import {
type ListGatewayRulesResponse,
type ListGatewaysResponse,
type ListGatewayTargetsResponse,
type UpdateGatewayResponse,
type UpdateGatewayRuleResponse,
type UpdateGatewayTargetResponse,
} from "@aws-sdk/client-bedrock-agentcore-control";
import {
buildGatewayCreateRequest,
buildGatewayUpdateRequest,
buildRuleUpdateRequest,
buildTargetUpdateRequest,
validateGatewayCreateInput,
validateGatewayTargetCreateInput,
} from "../handlers/gateway/mutations";
Expand All @@ -31,15 +40,19 @@ import type {
CreateGatewayInput,
CreateGatewayRuleInput,
CreateGatewayTargetInput,
GatewayRuleUpdatePatch,
GatewayTargetUpdatePatch,
GatewayUpdatePatch,
} from "../handlers/gateway/types";
import type { AwsClients, CoreOptions } from "./types";
import {
ensureGatewayExecutionRole,
getManagedGatewayTargetExecutionRole,
prepareGatewayExecutionRoleUpdate,
retryWhileGatewayRoleChangesPropagate,
type GatewayTargetExecutionRole,
type GatewayTargetRoleConfiguration,
} from "./gatewayExecutionRole";
import type { AwsClients, CoreOptions } from "./types";
import { toClientConfig } from "./utils";

export class GatewayClient implements CoreGatewayClient {
Expand Down Expand Up @@ -91,6 +104,29 @@ export class GatewayClient implements CoreGatewayClient {
.send(new ListGatewaysCommand({ nextToken, maxResults }));
}

async updateGateway(
patch: GatewayUpdatePatch,
options: CoreOptions,
): Promise<UpdateGatewayResponse> {
const control = this.clients.control(toClientConfig(options));
const current = await control.send(new GetGatewayCommand({ gatewayIdentifier: patch.id }));
const request = buildGatewayUpdateRequest(current, patch);
const finalizeRole =
patch.roleArn === undefined && current.roleArn && current.name
? await prepareGatewayExecutionRoleUpdate(
this.clients.iam({ region: options.region }),
current.roleArn,
current.name,
options.region,
request,
current.gatewayArn,
)
: undefined;
const response = await control.send(new UpdateGatewayCommand(request));
await finalizeRole?.();
return response;
}

async getGatewayTarget(
gatewayId: string,
targetId: string,
Expand Down Expand Up @@ -153,6 +189,42 @@ export class GatewayClient implements CoreGatewayClient {
}
}

async updateGatewayTarget(
patch: GatewayTargetUpdatePatch,
options: CoreOptions,
): Promise<UpdateGatewayTargetResponse> {
const control = this.clients.control(toClientConfig(options));
const current = await control.send(
new GetGatewayTargetCommand({
gatewayIdentifier: patch.gatewayId,
targetId: patch.targetId,
}),
);
const request = buildTargetUpdateRequest(current, patch);
const gateway = await control.send(
new GetGatewayCommand({ gatewayIdentifier: patch.gatewayId }),
);
const role = await getManagedGatewayTargetExecutionRole(
this.clients.iam({ region: options.region }),
gateway,
options.region,
);
if (!role) {
return control.send(new UpdateGatewayTargetCommand(request));
}

await role.prepare(
await listTargetRoleConfigurations(control, patch.gatewayId, patch.targetId, request),
);
const response = await retryWhileGatewayRoleChangesPropagate(() =>
control.send(new UpdateGatewayTargetCommand(request)),
);
await role.finalize(
await listTargetRoleConfigurations(control, patch.gatewayId, patch.targetId, request),
);
return response;
}

async getGatewayRule(
gatewayId: string,
ruleId: string,
Expand Down Expand Up @@ -187,6 +259,15 @@ export class GatewayClient implements CoreGatewayClient {
): Promise<CreateGatewayRuleResponse> {
return this.clients.control(toClientConfig(options)).send(new CreateGatewayRuleCommand(input));
}

async updateGatewayRule(
patch: GatewayRuleUpdatePatch,
options: CoreOptions,
): Promise<UpdateGatewayRuleResponse> {
return this.clients
.control(toClientConfig(options))
.send(new UpdateGatewayRuleCommand(buildRuleUpdateRequest(patch)));
}
}

async function rollbackTargetRole(
Expand Down
Loading
Loading