1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
6 #include <boost/optional.hpp>
13 enum struct Partition
{
14 aws
, aws_cn
, aws_us_gov
, wildcard
15 // If we wanted our own ARNs for principal type unique to us
16 // (maybe to integrate better with Swift) or for anything else we
17 // provide that doesn't map onto S3, we could add an 'rgw'
22 apigateway
, appstream
, artifact
, autoscaling
, aws_portal
, acm
,
23 cloudformation
, cloudfront
, cloudhsm
, cloudsearch
, cloudtrail
,
24 cloudwatch
, events
, logs
, codebuild
, codecommit
, codedeploy
,
25 codepipeline
, cognito_idp
, cognito_identity
, cognito_sync
,
26 config
, datapipeline
, dms
, devicefarm
, directconnect
,
27 ds
, dynamodb
, ec2
, ecr
, ecs
, ssm
, elasticbeanstalk
, elasticfilesystem
,
28 elasticloadbalancing
, elasticmapreduce
, elastictranscoder
, elasticache
,
29 es
, gamelift
, glacier
, health
, iam
, importexport
, inspector
, iot
,
30 kms
, kinesisanalytics
, firehose
, kinesis
, lambda
, lightsail
,
31 machinelearning
, aws_marketplace
, aws_marketplace_management
,
32 mobileanalytics
, mobilehub
, opsworks
, opsworks_cm
, polly
,
33 redshift
, rds
, route53
, route53domains
, sts
, servicecatalog
,
34 ses
, sns
, sqs
, s3
, swf
, sdb
, states
, storagegateway
, support
,
35 trustedadvisor
, waf
, workmail
, workspaces
, wildcard
39 * 'arn:partition:service:region:account-id:resource'
40 * The 'resource' part can be further broken down via ARNResource
46 // Once we refit tenant, we should probably use that instead of a
52 : partition(Partition::wildcard
), service(Service::wildcard
) {}
53 ARN(Partition partition
, Service service
, std::string region
,
54 std::string account
, std::string resource
)
55 : partition(partition
), service(service
), region(std::move(region
)),
56 account(std::move(account
)), resource(std::move(resource
)) {}
57 ARN(const rgw_obj
& o
);
58 ARN(const rgw_bucket
& b
);
59 ARN(const rgw_bucket
& b
, const std::string
& o
);
60 ARN(const std::string
& resource_name
, const std::string
& type
, const std::string
& tenant
, bool has_path
=false);
62 static boost::optional
<ARN
> parse(const std::string
& s
,
63 bool wildcard
= false);
64 std::string
to_string() const;
66 // `this` is the pattern
67 bool match(const ARN
& candidate
) const;
70 inline std::string
to_string(const ARN
& a
) {
74 inline std::ostream
& operator <<(std::ostream
& m
, const ARN
& a
) {
75 return m
<< to_string(a
);
78 bool operator ==(const ARN
& l
, const ARN
& r
);
79 bool operator <(const ARN
& l
, const ARN
& r
);
81 /* valid formats (only resource part):
83 * 'resourcetype/resource'
84 * 'resourcetype/resource/qualifier'
85 * 'resourcetype/resource:qualifier'
86 * 'resourcetype:resource'
87 * 'resourcetype:resource:qualifier'
88 * Note that 'resourceType' cannot be wildcard
91 constexpr static const char* const wildcard
= "*";
92 std::string resource_type
;
94 std::string qualifier
;
96 ARNResource() : resource_type(""), resource(wildcard
), qualifier("") {}
98 ARNResource(const std::string
& _resource_type
, const std::string
& _resource
, const std::string
& _qualifier
) :
99 resource_type(std::move(_resource_type
)), resource(std::move(_resource
)), qualifier(std::move(_qualifier
)) {}
101 static boost::optional
<ARNResource
> parse(const std::string
& s
);
103 std::string
to_string() const;
106 inline std::string
to_string(const ARNResource
& r
) {
107 return r
.to_string();
114 struct hash
<::rgw::Service
> {
115 size_t operator()(const ::rgw::Service
& s
) const noexcept
{
116 // Invoke a default-constructed hash object for int.
117 return hash
<int>()(static_cast<int>(s
));