( ctx context.Context, t testing.TB, client *codersdk.Client, metadataClient *http.Client, agentName string, )
| 453 | const awsInstanceIdentityMetadataURL = "http://169.254.169.254/latest/dynamic/instance-identity" |
| 454 | |
| 455 | func 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 | |
| 483 | func readAWSInstanceMetadata( |
| 484 | ctx context.Context, |
no test coverage detected