/
options.go
97 lines (88 loc) 路 2.25 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package localstack
import (
"encoding/json"
"fmt"
)
// Option is an optional configuration of this Gnomock preset. Use available
// Options to configure the container
type Option func(*P)
// Service represents an AWS service that can be setup using localstack
type Service string
// UnmarshalJSON allows to unmarshal string into Service type
func (s *Service) UnmarshalJSON(bs []byte) error {
var service string
err := json.Unmarshal(bs, &service)
if err != nil {
return fmt.Errorf("invalid service '%s': %w", string(bs), err)
}
switch svc := Service(service); svc {
case APIGateway,
CloudFormation,
CloudWatch,
CloudWatchLogs,
CloudWatchEvents,
DynamoDB,
DynamoDBStreams,
EC2,
ES,
Firehose,
IAM,
Kinesis,
KMS,
Lambda,
Redshift,
Route53,
S3,
SecretsManager,
SES,
SNS,
SQS,
SSM,
STS,
StepFunctions:
*s = svc
return nil
default:
return fmt.Errorf("unknown service '%s'", svc)
}
}
// These services are available in this Preset
const (
APIGateway Service = "apigateway"
CloudFormation Service = "cloudformation"
CloudWatch Service = "cloudwatch"
CloudWatchLogs Service = "logs"
CloudWatchEvents Service = "events"
DynamoDB Service = "dynamodb"
DynamoDBStreams Service = "dynamodbstreams"
EC2 Service = "ec2"
ES Service = "es"
Firehose Service = "firehose"
IAM Service = "iam"
Kinesis Service = "kinesis"
KMS Service = "kms"
Lambda Service = "lambda"
Redshift Service = "redshift"
Route53 Service = "route53"
S3 Service = "s3"
SecretsManager Service = "secretsmanager"
SES Service = "ses"
SNS Service = "sns"
SQS Service = "sqs"
SSM Service = "ssm"
STS Service = "sts"
StepFunctions Service = "stepfunctions"
)
// WithServices selects localstack services to spin up. It is OK to not select
// any services, but in such case the container will be useless
func WithServices(services ...Service) Option {
return func(o *P) {
o.Services = append(o.Services, services...)
}
}
// WithVersion sets image version.
func WithVersion(version string) Option {
return func(o *P) {
o.Version = version
}
}