aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/endpoint/internal/AWSEndpointAttribute.cpp
blob: 5c295bb1325b0a481cde605e950d7a3153b4be8c (plain) (blame)
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
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/core/endpoint/internal/AWSEndpointAttribute.h>
#include <aws/core/utils/logging/LogMacros.h>

static const char ENDPOINT_AUTH_SCHEME_TAG[] = "EndpointAuthScheme::BuildEndpointAuthSchemeFromJson";

Aws::String CrtToSdkSignerName(const Aws::String& crtSignerName)
{
    Aws::String sdkSigner = "NullSigner";
    if (crtSignerName == "sigv4") {
        sdkSigner = "SignatureV4";
    } else if (crtSignerName == "sigv4a") {
        sdkSigner = "AsymmetricSignatureV4";
    } else if (crtSignerName == "none") {
        sdkSigner = "NullSigner";
    } else if (crtSignerName == "bearer") {
        sdkSigner = "Bearer";
    } else {
        AWS_LOG_WARN(ENDPOINT_AUTH_SCHEME_TAG, (Aws::String("Unknown Endpoint authSchemes signer: ") + crtSignerName).c_str());
    }

    return sdkSigner;
}

Aws::Internal::Endpoint::EndpointAttributes
Aws::Internal::Endpoint::EndpointAttributes::BuildEndpointAttributesFromJson(const Aws::String& iJsonStr)
{
    Aws::Internal::Endpoint::EndpointAttributes attributes;
    Aws::Internal::Endpoint::EndpointAuthScheme& authScheme = attributes.authScheme;

    Utils::Json::JsonValue jsonObject(iJsonStr);
    if (jsonObject.WasParseSuccessful())
    {
        Aws::Map<Aws::String, Utils::Json::JsonView> jsonMap = jsonObject.View().GetAllObjects();
        for (const auto& mapItemAttribute : jsonMap)
        {
            if (mapItemAttribute.first == "authSchemes" && mapItemAttribute.second.IsListType()) {
                Aws::Utils::Array<Utils::Json::JsonView> jsonAuthSchemeArray = mapItemAttribute.second.AsArray();

                for (size_t arrayIdx = 0; arrayIdx < jsonAuthSchemeArray.GetLength(); ++arrayIdx)
                {
                    const Utils::Json::JsonView& property = jsonAuthSchemeArray.GetItem(arrayIdx);
                    for (const auto& mapItemProperty : property.GetAllObjects())
                    {
                        if (mapItemProperty.first == "name") {
                            authScheme.SetName(CrtToSdkSignerName(mapItemProperty.second.AsString()));
                        } else if (mapItemProperty.first == "signingName") {
                            authScheme.SetSigningName(mapItemProperty.second.AsString());
                        } else if (mapItemProperty.first == "signingRegion") {
                            authScheme.SetSigningRegion(mapItemProperty.second.AsString());
                        } else if (mapItemProperty.first == "signingRegionSet") {
                            Aws::Utils::Array<Utils::Json::JsonView> signingRegionArray = mapItemProperty.second.AsArray();
                            if (signingRegionArray.GetLength() != 1) {
                                AWS_LOG_WARN(ENDPOINT_AUTH_SCHEME_TAG,
                                             "Signing region set size is not equal to 1");
                            }
                            if (signingRegionArray.GetLength() > 0) {
                                authScheme.SetSigningRegionSet(signingRegionArray.GetItem(0).AsString());
                            }
                        } else if (mapItemProperty.first == "disableDoubleEncoding") {
                            authScheme.SetDisableDoubleEncoding(mapItemProperty.second.AsBool());
                        } else {
                            AWS_LOG_WARN(ENDPOINT_AUTH_SCHEME_TAG, Aws::String("Unknown Endpoint authSchemes attribute property: " + mapItemProperty.first).c_str());
                        }
                    }
                }
            } else {
                AWS_LOG_WARN(ENDPOINT_AUTH_SCHEME_TAG, Aws::String("Unknown Endpoint Attribute: " + mapItemAttribute.first).c_str());
            }
        }
    }
    else
    {
        AWS_LOGSTREAM_ERROR(ENDPOINT_AUTH_SCHEME_TAG, "Json Parse failed with message: " << jsonObject.GetErrorMessage());
    }

    return attributes;
}