service_credentials_provider.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 #pragma once
17 
18 #include <aws/core/Aws.h>
19 #include <aws/core/auth/AWSAuthSigner.h>
20 #include <aws/core/auth/AWSCredentialsProvider.h>
21 #include <aws/core/auth/AWSCredentialsProviderChain.h>
22 #include <aws/core/utils/json/JsonSerializer.h>
24 
25 #include <mutex>
26 
27 namespace Aws {
28 namespace Auth {
29 
32 static const long DEFAULT_AUTH_CONNECT_TIMEOUT_MS = 5000; // NOLINT(google-runtime-int)
35 static const long DEFAULT_AUTH_TOTAL_TIMEOUT_MS = 10000; // NOLINT(google-runtime-int)
36 
37 static const char CFG_CAFILE[] = "cafile";
38 static const char CFG_CERTFILE[] = "certfile";
39 static const char CFG_KEYFILE[] = "keyfile";
40 static const char CFG_ENDPOINT[] = "endpoint";
41 static const char CFG_ROLE[] = "role";
42 static const char CFG_THING_NAME[] = "thing_name";
43 static const char CFG_CONNECT_TIMEOUT_MS[] = "connect_timeout_ms";
44 static const char CFG_TOTAL_TIMEOUT_MS[] = "total_timeout_ms";
45 
58 {
59  IotRoleConfig() = default;
60 
61  IotRoleConfig(const char * _cafile,
62  const char * _certfile,
63  const char * _keyfile,
64  const char * _host,
65  const char * _role,
66  const char * _name,
67  const int _connect_timeout_ms,
68  const int _total_timeout_ms)
69  : cafile(_cafile),
70  certfile(_certfile),
71  keyfile(_keyfile),
72  host(_host),
73  role(_role),
74  name(_name),
75  connect_timeout_ms(_connect_timeout_ms),
76  total_timeout_ms(_total_timeout_ms) {}
77 
79  Aws::String cafile;
81  Aws::String certfile;
83  Aws::String keyfile;
85  Aws::String host;
87  Aws::String role;
89  Aws::String name;
91  long connect_timeout_ms = 0; // NOLINT(google-runtime-int)
93  long total_timeout_ms = 0; // NOLINT(google-runtime-int)
94 };
95 
104 {
107 };
108 
118  const std::shared_ptr<Aws::Client::ParameterReaderInterface> & parameters);
119 
129 class IotRoleCredentialsProvider : public Aws::Auth::AWSCredentialsProvider
130 {
131 public:
135  // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
138  IotRoleCredentialsProvider & operator=(const IotRoleCredentialsProvider & other) = delete;
139 
140  ~IotRoleCredentialsProvider() override;
141 
142  AWSCredentials GetAWSCredentials() override;
143 
144 protected:
145  // Visible for testing
146 
148  void Refresh();
150  void SetCredentials(AWSCredentials & creds_obj);
152  bool ValidateResponse(Aws::Utils::Json::JsonValue & value);
154  bool IsTimeExpired();
156  Aws::Auth::AWSCredentials cached_;
157 
158 private:
162  std::mutex creds_mutex_;
164  std::atomic<double> expiry_;
165 };
166 
175 class ServiceCredentialsProviderChain : public DefaultAWSCredentialsProviderChain
176 {
177 public:
182  // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
184  ~ServiceCredentialsProviderChain() override = default;
185 };
186 
187 } /* namespace Auth */
188 } /* namespace Aws */
static const char CFG_THING_NAME[]
Credentials provider chain for ROS AWS service integrations.
Aws::String host
Host name of the iot:CredentialProvider endpoint.
static const char CFG_TOTAL_TIMEOUT_MS[]
std::mutex creds_mutex_
Mutex to ensure only a single request is outstanding at any given time.
IotRoleConfig iot
IoT-specific configuration.
static const char CFG_CONNECT_TIMEOUT_MS[]
static const char CFG_CAFILE[]
static const long DEFAULT_AUTH_TOTAL_TIMEOUT_MS
Default number of milliseconds to wait before timing out when retrieving credentials from IoT...
static const char CFG_CERTFILE[]
long connect_timeout_ms
Number of ms to wait before timing out when connecting to the endpoint.
static const char CFG_ROLE[]
static const char CFG_KEYFILE[]
Aws::String cafile
Path to the Root CA for the endpoint.
IotRoleConfig config_
Configuration for connecting to IoT.
Auth configuration needed to retrieve AWS credentials via the IoT service.
Aws::String name
Thing name for the device.
static const long DEFAULT_AUTH_CONNECT_TIMEOUT_MS
Default number of milliseconds to wait before timing out when connecting to retrieve credentials from...
Aws::String certfile
Path to the certificate which identifies the device.
IotRoleConfig(const char *_cafile, const char *_certfile, const char *_keyfile, const char *_host, const char *_role, const char *_name, const int _connect_timeout_ms, const int _total_timeout_ms)
Aws::String role
Name of the AWS IoT Role Alias for the device.
static const char CFG_ENDPOINT[]
std::atomic< double > expiry_
Future epoch when the cached credentials will expire.
Aws::Auth::AWSCredentials cached_
Current cached credentials.
long total_timeout_ms
Total number of ms to wait for the entire connect/request/response transaction.
bool GetServiceAuthConfig(ServiceAuthConfig &config, const std::shared_ptr< Aws::Client::ParameterReaderInterface > &parameters)
Retrieves service authorization data from a ParameterReaderInterface and populates the ServiceAuthCon...
Aws::String keyfile
Path to the related private key for the certificate.
AWSCredentialsProvider that obtains credentials using the AWS IoT Core service.
Auth configuration for ROS AWS service integration.


aws_common
Author(s): AWS RoboMaker
autogenerated on Sat Mar 6 2021 03:11:38