1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package pricing
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/pricing/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns a list of attribute values. Attibutes are similar to the details in a
16// Price List API offer file. For a list of available attributes, see Offer File
17// Definitions
18// (https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/reading-an-offer.html#pps-defs)
19// in the AWS Billing and Cost Management User Guide
20// (https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/billing-what-is.html).
21func (c *Client) GetAttributeValues(ctx context.Context, params *GetAttributeValuesInput, optFns ...func(*Options)) (*GetAttributeValuesOutput, error) {
22	if params == nil {
23		params = &GetAttributeValuesInput{}
24	}
25
26	result, metadata, err := c.invokeOperation(ctx, "GetAttributeValues", params, optFns, addOperationGetAttributeValuesMiddlewares)
27	if err != nil {
28		return nil, err
29	}
30
31	out := result.(*GetAttributeValuesOutput)
32	out.ResultMetadata = metadata
33	return out, nil
34}
35
36type GetAttributeValuesInput struct {
37
38	// The name of the attribute that you want to retrieve the values for, such as
39	// volumeType.
40	//
41	// This member is required.
42	AttributeName *string
43
44	// The service code for the service whose attributes you want to retrieve. For
45	// example, if you want the retrieve an EC2 attribute, use AmazonEC2.
46	//
47	// This member is required.
48	ServiceCode *string
49
50	// The maximum number of results to return in response.
51	MaxResults int32
52
53	// The pagination token that indicates the next set of results that you want to
54	// retrieve.
55	NextToken *string
56}
57
58type GetAttributeValuesOutput struct {
59
60	// The list of values for an attribute. For example, Throughput Optimized HDD and
61	// Provisioned IOPS are two available values for the AmazonEC2volumeType.
62	AttributeValues []types.AttributeValue
63
64	// The pagination token that indicates the next set of results to retrieve.
65	NextToken *string
66
67	// Metadata pertaining to the operation's result.
68	ResultMetadata middleware.Metadata
69}
70
71func addOperationGetAttributeValuesMiddlewares(stack *middleware.Stack, options Options) (err error) {
72	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetAttributeValues{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetAttributeValues{}, middleware.After)
77	if err != nil {
78		return err
79	}
80	if err = addSetLoggerMiddleware(stack, options); err != nil {
81		return err
82	}
83	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
84		return err
85	}
86	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
87		return err
88	}
89	if err = addResolveEndpointMiddleware(stack, options); err != nil {
90		return err
91	}
92	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
93		return err
94	}
95	if err = addRetryMiddlewares(stack, options); err != nil {
96		return err
97	}
98	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
99		return err
100	}
101	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
105		return err
106	}
107	if err = addClientUserAgent(stack); err != nil {
108		return err
109	}
110	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
111		return err
112	}
113	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
114		return err
115	}
116	if err = addOpGetAttributeValuesValidationMiddleware(stack); err != nil {
117		return err
118	}
119	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetAttributeValues(options.Region), middleware.Before); err != nil {
120		return err
121	}
122	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addResponseErrorMiddleware(stack); err != nil {
126		return err
127	}
128	if err = addRequestResponseLogging(stack, options); err != nil {
129		return err
130	}
131	return nil
132}
133
134// GetAttributeValuesAPIClient is a client that implements the GetAttributeValues
135// operation.
136type GetAttributeValuesAPIClient interface {
137	GetAttributeValues(context.Context, *GetAttributeValuesInput, ...func(*Options)) (*GetAttributeValuesOutput, error)
138}
139
140var _ GetAttributeValuesAPIClient = (*Client)(nil)
141
142// GetAttributeValuesPaginatorOptions is the paginator options for
143// GetAttributeValues
144type GetAttributeValuesPaginatorOptions struct {
145	// The maximum number of results to return in response.
146	Limit int32
147
148	// Set to true if pagination should stop if the service returns a pagination token
149	// that matches the most recent token provided to the service.
150	StopOnDuplicateToken bool
151}
152
153// GetAttributeValuesPaginator is a paginator for GetAttributeValues
154type GetAttributeValuesPaginator struct {
155	options   GetAttributeValuesPaginatorOptions
156	client    GetAttributeValuesAPIClient
157	params    *GetAttributeValuesInput
158	nextToken *string
159	firstPage bool
160}
161
162// NewGetAttributeValuesPaginator returns a new GetAttributeValuesPaginator
163func NewGetAttributeValuesPaginator(client GetAttributeValuesAPIClient, params *GetAttributeValuesInput, optFns ...func(*GetAttributeValuesPaginatorOptions)) *GetAttributeValuesPaginator {
164	if params == nil {
165		params = &GetAttributeValuesInput{}
166	}
167
168	options := GetAttributeValuesPaginatorOptions{}
169	if params.MaxResults != 0 {
170		options.Limit = params.MaxResults
171	}
172
173	for _, fn := range optFns {
174		fn(&options)
175	}
176
177	return &GetAttributeValuesPaginator{
178		options:   options,
179		client:    client,
180		params:    params,
181		firstPage: true,
182	}
183}
184
185// HasMorePages returns a boolean indicating whether more pages are available
186func (p *GetAttributeValuesPaginator) HasMorePages() bool {
187	return p.firstPage || p.nextToken != nil
188}
189
190// NextPage retrieves the next GetAttributeValues page.
191func (p *GetAttributeValuesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetAttributeValuesOutput, error) {
192	if !p.HasMorePages() {
193		return nil, fmt.Errorf("no more pages available")
194	}
195
196	params := *p.params
197	params.NextToken = p.nextToken
198
199	params.MaxResults = p.options.Limit
200
201	result, err := p.client.GetAttributeValues(ctx, &params, optFns...)
202	if err != nil {
203		return nil, err
204	}
205	p.firstPage = false
206
207	prevToken := p.nextToken
208	p.nextToken = result.NextToken
209
210	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
211		p.nextToken = nil
212	}
213
214	return result, nil
215}
216
217func newServiceMetadataMiddleware_opGetAttributeValues(region string) *awsmiddleware.RegisterServiceMetadata {
218	return &awsmiddleware.RegisterServiceMetadata{
219		Region:        region,
220		ServiceID:     ServiceID,
221		SigningName:   "pricing",
222		OperationName: "GetAttributeValues",
223	}
224}
225