src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

api_op_GetMetadata.go (2036B)


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