MCPcopy Index your code
hub / github.com/coder/coder / postAWSInstanceIdentity

Function postAWSInstanceIdentity

coderd/workspaceresourceauth_test.go:455–481  ·  view source on GitHub ↗
(
	ctx context.Context,
	t testing.TB,
	client *codersdk.Client,
	metadataClient *http.Client,
	agentName string,
)

Source from the content-addressed store, hash-verified

453const awsInstanceIdentityMetadataURL = "http://169.254.169.254/latest/dynamic/instance-identity"
454
455func postAWSInstanceIdentity(
456 ctx context.Context,
457 t testing.TB,
458 client *codersdk.Client,
459 metadataClient *http.Client,
460 agentName string,
461) *http.Response {
462 t.Helper()
463
464 signature := readAWSInstanceMetadata(ctx, t, metadataClient, "signature")
465 document := readAWSInstanceMetadata(ctx, t, metadataClient, "document")
466 reqBody, err := json.Marshal(map[string]string{
467 "signature": signature,
468 "document": document,
469 "agent_name": agentName,
470 })
471 require.NoError(t, err)
472
473 res, err := client.RequestWithoutSessionToken(
474 ctx,
475 http.MethodPost,
476 "/api/v2/workspaceagents/aws-instance-identity",
477 reqBody,
478 )
479 require.NoError(t, err)
480 return res
481}
482
483func readAWSInstanceMetadata(
484 ctx context.Context,

Calls 4

readAWSInstanceMetadataFunction · 0.85
HelperMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected