diff --git a/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationClient.h b/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationClient.h index 37f9479ed..f95eb2194 100644 --- a/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationClient.h +++ b/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationClient.h @@ -36,7 +36,7 @@ #include #include #include -#include +#include /** * @brief Rules all the other namespaces. @@ -65,7 +65,7 @@ class AUTHENTICATION_API AuthenticationClient { /** * @brief (Optional) The scope assigned to the access token. */ - boost::optional scope{boost::none}; + porting::optional scope{porting::none}; /** * @brief (Optional) The device ID assigned to the access token. @@ -73,7 +73,7 @@ class AUTHENTICATION_API AuthenticationClient { * @note This field is only necessary if you want to apply a oauth rate * limit on a particular device. */ - boost::optional device_id{boost::none}; + porting::optional device_id{porting::none}; /** * @brief (Optional) The number of seconds left before the access @@ -89,7 +89,7 @@ class AUTHENTICATION_API AuthenticationClient { * requires it. Fully overrides default body and resets the request content * type. */ - boost::optional custom_body{boost::none}; + porting::optional custom_body{olp::porting::none}; }; /** diff --git a/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationCredentials.h b/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationCredentials.h index 2c81cbda1..4aeea40c8 100644 --- a/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationCredentials.h +++ b/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationCredentials.h @@ -21,7 +21,7 @@ #include -#include +#include #include "AuthenticationApi.h" namespace olp { @@ -58,12 +58,13 @@ class AUTHENTICATION_API AuthenticationCredentials { * @return An optional value with your credentials if the credentials were * read successfully, or no value in case of failure. */ - static boost::optional ReadFromStream( + static porting::optional ReadFromStream( std::istream& stream); /** - * @brief Parses the **credentials.properties** file downloaded from the [HERE platform](https://platform.here.com/) - * website and retrieves a value with your credentials. + * @brief Parses the **credentials.properties** file downloaded from the [HERE + * platform](https://platform.here.com/) website and retrieves a value with + * your credentials. * * The file must contain the following lines: * * here.access.key.id – your access key ID @@ -81,7 +82,7 @@ class AUTHENTICATION_API AuthenticationCredentials { * @return The optional value with your credentials if the credentials were * read successfully, or no value in case of failure. */ - static boost::optional ReadFromFile( + static porting::optional ReadFromFile( std::string filename = {}); AuthenticationCredentials() = delete; diff --git a/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationSettings.h b/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationSettings.h index a7f46775e..89c49cd3e 100644 --- a/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationSettings.h +++ b/olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationSettings.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace olp { namespace http { @@ -50,9 +50,9 @@ struct AUTHENTICATION_API AuthenticationSettings { /** * @brief The configuration settings for the network layer. * - * To remove any existing proxy settings, set to boost::none. + * To remove any existing proxy settings, set to olp::porting::none. */ - boost::optional network_proxy_settings{}; + porting::optional network_proxy_settings{}; /** * @brief The network instance that is used to internally operate with the diff --git a/olp-cpp-sdk-authentication/include/olp/authentication/AuthorizeRequest.h b/olp-cpp-sdk-authentication/include/olp/authentication/AuthorizeRequest.h index 7d37a62a0..fe0f6f008 100644 --- a/olp-cpp-sdk-authentication/include/olp/authentication/AuthorizeRequest.h +++ b/olp-cpp-sdk-authentication/include/olp/authentication/AuthorizeRequest.h @@ -19,11 +19,11 @@ #pragma once -#include #include #include #include +#include namespace olp { namespace authentication { @@ -83,7 +83,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return The service ID. */ - inline const std::string& GetServiceId() const { return service_id_; } + const std::string& GetServiceId() const { return service_id_; } /** * @brief Sets the service ID. @@ -92,7 +92,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return A reference to the updated `DecisionRequest` instance. */ - inline AuthorizeRequest& WithServiceId(std::string service_id) { + AuthorizeRequest& WithServiceId(std::string service_id) { service_id_ = std::move(service_id); return *this; } @@ -109,7 +109,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return The contract ID or an error. */ - inline const boost::optional& GetContractId() const { + const porting::optional& GetContractId() const { return contract_id_; } @@ -122,9 +122,9 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return A reference to the updated `DecisionRequest` instance. */ - inline AuthorizeRequest& WithContractId( - boost::optional contract_id) { - contract_id_ = std::move(contract_id); + template > + AuthorizeRequest& WithContractId(T&& contract_id) { + contract_id_ = std::forward(contract_id); return *this; } @@ -137,7 +137,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return A reference to the updated `DecisionRequest` instance. */ - inline AuthorizeRequest& WithContractId(std::string contract_id) { + AuthorizeRequest& WithContractId(std::string contract_id) { contract_id_ = std::move(contract_id); return *this; } @@ -159,8 +159,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return A reference to the updated `DecisionRequest` instance. */ - inline AuthorizeRequest& WithAction(std::string action, - std::string resource = "") { + AuthorizeRequest& WithAction(std::string action, std::string resource = "") { actions_.emplace_back(std::move(action), std::move(resource)); return *this; } @@ -174,7 +173,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return The operator type. */ - inline DecisionOperatorType GetOperatorType() const { return operator_type_; } + DecisionOperatorType GetOperatorType() const { return operator_type_; } /** * @brief Sets the operator type for the request. @@ -185,8 +184,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return A reference to the updated `DecisionRequest` instance. */ - inline AuthorizeRequest& WithOperatorType( - DecisionOperatorType operator_type) { + AuthorizeRequest& WithOperatorType(DecisionOperatorType operator_type) { operator_type_ = operator_type; return *this; } @@ -196,7 +194,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return The diagnostics flag. */ - inline bool GetDiagnostics() const { return diagnostics_; } + bool GetDiagnostics() const { return diagnostics_; } /** * @brief Sets the diagnostics flag for the request. @@ -206,7 +204,7 @@ class AUTHENTICATION_API AuthorizeRequest final { * * @return A reference to the updated `DecisionRequest` instance. */ - inline AuthorizeRequest& WithDiagnostics(bool diagnostics) { + AuthorizeRequest& WithDiagnostics(bool diagnostics) { diagnostics_ = diagnostics; return *this; } @@ -220,7 +218,7 @@ class AUTHENTICATION_API AuthorizeRequest final { private: std::string service_id_; - boost::optional contract_id_; + porting::optional contract_id_; Actions actions_; DecisionOperatorType operator_type_{DecisionOperatorType::kAnd}; bool diagnostics_{false}; diff --git a/olp-cpp-sdk-authentication/include/olp/authentication/Settings.h b/olp-cpp-sdk-authentication/include/olp/authentication/Settings.h index 0264226d1..6019306c2 100644 --- a/olp-cpp-sdk-authentication/include/olp/authentication/Settings.h +++ b/olp-cpp-sdk-authentication/include/olp/authentication/Settings.h @@ -19,12 +19,12 @@ #pragma once -#include #include #include #include #include +#include #include "AuthenticationApi.h" #include "AuthenticationCredentials.h" @@ -77,7 +77,7 @@ struct AUTHENTICATION_API Settings { /** * @brief (Optional) The configuration settings for the network layer. */ - boost::optional network_proxy_settings; + porting::optional network_proxy_settings; /** * @brief (Optional) The server URL of the token endpoint. @@ -108,7 +108,7 @@ struct AUTHENTICATION_API Settings { /** * @brief (Optional) The scope to be assigned to an access token requests. */ - boost::optional scope; + porting::optional scope; }; } // namespace authentication diff --git a/olp-cpp-sdk-authentication/include/olp/authentication/TokenResult.h b/olp-cpp-sdk-authentication/include/olp/authentication/TokenResult.h index 0d31a0f84..d63f1697d 100644 --- a/olp-cpp-sdk-authentication/include/olp/authentication/TokenResult.h +++ b/olp-cpp-sdk-authentication/include/olp/authentication/TokenResult.h @@ -19,11 +19,11 @@ #pragma once -#include #include #include #include +#include #include "AuthenticationApi.h" #include "ErrorResponse.h" @@ -47,7 +47,7 @@ class AUTHENTICATION_API TokenResult { * @param scope The scope assigned to the access token. */ TokenResult(std::string access_token, time_t expiry_time, - boost::optional scope); + porting::optional scope); /** * @brief Creates the `TokenResult` instance. @@ -57,7 +57,7 @@ class AUTHENTICATION_API TokenResult { * @param scope The scope assigned to the access token. */ TokenResult(std::string access_token, std::chrono::seconds expires_in, - boost::optional scope); + porting::optional scope); /** * @brief Creates the default `TokenResult` instance. */ @@ -92,13 +92,13 @@ class AUTHENTICATION_API TokenResult { * @return The optional string that contains the scope assigned to the access * token. */ - const boost::optional& GetScope() const; + const porting::optional& GetScope() const; private: std::string access_token_; time_t expiry_time_{}; std::chrono::seconds expires_in_{}; - boost::optional scope_; + porting::optional scope_; }; } // namespace authentication diff --git a/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp b/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp index 855b44a42..567c1cde8 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp +++ b/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp @@ -265,24 +265,24 @@ Response AuthenticationClientImpl::GetSignInResponse( } template <> -boost::optional AuthenticationClientImpl::FindInCache( +porting::optional AuthenticationClientImpl::FindInCache( const std::string& key) { return client_token_cache_->locked( [&](utils::LruCache& cache) { auto it = cache.Find(key); - return it != cache.end() ? boost::make_optional(it->value()) - : boost::none; + return it != cache.end() ? porting::make_optional(it->value()) + : porting::none; }); } template <> -boost::optional AuthenticationClientImpl::FindInCache( +porting::optional AuthenticationClientImpl::FindInCache( const std::string& key) { return user_token_cache_->locked( [&](utils::LruCache& cache) { auto it = cache.Find(key); - return it != cache.end() ? boost::make_optional(it->value()) - : boost::none; + return it != cache.end() ? porting::make_optional(it->value()) + : porting::none; }); } @@ -325,7 +325,7 @@ client::CancellationToken AuthenticationClientImpl::SignInClient( // endpoint with it. Construction of the `OlpClient` requires the host part // of URL, while `CallAuth` method - the rest of URL, hence we need to split // URL passed in the Credentials object. - const auto credentials_endpoint = credentials.GetEndpointUrl(); + const auto& credentials_endpoint = credentials.GetEndpointUrl(); const auto maybe_host_and_rest = olp::utils::Url::ParseHostAndRest(credentials_endpoint); if (maybe_host_and_rest) { @@ -338,7 +338,7 @@ client::CancellationToken AuthenticationClientImpl::SignInClient( // settings object. auto settings = settings_; settings.token_endpoint_url = olp_client_host; - auto client = CreateOlpClient(settings, boost::none, false); + auto client = CreateOlpClient(settings, porting::none, false); RequestTimer timer = CreateRequestTimer(client, context); @@ -472,7 +472,7 @@ client::CancellationToken AuthenticationClientImpl::SignInApple( return client::ApiError::Cancelled(); } - auto client = CreateOlpClient(settings_, boost::none); + auto client = CreateOlpClient(settings_, porting::none); auto auth_response = CallApi(client, kOauthEndpoint, context, properties.GetAccessToken(), request_body); @@ -534,7 +534,7 @@ client::CancellationToken AuthenticationClientImpl::HandleUserRequest( return client::ApiError::Cancelled(); } - auto client = CreateOlpClient(settings_, boost::none, false); + auto client = CreateOlpClient(settings_, porting::none, false); RequestTimer timer = CreateRequestTimer(client, context); @@ -834,12 +834,12 @@ client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateClientBody( if (properties.scope) { writer.Key(kScope); - writer.String(properties.scope.get().c_str()); + writer.String(properties.scope->c_str()); } if (properties.device_id) { writer.Key(kDeviceId); - writer.String(properties.device_id.get().c_str()); + writer.String(properties.device_id->c_str()); } writer.EndObject(); diff --git a/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.h b/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.h index a3fa78963..ba7f13af4 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.h +++ b/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.h @@ -178,7 +178,7 @@ class AuthenticationClientImpl { const client::CancellationContext& context, const std::string& key); template - boost::optional FindInCache(const std::string& key); + porting::optional FindInCache(const std::string& key); template void StoreInCache(const std::string& key, SignInResponseType); diff --git a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp index 3ff6616c2..7de7dccca 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp +++ b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -123,7 +124,7 @@ std::time_t ParseTime(const std::string& value) { #endif -boost::optional GetTimestampFromHeaders( +porting::optional GetTimestampFromHeaders( const olp::http::Headers& headers) { auto it = std::find_if(begin(headers), end(headers), @@ -134,7 +135,7 @@ boost::optional GetTimestampFromHeaders( if (it != end(headers)) { return ParseTime(it->second); } - return boost::none; + return porting::none; } IntrospectAppResult GetIntrospectAppResult(const rapidjson::Document& doc) { @@ -263,11 +264,11 @@ UserAccountInfoResponse GetUserAccountInfoResponse( client::OlpClient CreateOlpClient( const AuthenticationSettings& auth_settings, - boost::optional authentication_settings, - bool retry) { + porting::optional authentication_settings, + const bool retry) { client::OlpClientSettings settings; settings.network_request_handler = auth_settings.network_request_handler; - settings.authentication_settings = authentication_settings; + settings.authentication_settings = std::move(authentication_settings); settings.proxy_settings = auth_settings.network_proxy_settings; settings.retry_settings = auth_settings.retry_settings; diff --git a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h index 2b5af2fc4..3904627df 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h +++ b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h @@ -70,7 +70,7 @@ inline client::CancellationToken AddTask( * @param headers http headers. * @return optional time_t time from headers. */ -boost::optional GetTimestampFromHeaders( +porting::optional GetTimestampFromHeaders( const http::Headers& headers); /* @@ -129,7 +129,7 @@ std::time_t ParseTime(const std::string& value); */ client::OlpClient CreateOlpClient( const AuthenticationSettings& auth_settings, - boost::optional authentication_settings, + porting::optional authentication_settings, bool retry = true); /* diff --git a/olp-cpp-sdk-authentication/src/AuthenticationCredentials.cpp b/olp-cpp-sdk-authentication/src/AuthenticationCredentials.cpp index ea137809c..15111e8d1 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationCredentials.cpp +++ b/olp-cpp-sdk-authentication/src/AuthenticationCredentials.cpp @@ -58,7 +58,7 @@ std::string GetDefaultPath() { namespace olp { namespace authentication { -boost::optional +porting::optional AuthenticationCredentials::ReadFromStream(std::istream& stream) { static const std::regex kRegex{kRegexString}; @@ -89,20 +89,20 @@ AuthenticationCredentials::ReadFromStream(std::istream& stream) { } return (!access_key_id.empty() && !access_key_secret.empty()) - ? boost::make_optional( + ? porting::make_optional( {std::move(access_key_id), std::move(access_key_secret), std::move(token_endpoint_url)}) - : boost::none; + : porting::none; } -boost::optional +porting::optional AuthenticationCredentials::ReadFromFile(std::string filename) { if (filename.empty()) { filename = GetDefaultPath(); } std::ifstream stream(filename, std::ios::in); - return stream ? ReadFromStream(stream) : boost::none; + return stream ? ReadFromStream(stream) : porting::none; } AuthenticationCredentials::AuthenticationCredentials(std::string key, diff --git a/olp-cpp-sdk-authentication/src/AuthorizeRequest.cpp b/olp-cpp-sdk-authentication/src/AuthorizeRequest.cpp index bd4c7e937..8c2c06ca4 100644 --- a/olp-cpp-sdk-authentication/src/AuthorizeRequest.cpp +++ b/olp-cpp-sdk-authentication/src/AuthorizeRequest.cpp @@ -28,7 +28,7 @@ std::string AuthorizeRequest::CreateKey() const { std::stringstream out; out << service_id_; if (GetContractId()) { - out << "[" << GetContractId().get() << "]"; + out << "[" << *GetContractId() << "]"; } return out.str(); } diff --git a/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp b/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp index 5e38439d9..52bf22fa9 100644 --- a/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp +++ b/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp @@ -129,7 +129,7 @@ std::string GenerateUid() { client::OlpClient::RequestBodyType GenerateClientBody( const TokenRequest& token_request, - const boost::optional& scope) { + const porting::optional& scope) { rapidjson::StringBuffer data; rapidjson::Writer writer(data); writer.StartObject(); @@ -146,7 +146,7 @@ client::OlpClient::RequestBodyType GenerateClientBody( if (scope) { writer.Key(kScope); - writer.String(scope.get().c_str()); + writer.String(scope->c_str()); } writer.EndObject(); @@ -211,10 +211,11 @@ client::CancellationToken TokenEndpointImpl::RequestToken( return; } - callback(TokenResult{ - sign_in_result.GetAccessToken(), sign_in_result.GetExpiresIn(), - sign_in_result.GetScope().empty() ? boost::optional{} - : sign_in_result.GetScope()}); + callback(TokenResult{sign_in_result.GetAccessToken(), + sign_in_result.GetExpiresIn(), + sign_in_result.GetScope().empty() + ? olp::porting::optional{} + : sign_in_result.GetScope()}); }); } @@ -251,7 +252,7 @@ TokenResponse TokenEndpointImpl::RequestToken( return TokenResult{ sign_in_result.GetAccessToken(), sign_in_result.GetExpiresIn(), - sign_in_result.GetScope().empty() ? boost::optional{} + sign_in_result.GetScope().empty() ? olp::porting::optional{} : sign_in_result.GetScope()}; } @@ -266,7 +267,7 @@ SignInResponse TokenEndpointImpl::SignInClient( return client::ApiError::Cancelled(); } - auto client = CreateOlpClient(settings_, boost::none, false); + auto client = CreateOlpClient(settings_, porting::none, false); RequestTimer timer = CreateRequestTimer(client, context); diff --git a/olp-cpp-sdk-authentication/src/TokenEndpointImpl.h b/olp-cpp-sdk-authentication/src/TokenEndpointImpl.h index 9688302ea..639f57f6a 100644 --- a/olp-cpp-sdk-authentication/src/TokenEndpointImpl.h +++ b/olp-cpp-sdk-authentication/src/TokenEndpointImpl.h @@ -19,7 +19,6 @@ #pragma once -#include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include "TokenRequest.h" namespace olp { @@ -90,7 +90,7 @@ class TokenEndpointImpl { client::CancellationContext& context) const; const AuthenticationCredentials credentials_; - const boost::optional scope_; + const porting::optional scope_; const AuthenticationSettings settings_; AuthenticationClient auth_client_; }; diff --git a/olp-cpp-sdk-authentication/src/TokenResult.cpp b/olp-cpp-sdk-authentication/src/TokenResult.cpp index 9b754b97d..eecf2c1bf 100644 --- a/olp-cpp-sdk-authentication/src/TokenResult.cpp +++ b/olp-cpp-sdk-authentication/src/TokenResult.cpp @@ -22,7 +22,7 @@ namespace olp { namespace authentication { TokenResult::TokenResult(std::string access_token, time_t expiry_time, - boost::optional scope) + porting::optional scope) : access_token_(std::move(access_token)), expiry_time_(expiry_time), scope_(std::move(scope)) { @@ -33,7 +33,7 @@ TokenResult::TokenResult(std::string access_token, time_t expiry_time, TokenResult::TokenResult(std::string access_token, std::chrono::seconds expires_in, - boost::optional scope) + porting::optional scope) : access_token_(std::move(access_token)), expires_in_(expires_in), scope_(std::move(scope)) { @@ -46,7 +46,7 @@ time_t TokenResult::GetExpiryTime() const { return expiry_time_; } std::chrono::seconds TokenResult::GetExpiresIn() const { return expires_in_; } -const boost::optional& TokenResult::GetScope() const { +const porting::optional& TokenResult::GetScope() const { return scope_; } diff --git a/olp-cpp-sdk-authentication/tests/DecisionApiClientTest.cpp b/olp-cpp-sdk-authentication/tests/DecisionApiClientTest.cpp index af1df3cac..bc1b455db 100644 --- a/olp-cpp-sdk-authentication/tests/DecisionApiClientTest.cpp +++ b/olp-cpp-sdk-authentication/tests/DecisionApiClientTest.cpp @@ -27,11 +27,9 @@ namespace auth = olp::authentication; TEST(DecisionApiClientTest, AuthorizeRequestTest) { EXPECT_EQ(auth::AuthorizeRequest().WithServiceId("ServiceId").GetServiceId(), "ServiceId"); - EXPECT_EQ(auth::AuthorizeRequest() - .WithContractId("ContractId") - .GetContractId() - .get(), - "ContractId"); + EXPECT_EQ( + *auth::AuthorizeRequest().WithContractId("ContractId").GetContractId(), + "ContractId"); auto request = auth::AuthorizeRequest().WithAction("action1").WithAction( "action2", std::string("hrn::test")); EXPECT_EQ(auth::AuthorizeRequest().GetDiagnostics(), false);