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