Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <aws/core/auth/bearer-token-provider/AWSBearerTokenProviderBase.h>
#include <aws/core/auth/bearer-token-provider/DefaultBearerTokenProviderChain.h>
#include <aws/core/auth/bearer-token-provider/SSOBearerTokenProvider.h>
#include <aws/core/auth/bearer-token-provider/StaticBearerTokenProvider.h>
#include <aws/core/auth/signer-provider/BearerTokenAuthSignerProvider.h>
#include <aws/core/auth/signer/AWSAuthBearerSigner.h>
#include <aws/core/platform/Environment.h>
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
#include <smithy/identity/resolver/AwsBearerTokenIdentityResolver.h>
#include <smithy/identity/resolver/AwsIdentityResolverBase.h>

namespace Aws {
namespace BedrockAgentRuntime {

class BedrockAgentRuntimeAwsBearerTokenIdentityResolver : public smithy::AwsBearerTokenIdentityResolver {
public:
using IdentityT = smithy::AwsBearerTokenIdentity;
virtual ~BedrockAgentRuntimeAwsBearerTokenIdentityResolver() = default;

BedrockAgentRuntimeAwsBearerTokenIdentityResolver() {
m_providerChainLegacy.emplace_back(Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>("SSOBearerTokenProvider"));
const Aws::String bedrockToken = Aws::Environment::GetEnv("AWS_BEARER_TOKEN_BEDROCK");
if (!bedrockToken.empty()) {
m_providerChainLegacy.emplace_back(
Aws::MakeShared<Aws::Auth::StaticAWSBearerTokenProvider>("StaticAWSBearerTokenProvider", bedrockToken));
}
};

BedrockAgentRuntimeAwsBearerTokenIdentityResolver(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration &config) {
m_providerChainLegacy.emplace_back(Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>("SSOBearerTokenProvider", config.profile));
const Aws::String bedrockToken = Aws::Environment::GetEnv("AWS_BEARER_TOKEN_BEDROCK");
if (!bedrockToken.empty()) {
m_providerChainLegacy.emplace_back(
Aws::MakeShared<Aws::Auth::StaticAWSBearerTokenProvider>("StaticAWSBearerTokenProvider", bedrockToken));
}
}

ResolveIdentityFutureOutcome virtual getIdentity(const IdentityProperties &identityProperties,
const AdditionalParameters &additionalParameters) override {
auto outcome = AwsBearerTokenIdentityResolver::getIdentity(identityProperties, additionalParameters);
outcome.GetResult()->AddUserAgentFeature(Aws::Client::UserAgentFeature::BEARER_SERVICE_ENV_VARS);
return outcome;
}
};

} // namespace BedrockAgentRuntime
} // namespace Aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#pragma once

#include <aws/bedrock-agent-runtime/BedrockAgentRuntime_EXPORTS.h>
#include <aws/core/client/GenericClientConfiguration.h>

namespace Aws {
namespace BedrockAgentRuntime {
struct AWS_BEDROCKAGENTRUNTIME_API BedrockAgentRuntimeClientConfiguration : public Aws::Client::GenericClientConfiguration {
using BaseClientConfigClass = Aws::Client::GenericClientConfiguration;

BedrockAgentRuntimeClientConfiguration(const Client::ClientConfigurationInitValues& configuration = {});

/**
* Create a configuration based on settings in the aws configuration file for the given profile name.
* The configuration file location can be set via the environment variable AWS_CONFIG_FILE
* @param profileName the aws profile name.
* @param shouldDisableIMDS whether or not to disable IMDS calls.
*/
BedrockAgentRuntimeClientConfiguration(const char* profileName, bool shouldDisableIMDS = false);

/**
* Create a configuration with a predefined smart defaults
* @param useSmartDefaults, required to differentiate c-tors
* @param defaultMode, default mode to use
* @param shouldDisableIMDS whether or not to disable IMDS calls.
*/
BedrockAgentRuntimeClientConfiguration(bool useSmartDefaults, const char* defaultMode = "legacy", bool shouldDisableIMDS = false);

/**
* Converting constructors for compatibility with a legacy code
*/
BedrockAgentRuntimeClientConfiguration(const Client::ClientConfiguration& config);

private:
void LoadBedrockAgentRuntimeSpecificConfig(const Aws::String& profileName);
};
} // namespace BedrockAgentRuntime
} // namespace Aws
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

#pragma once
#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeClientConfiguration.h>
#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeEndpointRules.h>
#include <aws/bedrock-agent-runtime/BedrockAgentRuntime_EXPORTS.h>
#include <aws/core/client/GenericClientConfiguration.h>
#include <aws/core/endpoint/DefaultEndpointProvider.h>
#include <aws/core/endpoint/EndpointParameter.h>
#include <aws/core/utils/memory/stl/AWSString.h>
Expand All @@ -15,14 +15,19 @@
namespace Aws {
namespace BedrockAgentRuntime {
namespace Endpoint {
using BedrockAgentRuntimeClientConfiguration = Aws::BedrockAgentRuntime::BedrockAgentRuntimeClientConfiguration;
using EndpointParameters = Aws::Endpoint::EndpointParameters;
using Aws::Endpoint::DefaultEndpointProvider;
using Aws::Endpoint::EndpointProviderBase;

using BedrockAgentRuntimeClientContextParameters = Aws::Endpoint::ClientContextParameters;

using BedrockAgentRuntimeClientConfiguration = Aws::Client::GenericClientConfiguration;
using BedrockAgentRuntimeBuiltInParameters = Aws::Endpoint::BuiltInParameters;
class AWS_BEDROCKAGENTRUNTIME_API BedrockAgentRuntimeBuiltInParameters : public Aws::Endpoint::BuiltInParameters {
public:
virtual ~BedrockAgentRuntimeBuiltInParameters() {};
using Aws::Endpoint::BuiltInParameters::SetFromClientConfiguration;
virtual void SetFromClientConfiguration(const BedrockAgentRuntimeClientConfiguration& config);
};

/**
* The type for the BedrockAgentRuntime Client Endpoint Provider.
Expand All @@ -37,6 +42,26 @@ using BedrockAgentRuntimeDefaultEpProviderBase =
DefaultEndpointProvider<BedrockAgentRuntimeClientConfiguration, BedrockAgentRuntimeBuiltInParameters,
BedrockAgentRuntimeClientContextParameters>;

} // namespace Endpoint
} // namespace BedrockAgentRuntime

namespace Endpoint {
/**
* Export endpoint provider symbols for Windows DLL, otherwise declare as extern
*/
AWS_BEDROCKAGENTRUNTIME_EXTERN template class AWS_BEDROCKAGENTRUNTIME_API
Aws::Endpoint::EndpointProviderBase<BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientConfiguration,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeBuiltInParameters,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientContextParameters>;

AWS_BEDROCKAGENTRUNTIME_EXTERN template class AWS_BEDROCKAGENTRUNTIME_API
Aws::Endpoint::DefaultEndpointProvider<BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientConfiguration,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeBuiltInParameters,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientContextParameters>;
} // namespace Endpoint

namespace BedrockAgentRuntime {
namespace Endpoint {
/**
* Default endpoint provider used for this service
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class RetryStrategy;
} // namespace Client

namespace BedrockAgentRuntime {
using BedrockAgentRuntimeClientConfiguration = Aws::Client::GenericClientConfiguration;
using BedrockAgentRuntimeEndpointProviderBase = Aws::BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeEndpointProviderBase;
using BedrockAgentRuntimeEndpointProvider = Aws::BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeEndpointProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeAwsBearerTokenIdentityResolver.h>
#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeClient.h>
#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeEndpointProvider.h>
#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeErrorMarshaller.h>
Expand Down Expand Up @@ -118,17 +119,16 @@ BedrockAgentRuntimeClient::BedrockAgentRuntimeClient(const std::shared_ptr<AWSCr

/* Legacy constructors due deprecation */
BedrockAgentRuntimeClient::BedrockAgentRuntimeClient(const Client::ClientConfiguration& clientConfiguration)
: AwsSmithyClientT(clientConfiguration, GetServiceName(), "Bedrock Agent Runtime", Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<BedrockAgentRuntimeErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<BedrockAgentRuntimeEndpointProvider>(ALLOCATION_TAG),
Aws::MakeShared<smithy::GenericAuthSchemeResolver<>>(
ALLOCATION_TAG, Aws::Vector<smithy::AuthSchemeOption>({smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption})),
{
{smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption.schemeId,
smithy::SigV4AuthScheme{Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(
ALLOCATION_TAG, clientConfiguration.credentialProviderConfig),
GetServiceName(), clientConfiguration.region}},
}) {}
: AwsSmithyClientT(
clientConfiguration, GetServiceName(), "Bedrock Agent Runtime", Aws::Http::CreateHttpClient(clientConfiguration),
Aws::MakeShared<BedrockAgentRuntimeErrorMarshaller>(ALLOCATION_TAG),
Aws::MakeShared<BedrockAgentRuntimeEndpointProvider>(ALLOCATION_TAG),
Aws::MakeShared<smithy::GenericAuthSchemeResolver<>>(
ALLOCATION_TAG, Aws::Vector<smithy::AuthSchemeOption>({smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption})),
{
{smithy::SigV4AuthSchemeOption::sigV4AuthSchemeOption.schemeId,
smithy::SigV4AuthScheme{GetServiceName(), clientConfiguration.region, clientConfiguration.credentialProviderConfig}},
}) {}

BedrockAgentRuntimeClient::BedrockAgentRuntimeClient(const AWSCredentials& credentials,
const Client::ClientConfiguration& clientConfiguration)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeClientConfiguration.h>

namespace Aws {
namespace BedrockAgentRuntime {

static const char AWS_BEARER_TOKEN_BEDROCK[] = "AWS_BEARER_TOKEN_BEDROCK";

void BedrockAgentRuntimeClientConfiguration::LoadBedrockAgentRuntimeSpecificConfig(const Aws::String& inputProfileName) {
const Aws::String& bedrockToken =
BaseClientConfigClass::LoadConfigFromEnvOrProfile(AWS_BEARER_TOKEN_BEDROCK, inputProfileName, AWS_BEARER_TOKEN_BEDROCK, {}, "");
if (!bedrockToken.empty()) {
Aws::Vector<Aws::String>::iterator position = std::find(authPreferences.begin(), authPreferences.end(), "bearer");
if (position != authPreferences.end()) {
authPreferences.erase(position);
}
authPreferences.insert(authPreferences.begin(), "bearer");
}
}

BedrockAgentRuntimeClientConfiguration::BedrockAgentRuntimeClientConfiguration(const Client::ClientConfigurationInitValues& configuration)
: BaseClientConfigClass(configuration) {
LoadBedrockAgentRuntimeSpecificConfig(this->profileName);
}

BedrockAgentRuntimeClientConfiguration::BedrockAgentRuntimeClientConfiguration(const char* inputProfileName, bool shouldDisableIMDS)
: BaseClientConfigClass(inputProfileName, shouldDisableIMDS) {
LoadBedrockAgentRuntimeSpecificConfig(Aws::String(inputProfileName));
}

BedrockAgentRuntimeClientConfiguration::BedrockAgentRuntimeClientConfiguration(bool useSmartDefaults, const char* defaultMode,
bool shouldDisableIMDS)
: BaseClientConfigClass(useSmartDefaults, defaultMode, shouldDisableIMDS) {
LoadBedrockAgentRuntimeSpecificConfig(this->profileName);
}

BedrockAgentRuntimeClientConfiguration::BedrockAgentRuntimeClientConfiguration(const Client::ClientConfiguration& config)
: BaseClientConfigClass(config) {
LoadBedrockAgentRuntimeSpecificConfig(this->profileName);
}

} // namespace BedrockAgentRuntime
} // namespace Aws
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@
#include <aws/bedrock-agent-runtime/BedrockAgentRuntimeEndpointProvider.h>

namespace Aws {
#ifndef AWS_BEDROCKAGENTRUNTIME_EXPORTS // Except for Windows DLL
namespace Endpoint {
/**
* Instantiate endpoint providers
*/
template class Aws::Endpoint::EndpointProviderBase<BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientConfiguration,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeBuiltInParameters,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientContextParameters>;

template class Aws::Endpoint::DefaultEndpointProvider<BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientConfiguration,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeBuiltInParameters,
BedrockAgentRuntime::Endpoint::BedrockAgentRuntimeClientContextParameters>;
} // namespace Endpoint
#endif

namespace BedrockAgentRuntime {
namespace Endpoint {} // namespace Endpoint
namespace Endpoint {
void BedrockAgentRuntimeBuiltInParameters::SetFromClientConfiguration(const BedrockAgentRuntimeClientConfiguration& config) {
SetFromClientConfiguration(static_cast<const BedrockAgentRuntimeClientConfiguration::BaseClientConfigClass&>(config));
}

} // namespace Endpoint
} // namespace BedrockAgentRuntime
} // namespace Aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <aws/core/auth/bearer-token-provider/AWSBearerTokenProviderBase.h>
#include <aws/core/auth/bearer-token-provider/DefaultBearerTokenProviderChain.h>
#include <aws/core/auth/bearer-token-provider/SSOBearerTokenProvider.h>
#include <aws/core/auth/bearer-token-provider/StaticBearerTokenProvider.h>
#include <aws/core/auth/signer-provider/BearerTokenAuthSignerProvider.h>
#include <aws/core/auth/signer/AWSAuthBearerSigner.h>
#include <aws/core/platform/Environment.h>
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
#include <smithy/identity/resolver/AwsBearerTokenIdentityResolver.h>
#include <smithy/identity/resolver/AwsIdentityResolverBase.h>

namespace Aws {
namespace BedrockAgent {

class BedrockAgentAwsBearerTokenIdentityResolver : public smithy::AwsBearerTokenIdentityResolver {
public:
using IdentityT = smithy::AwsBearerTokenIdentity;
virtual ~BedrockAgentAwsBearerTokenIdentityResolver() = default;

BedrockAgentAwsBearerTokenIdentityResolver() {
m_providerChainLegacy.emplace_back(Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>("SSOBearerTokenProvider"));
const Aws::String bedrockToken = Aws::Environment::GetEnv("AWS_BEARER_TOKEN_BEDROCK");
if (!bedrockToken.empty()) {
m_providerChainLegacy.emplace_back(
Aws::MakeShared<Aws::Auth::StaticAWSBearerTokenProvider>("StaticAWSBearerTokenProvider", bedrockToken));
}
};

BedrockAgentAwsBearerTokenIdentityResolver(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration &config) {
m_providerChainLegacy.emplace_back(Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>("SSOBearerTokenProvider", config.profile));
const Aws::String bedrockToken = Aws::Environment::GetEnv("AWS_BEARER_TOKEN_BEDROCK");
if (!bedrockToken.empty()) {
m_providerChainLegacy.emplace_back(
Aws::MakeShared<Aws::Auth::StaticAWSBearerTokenProvider>("StaticAWSBearerTokenProvider", bedrockToken));
}
}

ResolveIdentityFutureOutcome virtual getIdentity(const IdentityProperties &identityProperties,
const AdditionalParameters &additionalParameters) override {
auto outcome = AwsBearerTokenIdentityResolver::getIdentity(identityProperties, additionalParameters);
outcome.GetResult()->AddUserAgentFeature(Aws::Client::UserAgentFeature::BEARER_SERVICE_ENV_VARS);
return outcome;
}
};

} // namespace BedrockAgent
} // namespace Aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#pragma once

#include <aws/bedrock-agent/BedrockAgent_EXPORTS.h>
#include <aws/core/client/GenericClientConfiguration.h>

namespace Aws {
namespace BedrockAgent {
struct AWS_BEDROCKAGENT_API BedrockAgentClientConfiguration : public Aws::Client::GenericClientConfiguration {
using BaseClientConfigClass = Aws::Client::GenericClientConfiguration;

BedrockAgentClientConfiguration(const Client::ClientConfigurationInitValues& configuration = {});

/**
* Create a configuration based on settings in the aws configuration file for the given profile name.
* The configuration file location can be set via the environment variable AWS_CONFIG_FILE
* @param profileName the aws profile name.
* @param shouldDisableIMDS whether or not to disable IMDS calls.
*/
BedrockAgentClientConfiguration(const char* profileName, bool shouldDisableIMDS = false);

/**
* Create a configuration with a predefined smart defaults
* @param useSmartDefaults, required to differentiate c-tors
* @param defaultMode, default mode to use
* @param shouldDisableIMDS whether or not to disable IMDS calls.
*/
BedrockAgentClientConfiguration(bool useSmartDefaults, const char* defaultMode = "legacy", bool shouldDisableIMDS = false);

/**
* Converting constructors for compatibility with a legacy code
*/
BedrockAgentClientConfiguration(const Client::ClientConfiguration& config);

private:
void LoadBedrockAgentSpecificConfig(const Aws::String& profileName);
};
} // namespace BedrockAgent
} // namespace Aws
Loading
Loading