github.com/etecs-ru/gnomock@v0.13.2/preset/localstack/options.go (about)

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