unit test for EndpointProvider and StsAssumeRoleCrendentialsProvider
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -58,7 +58,7 @@ void CoreClient::asyncExecute(Runnable * r)const
|
||||
HttpClient::HttpResponseOutcome CoreClient::AttemptRequest(const std::string & endpoint, const ServiceRequest & request, HttpRequest::Method method) const
|
||||
{
|
||||
auto r = buildHttpRequest(endpoint, request, method);
|
||||
auto outcome = httpClient_->makeRequest(r);
|
||||
auto outcome = httpClient_->makeRequest(r);
|
||||
if (!outcome.isSuccess())
|
||||
return outcome;
|
||||
if(hasResponseError(outcome.result()))
|
||||
|
||||
@@ -82,8 +82,14 @@ namespace
|
||||
"]}";
|
||||
}
|
||||
|
||||
EndpointProvider::EndpointProvider(const std::shared_ptr<Location::LocationClient>& locationClient, const std::string regionId, const std::string product, const std::string serviceCode, int durationSeconds) :
|
||||
locationClient_(locationClient),
|
||||
EndpointProvider::EndpointProvider(
|
||||
const Credentials& credentials,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::string ®ionId,
|
||||
const std::string &product,
|
||||
const std::string &serviceCode,
|
||||
int durationSeconds) :
|
||||
LocationClient(credentials, configuration),
|
||||
regionId_(regionId),
|
||||
product_(product),
|
||||
serviceCode_(serviceCode),
|
||||
@@ -157,8 +163,8 @@ std::string EndpointProvider::internalEndpoint(const std::string regionId, const
|
||||
|
||||
EndpointProvider::EndpointOutcome EndpointProvider::getEndpoint()
|
||||
{
|
||||
if (!locationClient_->configuration().endpoint().empty())
|
||||
return EndpointOutcome(locationClient_->configuration().endpoint());
|
||||
if (!configuration().endpoint().empty())
|
||||
return EndpointOutcome(configuration().endpoint());
|
||||
|
||||
if (!serviceCode_.empty())
|
||||
{
|
||||
@@ -188,7 +194,7 @@ EndpointProvider::EndpointOutcome EndpointProvider::loadRemoteEndpoint()
|
||||
request.setId(regionId_);
|
||||
request.setServiceCode(serviceCode_);
|
||||
request.setType("openAPI");
|
||||
auto outcome = locationClient_->describeEndpoints(request);
|
||||
auto outcome = describeEndpoints(request);
|
||||
if (!outcome.isSuccess())
|
||||
return EndpointOutcome(outcome.error());
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -21,9 +21,15 @@
|
||||
using namespace AlibabaCloud;
|
||||
using namespace AlibabaCloud::Sts;
|
||||
|
||||
StsAssumeRoleCredentialsProvider::StsAssumeRoleCredentialsProvider(const std::shared_ptr<StsClient>& stsClient, const std::string & roleArn, const std::string & roleSessionName, const std::string & policy, int durationSeconds) :
|
||||
StsAssumeRoleCredentialsProvider::StsAssumeRoleCredentialsProvider(
|
||||
const Credentials &credentials,
|
||||
const ClientConfiguration &configuration,
|
||||
const std::string & roleArn,
|
||||
const std::string & roleSessionName,
|
||||
const std::string & policy,
|
||||
int durationSeconds):
|
||||
CredentialsProvider(),
|
||||
stsClient_(stsClient),
|
||||
StsClient(credentials, configuration),
|
||||
roleArn_(roleArn),
|
||||
roleSessionName_(roleSessionName),
|
||||
policy_(policy),
|
||||
@@ -66,7 +72,7 @@ void StsAssumeRoleCredentialsProvider::loadCredentials()
|
||||
request.setPolicy(policy_);
|
||||
request.setDurationSeconds(durationSeconds_);
|
||||
|
||||
auto assumeRoleOutcome = stsClient_->assumeRole(request);
|
||||
auto assumeRoleOutcome = assumeRole(request);
|
||||
if (assumeRoleOutcome.isSuccess())
|
||||
{
|
||||
const auto stsCredentials = assumeRoleOutcome.result().credentials();
|
||||
|
||||
Reference in New Issue
Block a user