1 package scw
2 3 import (
4 "context"
5 6 "github.com/scaleway/scaleway-sdk-go/internal/auth"
7 )
8 9 // RequestOption is a function that applies options to a ScalewayRequest.
10 type RequestOption func(*ScalewayRequest)
11 12 // WithContext request option sets the context of a ScalewayRequest
13 func WithContext(ctx context.Context) RequestOption {
14 return func(s *ScalewayRequest) {
15 s.ctx = ctx
16 }
17 }
18 19 // WithAllPages aggregate all pages in the response of a List request.
20 // Will error when pagination is not supported on the request.
21 func WithAllPages() RequestOption {
22 return func(s *ScalewayRequest) {
23 s.allPages = true
24 }
25 }
26 27 // WithAuthRequest overwrites the client access key and secret key used in the request.
28 func WithAuthRequest(accessKey, secretKey string) RequestOption {
29 return func(s *ScalewayRequest) {
30 s.auth = auth.NewToken(accessKey, secretKey)
31 }
32 }
33 34 // WithZones aggregate results from requested zones in the response of a List request.
35 // response rows are sorted by zone using order of given zones
36 // Will error when pagination is not supported on the request.
37 func WithZones(zones ...Zone) RequestOption {
38 return func(s *ScalewayRequest) {
39 s.zones = append(s.zones, zones...)
40 }
41 }
42 43 // WithRegions aggregate results from requested regions in the response of a List request.
44 // response rows are sorted by region using order of given regions
45 // Will error when pagination is not supported on the request.
46 func WithRegions(regions ...Region) RequestOption {
47 return func(s *ScalewayRequest) {
48 s.regions = append(s.regions, regions...)
49 }
50 }
51