Skip to content
Merged
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
8 changes: 7 additions & 1 deletion internal/awsdevops/awsdevops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type fakeAgent struct {
tagsErr error
// tagsErrFor fails the tag lookup of one resource ARN.
tagsErrFor map[string]error
// spaceLinks holds associations by space ID.
spaceLinks map[string][]agenttypes.Association
// operatorApps holds enabled apps by space.
operatorApps map[string]*devopsagent.GetOperatorAppOutput
// operatorAppErr fails every GetOperatorApp call.
Expand Down Expand Up @@ -177,7 +179,11 @@ func (f *fakeAgent) ListServices(_ context.Context, in *devopsagent.ListServices
}

func (f *fakeAgent) ListAssociations(_ context.Context, in *devopsagent.ListAssociationsInput, _ ...func(*devopsagent.Options)) (*devopsagent.ListAssociationsOutput, error) {
items, next := page(f.associations, in.NextToken, f.paginate)
links := f.associations
if f.spaceLinks != nil {
links = f.spaceLinks[aws.ToString(in.AgentSpaceId)]
}
items, next := page(links, in.NextToken, f.paginate)

return &devopsagent.ListAssociationsOutput{Associations: items, NextToken: next}, nil
}
Expand Down
34 changes: 31 additions & 3 deletions internal/awsdevops/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,25 @@ func agentSpaceARN(region, accountID, spaceID string) string {
// account has one. AWS keeps MCP servers at the account level, so a second
// agent space reuses the existing registration.
func FindMCPServer(ctx context.Context, clients Clients, endpoint string) (string, error) {
id, _, err := findMCPService(ctx, clients, endpoint)

return id, err
}

// findMCPService returns the ID and the name of the MCP server registered at
// endpoint, if the account has one.
func findMCPService(ctx context.Context, clients Clients, endpoint string) (id, name string, err error) {
services, err := listServices(ctx, clients)
if err != nil {
return "", err
return "", "", err
}
for _, service := range services {
if mcpEndpointOf(service) == endpoint {
return aws.ToString(service.ServiceId), nil
return aws.ToString(service.ServiceId), serviceName(service), nil
}
}

return "", nil
return "", "", nil
}

// FindAgentSpace returns the ID of the agent space with the given name, or an
Expand All @@ -209,6 +217,26 @@ func FindAgentSpace(ctx context.Context, clients Clients, name string) (string,
return "", nil
}

// spacesNamed lists IDs of spaces named name.
func spacesNamed(ctx context.Context, clients Clients, name string) ([]string, error) {
// An empty name names no space, even a space without a name.
if name == "" {
return nil, nil
}
spaces, err := listAgentSpaces(ctx, clients)
if err != nil {
return nil, err
}
var ids []string
for _, space := range spaces {
if strings.EqualFold(aws.ToString(space.Name), name) {
ids = append(ids, aws.ToString(space.AgentSpaceId))
}
}

return ids, nil
}

// FindAssociation returns the ID of an existing association between an agent
// space and a service, so setup can be re-run without AWS rejecting duplicates.
func FindAssociation(ctx context.Context, clients Clients, agentSpaceID, serviceID string) (string, error) {
Expand Down
Loading
Loading