1 | /* |
---|---|
2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
5 | * You may not use this file except in compliance with the License. |
6 | * A copy of the License is located at |
7 | * |
8 | * http://aws.amazon.com/apache2.0 |
9 | * |
10 | * or in the "license" file accompanying this file. This file is distributed |
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
12 | * express or implied. See the License for the specific language governing |
13 | * permissions and limitations under the License. |
14 | */ |
15 | |
16 | #include <aws/core/utils/ARN.h> |
17 | #include <aws/core/utils/StringUtils.h> |
18 | #include <aws/core/utils/logging/LogMacros.h> |
19 | |
20 | namespace Aws |
21 | { |
22 | namespace Utils |
23 | { |
24 | ARN::ARN(const Aws::String& arnString) |
25 | { |
26 | m_valid = false; |
27 | |
28 | // An ARN can be identified as any string starting with arn: with 6 defined segments each separated by a : |
29 | const auto result = StringUtils::Split(arnString, ':', StringUtils::SplitOptions::INCLUDE_EMPTY_ENTRIES); |
30 | |
31 | if (result.size() < 6) |
32 | { |
33 | return; |
34 | } |
35 | |
36 | if (result[0] != "arn") |
37 | { |
38 | return; |
39 | } |
40 | |
41 | m_arnString = arnString; |
42 | m_partition = result[1]; |
43 | m_service = result[2]; |
44 | m_region = result[3]; |
45 | m_accountId = result[4]; |
46 | m_resource = result[5]; |
47 | |
48 | for (size_t i = 6; i < result.size(); i++) |
49 | { |
50 | m_resource += ":"+ result[i]; |
51 | } |
52 | |
53 | m_valid = true; |
54 | } |
55 | } |
56 | } |