1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package gamelift
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/gamelift/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Retrieves all scaling policies applied to a fleet. To get a fleet's scaling
16// policies, specify the fleet ID. You can filter this request by policy status,
17// such as to retrieve only active scaling policies. Use the pagination parameters
18// to retrieve results as a set of sequential pages. If successful, set of
19// ScalingPolicy objects is returned for the fleet. A fleet may have all of its
20// scaling policies suspended (StopFleetActions). This operation does not affect
21// the status of the scaling policies, which remains ACTIVE. To see whether a
22// fleet's scaling policies are in force or suspended, call DescribeFleetAttributes
23// and check the stopped actions. Related actions DescribeFleetCapacity |
24// UpdateFleetCapacity | DescribeEC2InstanceLimits | PutScalingPolicy |
25// DescribeScalingPolicies | DeleteScalingPolicy | StopFleetActions |
26// StartFleetActions | All APIs by task
27// (https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets)
28func (c *Client) DescribeScalingPolicies(ctx context.Context, params *DescribeScalingPoliciesInput, optFns ...func(*Options)) (*DescribeScalingPoliciesOutput, error) {
29	if params == nil {
30		params = &DescribeScalingPoliciesInput{}
31	}
32
33	result, metadata, err := c.invokeOperation(ctx, "DescribeScalingPolicies", params, optFns, addOperationDescribeScalingPoliciesMiddlewares)
34	if err != nil {
35		return nil, err
36	}
37
38	out := result.(*DescribeScalingPoliciesOutput)
39	out.ResultMetadata = metadata
40	return out, nil
41}
42
43// Represents the input for a request operation.
44type DescribeScalingPoliciesInput struct {
45
46	// A unique identifier for the fleet to retrieve scaling policies for. You can use
47	// either the fleet ID or ARN value.
48	//
49	// This member is required.
50	FleetId *string
51
52	// The maximum number of results to return. Use this parameter with NextToken to
53	// get results as a set of sequential pages.
54	Limit *int32
55
56	// CONTENT TODO
57	Location *string
58
59	// A token that indicates the start of the next sequential page of results. Use the
60	// token that is returned with a previous call to this operation. To start at the
61	// beginning of the result set, do not specify a value.
62	NextToken *string
63
64	// Scaling policy status to filter results on. A scaling policy is only in force
65	// when in an ACTIVE status.
66	//
67	// * ACTIVE -- The scaling policy is currently in
68	// force.
69	//
70	// * UPDATEREQUESTED -- A request to update the scaling policy has been
71	// received.
72	//
73	// * UPDATING -- A change is being made to the scaling policy.
74	//
75	// *
76	// DELETEREQUESTED -- A request to delete the scaling policy has been received.
77	//
78	// *
79	// DELETING -- The scaling policy is being deleted.
80	//
81	// * DELETED -- The scaling
82	// policy has been deleted.
83	//
84	// * ERROR -- An error occurred in creating the policy.
85	// It should be removed and recreated.
86	StatusFilter types.ScalingStatusType
87}
88
89// Represents the returned data in response to a request operation.
90type DescribeScalingPoliciesOutput struct {
91
92	// A token that indicates where to resume retrieving results on the next call to
93	// this operation. If no token is returned, these results represent the end of the
94	// list.
95	NextToken *string
96
97	// A collection of objects containing the scaling policies matching the request.
98	ScalingPolicies []types.ScalingPolicy
99
100	// Metadata pertaining to the operation's result.
101	ResultMetadata middleware.Metadata
102}
103
104func addOperationDescribeScalingPoliciesMiddlewares(stack *middleware.Stack, options Options) (err error) {
105	err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeScalingPolicies{}, middleware.After)
106	if err != nil {
107		return err
108	}
109	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeScalingPolicies{}, middleware.After)
110	if err != nil {
111		return err
112	}
113	if err = addSetLoggerMiddleware(stack, options); err != nil {
114		return err
115	}
116	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
117		return err
118	}
119	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addResolveEndpointMiddleware(stack, options); err != nil {
123		return err
124	}
125	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
126		return err
127	}
128	if err = addRetryMiddlewares(stack, options); err != nil {
129		return err
130	}
131	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
132		return err
133	}
134	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
135		return err
136	}
137	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
138		return err
139	}
140	if err = addClientUserAgent(stack); err != nil {
141		return err
142	}
143	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
144		return err
145	}
146	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
147		return err
148	}
149	if err = addOpDescribeScalingPoliciesValidationMiddleware(stack); err != nil {
150		return err
151	}
152	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeScalingPolicies(options.Region), middleware.Before); err != nil {
153		return err
154	}
155	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
156		return err
157	}
158	if err = addResponseErrorMiddleware(stack); err != nil {
159		return err
160	}
161	if err = addRequestResponseLogging(stack, options); err != nil {
162		return err
163	}
164	return nil
165}
166
167// DescribeScalingPoliciesAPIClient is a client that implements the
168// DescribeScalingPolicies operation.
169type DescribeScalingPoliciesAPIClient interface {
170	DescribeScalingPolicies(context.Context, *DescribeScalingPoliciesInput, ...func(*Options)) (*DescribeScalingPoliciesOutput, error)
171}
172
173var _ DescribeScalingPoliciesAPIClient = (*Client)(nil)
174
175// DescribeScalingPoliciesPaginatorOptions is the paginator options for
176// DescribeScalingPolicies
177type DescribeScalingPoliciesPaginatorOptions struct {
178	// The maximum number of results to return. Use this parameter with NextToken to
179	// get results as a set of sequential pages.
180	Limit int32
181
182	// Set to true if pagination should stop if the service returns a pagination token
183	// that matches the most recent token provided to the service.
184	StopOnDuplicateToken bool
185}
186
187// DescribeScalingPoliciesPaginator is a paginator for DescribeScalingPolicies
188type DescribeScalingPoliciesPaginator struct {
189	options   DescribeScalingPoliciesPaginatorOptions
190	client    DescribeScalingPoliciesAPIClient
191	params    *DescribeScalingPoliciesInput
192	nextToken *string
193	firstPage bool
194}
195
196// NewDescribeScalingPoliciesPaginator returns a new
197// DescribeScalingPoliciesPaginator
198func NewDescribeScalingPoliciesPaginator(client DescribeScalingPoliciesAPIClient, params *DescribeScalingPoliciesInput, optFns ...func(*DescribeScalingPoliciesPaginatorOptions)) *DescribeScalingPoliciesPaginator {
199	if params == nil {
200		params = &DescribeScalingPoliciesInput{}
201	}
202
203	options := DescribeScalingPoliciesPaginatorOptions{}
204	if params.Limit != nil {
205		options.Limit = *params.Limit
206	}
207
208	for _, fn := range optFns {
209		fn(&options)
210	}
211
212	return &DescribeScalingPoliciesPaginator{
213		options:   options,
214		client:    client,
215		params:    params,
216		firstPage: true,
217	}
218}
219
220// HasMorePages returns a boolean indicating whether more pages are available
221func (p *DescribeScalingPoliciesPaginator) HasMorePages() bool {
222	return p.firstPage || p.nextToken != nil
223}
224
225// NextPage retrieves the next DescribeScalingPolicies page.
226func (p *DescribeScalingPoliciesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeScalingPoliciesOutput, error) {
227	if !p.HasMorePages() {
228		return nil, fmt.Errorf("no more pages available")
229	}
230
231	params := *p.params
232	params.NextToken = p.nextToken
233
234	var limit *int32
235	if p.options.Limit > 0 {
236		limit = &p.options.Limit
237	}
238	params.Limit = limit
239
240	result, err := p.client.DescribeScalingPolicies(ctx, &params, optFns...)
241	if err != nil {
242		return nil, err
243	}
244	p.firstPage = false
245
246	prevToken := p.nextToken
247	p.nextToken = result.NextToken
248
249	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
250		p.nextToken = nil
251	}
252
253	return result, nil
254}
255
256func newServiceMetadataMiddleware_opDescribeScalingPolicies(region string) *awsmiddleware.RegisterServiceMetadata {
257	return &awsmiddleware.RegisterServiceMetadata{
258		Region:        region,
259		ServiceID:     ServiceID,
260		SigningName:   "gamelift",
261		OperationName: "DescribeScalingPolicies",
262	}
263}
264