api_op_GetDynamicData.go (2128B)
1 package imds 2 3 import ( 4 "context" 5 "fmt" 6 "io" 7 8 "github.com/aws/smithy-go/middleware" 9 smithyhttp "github.com/aws/smithy-go/transport/http" 10 ) 11 12 const getDynamicDataPath = "/latest/dynamic" 13 14 // GetDynamicData uses the path provided to request information from the EC2 15 // instance metadata service for dynamic data. The content will be returned 16 // as a string, or error if the request failed. 17 func (c *Client) GetDynamicData(ctx context.Context, params *GetDynamicDataInput, optFns ...func(*Options)) (*GetDynamicDataOutput, error) { 18 if params == nil { 19 params = &GetDynamicDataInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "GetDynamicData", params, optFns, 23 addGetDynamicDataMiddleware, 24 ) 25 if err != nil { 26 return nil, err 27 } 28 29 out := result.(*GetDynamicDataOutput) 30 out.ResultMetadata = metadata 31 return out, nil 32 } 33 34 // GetDynamicDataInput provides the input parameters for the GetDynamicData 35 // operation. 36 type GetDynamicDataInput struct { 37 // The relative dynamic data path to retrieve. Can be empty string to 38 // retrieve a response containing a new line separated list of dynamic data 39 // resources available. 40 // 41 // Must not include the dynamic data base path. 42 // 43 // May include leading slash. If Path includes trailing slash the trailing 44 // slash will be included in the request for the resource. 45 Path string 46 } 47 48 // GetDynamicDataOutput provides the output parameters for the GetDynamicData 49 // operation. 50 type GetDynamicDataOutput struct { 51 Content io.ReadCloser 52 53 ResultMetadata middleware.Metadata 54 } 55 56 func addGetDynamicDataMiddleware(stack *middleware.Stack, options Options) error { 57 return addAPIRequestMiddleware(stack, 58 options, 59 "GetDynamicData", 60 buildGetDynamicDataPath, 61 buildGetDynamicDataOutput) 62 } 63 64 func buildGetDynamicDataPath(params interface{}) (string, error) { 65 p, ok := params.(*GetDynamicDataInput) 66 if !ok { 67 return "", fmt.Errorf("unknown parameter type %T", params) 68 } 69 70 return appendURIPath(getDynamicDataPath, p.Path), nil 71 } 72 73 func buildGetDynamicDataOutput(resp *smithyhttp.Response) (interface{}, error) { 74 return &GetDynamicDataOutput{ 75 Content: resp.Body, 76 }, nil 77 }