api_op_GetInstanceIdentityDocument.go (3558B)
1 package imds 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 "io" 8 "time" 9 10 "github.com/aws/smithy-go" 11 smithyio "github.com/aws/smithy-go/io" 12 "github.com/aws/smithy-go/middleware" 13 smithyhttp "github.com/aws/smithy-go/transport/http" 14 ) 15 16 const getInstanceIdentityDocumentPath = getDynamicDataPath + "/instance-identity/document" 17 18 // GetInstanceIdentityDocument retrieves an identity document describing an 19 // instance. Error is returned if the request fails or is unable to parse 20 // the response. 21 func (c *Client) GetInstanceIdentityDocument( 22 ctx context.Context, params *GetInstanceIdentityDocumentInput, optFns ...func(*Options), 23 ) ( 24 *GetInstanceIdentityDocumentOutput, error, 25 ) { 26 if params == nil { 27 params = &GetInstanceIdentityDocumentInput{} 28 } 29 30 result, metadata, err := c.invokeOperation(ctx, "GetInstanceIdentityDocument", params, optFns, 31 addGetInstanceIdentityDocumentMiddleware, 32 ) 33 if err != nil { 34 return nil, err 35 } 36 37 out := result.(*GetInstanceIdentityDocumentOutput) 38 out.ResultMetadata = metadata 39 return out, nil 40 } 41 42 // GetInstanceIdentityDocumentInput provides the input parameters for 43 // GetInstanceIdentityDocument operation. 44 type GetInstanceIdentityDocumentInput struct{} 45 46 // GetInstanceIdentityDocumentOutput provides the output parameters for 47 // GetInstanceIdentityDocument operation. 48 type GetInstanceIdentityDocumentOutput struct { 49 InstanceIdentityDocument 50 51 ResultMetadata middleware.Metadata 52 } 53 54 func addGetInstanceIdentityDocumentMiddleware(stack *middleware.Stack, options Options) error { 55 return addAPIRequestMiddleware(stack, 56 options, 57 "GetInstanceIdentityDocument", 58 buildGetInstanceIdentityDocumentPath, 59 buildGetInstanceIdentityDocumentOutput, 60 ) 61 } 62 63 func buildGetInstanceIdentityDocumentPath(params interface{}) (string, error) { 64 return getInstanceIdentityDocumentPath, nil 65 } 66 67 func buildGetInstanceIdentityDocumentOutput(resp *smithyhttp.Response) (v interface{}, err error) { 68 defer func() { 69 closeErr := resp.Body.Close() 70 if err == nil { 71 err = closeErr 72 } else if closeErr != nil { 73 err = fmt.Errorf("response body close error: %v, original error: %w", closeErr, err) 74 } 75 }() 76 77 var buff [1024]byte 78 ringBuffer := smithyio.NewRingBuffer(buff[:]) 79 body := io.TeeReader(resp.Body, ringBuffer) 80 81 output := &GetInstanceIdentityDocumentOutput{} 82 if err = json.NewDecoder(body).Decode(&output.InstanceIdentityDocument); err != nil { 83 return nil, &smithy.DeserializationError{ 84 Err: fmt.Errorf("failed to decode instance identity document, %w", err), 85 Snapshot: ringBuffer.Bytes(), 86 } 87 } 88 89 return output, nil 90 } 91 92 // InstanceIdentityDocument provides the shape for unmarshaling 93 // an instance identity document 94 type InstanceIdentityDocument struct { 95 DevpayProductCodes []string `json:"devpayProductCodes"` 96 MarketplaceProductCodes []string `json:"marketplaceProductCodes"` 97 AvailabilityZone string `json:"availabilityZone"` 98 PrivateIP string `json:"privateIp"` 99 Version string `json:"version"` 100 Region string `json:"region"` 101 InstanceID string `json:"instanceId"` 102 BillingProducts []string `json:"billingProducts"` 103 InstanceType string `json:"instanceType"` 104 AccountID string `json:"accountId"` 105 PendingTime time.Time `json:"pendingTime"` 106 ImageID string `json:"imageId"` 107 KernelID string `json:"kernelId"` 108 RamdiskID string `json:"ramdiskId"` 109 Architecture string `json:"architecture"` 110 }