]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_arn.h
import ceph 15.2.10
[ceph.git] / ceph / src / rgw / rgw_arn.h
CommitLineData
eafe8130
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab ft=cpp
3
4#pragma once
5#include <string>
6#include <boost/optional.hpp>
7
8class rgw_obj;
9class rgw_bucket;
10
11namespace rgw {
12
13enum 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'
18 // partition type.
19};
20
21enum struct Service {
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
36};
37
38/* valid format:
39 * 'arn:partition:service:region:account-id:resource'
40 * The 'resource' part can be further broken down via ARNResource
41*/
42struct ARN {
43 Partition partition;
44 Service service;
45 std::string region;
46 // Once we refit tenant, we should probably use that instead of a
47 // string.
48 std::string account;
49 std::string resource;
50
51 ARN()
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);
61
62 static boost::optional<ARN> parse(const std::string& s,
63 bool wildcard = false);
64 std::string to_string() const;
65
66 // `this` is the pattern
67 bool match(const ARN& candidate) const;
68};
69
70inline std::string to_string(const ARN& a) {
71 return a.to_string();
72}
73
74inline std::ostream& operator <<(std::ostream& m, const ARN& a) {
75 return m << to_string(a);
76}
77
78bool operator ==(const ARN& l, const ARN& r);
79bool operator <(const ARN& l, const ARN& r);
80
81/* valid formats (only resource part):
82 * 'resource'
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
89*/
90struct ARNResource {
91 constexpr static const char* const wildcard = "*";
92 std::string resource_type;
93 std::string resource;
94 std::string qualifier;
95
96 ARNResource() : resource_type(""), resource(wildcard), qualifier("") {}
97
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)) {}
100
101 static boost::optional<ARNResource> parse(const std::string& s);
102
103 std::string to_string() const;
104};
105
106inline std::string to_string(const ARNResource& r) {
107 return r.to_string();
108}
109
110} // namespace rgw
111
112namespace std {
113template<>
114struct 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));
118 }
119};
120} // namespace std
121