1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package clouddirectory 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/clouddirectory/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns all of the ObjectIdentifiers to which a given policy is attached. 16func (c *Client) ListPolicyAttachments(ctx context.Context, params *ListPolicyAttachmentsInput, optFns ...func(*Options)) (*ListPolicyAttachmentsOutput, error) { 17 if params == nil { 18 params = &ListPolicyAttachmentsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListPolicyAttachments", params, optFns, addOperationListPolicyAttachmentsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListPolicyAttachmentsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListPolicyAttachmentsInput struct { 32 33 // The Amazon Resource Name (ARN) that is associated with the Directory where 34 // objects reside. For more information, see arns. 35 // 36 // This member is required. 37 DirectoryArn *string 38 39 // The reference that identifies the policy object. 40 // 41 // This member is required. 42 PolicyReference *types.ObjectReference 43 44 // Represents the manner and timing in which the successful write or update of an 45 // object is reflected in a subsequent read operation of that same object. 46 ConsistencyLevel types.ConsistencyLevel 47 48 // The maximum number of items to be retrieved in a single call. This is an 49 // approximate number. 50 MaxResults *int32 51 52 // The pagination token. 53 NextToken *string 54} 55 56type ListPolicyAttachmentsOutput struct { 57 58 // The pagination token. 59 NextToken *string 60 61 // A list of ObjectIdentifiers to which the policy is attached. 62 ObjectIdentifiers []string 63 64 // Metadata pertaining to the operation's result. 65 ResultMetadata middleware.Metadata 66} 67 68func addOperationListPolicyAttachmentsMiddlewares(stack *middleware.Stack, options Options) (err error) { 69 err = stack.Serialize.Add(&awsRestjson1_serializeOpListPolicyAttachments{}, middleware.After) 70 if err != nil { 71 return err 72 } 73 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListPolicyAttachments{}, middleware.After) 74 if err != nil { 75 return err 76 } 77 if err = addSetLoggerMiddleware(stack, options); err != nil { 78 return err 79 } 80 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 81 return err 82 } 83 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 84 return err 85 } 86 if err = addResolveEndpointMiddleware(stack, options); err != nil { 87 return err 88 } 89 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 90 return err 91 } 92 if err = addRetryMiddlewares(stack, options); err != nil { 93 return err 94 } 95 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 96 return err 97 } 98 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 102 return err 103 } 104 if err = addClientUserAgent(stack); err != nil { 105 return err 106 } 107 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 108 return err 109 } 110 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 111 return err 112 } 113 if err = addOpListPolicyAttachmentsValidationMiddleware(stack); err != nil { 114 return err 115 } 116 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPolicyAttachments(options.Region), middleware.Before); err != nil { 117 return err 118 } 119 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 120 return err 121 } 122 if err = addResponseErrorMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addRequestResponseLogging(stack, options); err != nil { 126 return err 127 } 128 return nil 129} 130 131// ListPolicyAttachmentsAPIClient is a client that implements the 132// ListPolicyAttachments operation. 133type ListPolicyAttachmentsAPIClient interface { 134 ListPolicyAttachments(context.Context, *ListPolicyAttachmentsInput, ...func(*Options)) (*ListPolicyAttachmentsOutput, error) 135} 136 137var _ ListPolicyAttachmentsAPIClient = (*Client)(nil) 138 139// ListPolicyAttachmentsPaginatorOptions is the paginator options for 140// ListPolicyAttachments 141type ListPolicyAttachmentsPaginatorOptions struct { 142 // The maximum number of items to be retrieved in a single call. This is an 143 // approximate number. 144 Limit int32 145 146 // Set to true if pagination should stop if the service returns a pagination token 147 // that matches the most recent token provided to the service. 148 StopOnDuplicateToken bool 149} 150 151// ListPolicyAttachmentsPaginator is a paginator for ListPolicyAttachments 152type ListPolicyAttachmentsPaginator struct { 153 options ListPolicyAttachmentsPaginatorOptions 154 client ListPolicyAttachmentsAPIClient 155 params *ListPolicyAttachmentsInput 156 nextToken *string 157 firstPage bool 158} 159 160// NewListPolicyAttachmentsPaginator returns a new ListPolicyAttachmentsPaginator 161func NewListPolicyAttachmentsPaginator(client ListPolicyAttachmentsAPIClient, params *ListPolicyAttachmentsInput, optFns ...func(*ListPolicyAttachmentsPaginatorOptions)) *ListPolicyAttachmentsPaginator { 162 if params == nil { 163 params = &ListPolicyAttachmentsInput{} 164 } 165 166 options := ListPolicyAttachmentsPaginatorOptions{} 167 if params.MaxResults != nil { 168 options.Limit = *params.MaxResults 169 } 170 171 for _, fn := range optFns { 172 fn(&options) 173 } 174 175 return &ListPolicyAttachmentsPaginator{ 176 options: options, 177 client: client, 178 params: params, 179 firstPage: true, 180 } 181} 182 183// HasMorePages returns a boolean indicating whether more pages are available 184func (p *ListPolicyAttachmentsPaginator) HasMorePages() bool { 185 return p.firstPage || p.nextToken != nil 186} 187 188// NextPage retrieves the next ListPolicyAttachments page. 189func (p *ListPolicyAttachmentsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPolicyAttachmentsOutput, error) { 190 if !p.HasMorePages() { 191 return nil, fmt.Errorf("no more pages available") 192 } 193 194 params := *p.params 195 params.NextToken = p.nextToken 196 197 var limit *int32 198 if p.options.Limit > 0 { 199 limit = &p.options.Limit 200 } 201 params.MaxResults = limit 202 203 result, err := p.client.ListPolicyAttachments(ctx, ¶ms, optFns...) 204 if err != nil { 205 return nil, err 206 } 207 p.firstPage = false 208 209 prevToken := p.nextToken 210 p.nextToken = result.NextToken 211 212 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 213 p.nextToken = nil 214 } 215 216 return result, nil 217} 218 219func newServiceMetadataMiddleware_opListPolicyAttachments(region string) *awsmiddleware.RegisterServiceMetadata { 220 return &awsmiddleware.RegisterServiceMetadata{ 221 Region: region, 222 ServiceID: ServiceID, 223 SigningName: "clouddirectory", 224 OperationName: "ListPolicyAttachments", 225 } 226} 227