Skip to content

Commit

Permalink
Remove AWSCredentials from AuthSchemeHandler and use ClientConfig.Def…
Browse files Browse the repository at this point in the history
…aultAWSCredentials instead.
  • Loading branch information
muhammad-othman committed Nov 27, 2024
1 parent ddfbf2c commit 46cbc70
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 93 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ namespace <#=this.Config.Namespace#>.Internal
/// </summary>
public class Amazon<#=this.Config.ClassName#>AuthSchemeHandler : BaseAuthResolverHandler
{
/// <summary>
/// Construct an instance of Amazon<#=this.Config.ClassName#>AuthSchemeHandler
/// </summary>
public Amazon<#=this.Config.ClassName#>AuthSchemeHandler(AWSCredentials credentials)
: base(credentials)
{ }

<# if (IsServiceAllowListedForRulesBasedResolver()) { #>
private readonly Amazon<#=this.Config.ClassName#>EndpointResolver _endpointResolver = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)

#line default
#line hidden
this.Write("AuthSchemeHandler(this.Config.DefaultAWSCredentials));\r\n");
this.Write("AuthSchemeHandler());\r\n");

#line 236 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\ServiceClientsNetFramework.tt"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace <#=this.Config.Namespace#>
/// <param name="pipeline"></param>
protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)
{
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new Amazon<#=this.Config.ClassName#>AuthSchemeHandler(this.Config.DefaultAWSCredentials));
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new Amazon<#=this.Config.ClassName#>AuthSchemeHandler());
<#
var pipelineOverrides = this.Config.ServiceModel.Customizations.PipelineOverride;
if (pipelineOverrides != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)

#line default
#line hidden
this.Write("AuthSchemeHandler(this.Config.DefaultAWSCredentials));\r\n");
this.Write("AuthSchemeHandler());\r\n");

#line 240 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\SourceFiles\ServiceClientsNetStandard.tt"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ namespace <#=this.Config.Namespace#>
/// <param name="pipeline">Runtime pipeline for the current client.</param>
protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)
{
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new Amazon<#=this.Config.ClassName#>AuthSchemeHandler(this.Config.DefaultAWSCredentials));
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new Amazon<#=this.Config.ClassName#>AuthSchemeHandler());
<#
var pipelineOverrides = this.Config.ServiceModel.Customizations.PipelineOverride;
if (pipelineOverrides != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ public abstract class BaseAuthResolverHandler : PipelineHandler
new AwsV4AuthScheme()
};

public BaseAuthResolverHandler(AWSCredentials credentials)
{
this.DefaultAWSCredentials = credentials;
}

protected AWSCredentials DefaultAWSCredentials
{
get;
private set;
}


public override void InvokeSync(IExecutionContext executionContext)
{
PreInvoke(executionContext);
Expand Down Expand Up @@ -79,7 +67,7 @@ protected void PreInvoke(IExecutionContext executionContext)
if (scheme is AwsV4aAuthScheme || scheme is AwsV4AuthScheme)
{
// We can use DefaultAWSCredentials if it was set by the user for these schemes.
executionContext.RequestContext.Identity = this.DefaultAWSCredentials;
executionContext.RequestContext.Identity = executionContext.RequestContext.ClientConfig.DefaultAWSCredentials;
}

if (executionContext.RequestContext.Identity == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public class AmazonAutoScalingAuthSchemeParameters : IAuthSchemeParameters
/// </summary>
public class AmazonAutoScalingAuthSchemeHandler : BaseAuthResolverHandler
{
/// <summary>
/// Construct an instance of AmazonAutoScalingAuthSchemeHandler
/// </summary>
public AmazonAutoScalingAuthSchemeHandler(AWSCredentials credentials)
: base(credentials)
{ }

/// <summary>
/// Modeled auth scheme resolver for AutoScaling.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public AmazonAutoScalingClient(string awsAccessKeyId, string awsSecretAccessKey,
/// <param name="pipeline"></param>
protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)
{
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonAutoScalingAuthSchemeHandler(this.Config.DefaultAWSCredentials));
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonAutoScalingAuthSchemeHandler());
pipeline.RemoveHandler<Amazon.Runtime.Internal.EndpointResolver>();
pipeline.AddHandlerAfter<Amazon.Runtime.Internal.Marshaller>(new AmazonAutoScalingEndpointResolver());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public IAutoScalingPaginatorFactory Paginators
/// <param name="pipeline">Runtime pipeline for the current client.</param>
protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)
{
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonAutoScalingAuthSchemeHandler(this.Config.DefaultAWSCredentials));
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonAutoScalingAuthSchemeHandler());
pipeline.RemoveHandler<Amazon.Runtime.Internal.EndpointResolver>();
pipeline.AddHandlerAfter<Amazon.Runtime.Internal.Marshaller>(new AmazonAutoScalingEndpointResolver());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public class AmazonS3AuthSchemeParameters : IAuthSchemeParameters
/// </summary>
public class AmazonS3AuthSchemeHandler : BaseAuthResolverHandler
{
/// <summary>
/// Construct an instance of AmazonS3AuthSchemeHandler
/// </summary>
public AmazonS3AuthSchemeHandler(AWSCredentials credentials)
: base(credentials)
{ }

private readonly AmazonS3EndpointResolver _endpointResolver = new();

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/Services/S3/Generated/_bcl/AmazonS3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public AmazonS3Client(string awsAccessKeyId, string awsSecretAccessKey, string a
/// <param name="pipeline"></param>
protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)
{
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonS3AuthSchemeHandler(this.Config.DefaultAWSCredentials));
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonS3AuthSchemeHandler());
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.Marshaller>(new Amazon.S3.Internal.AmazonS3PreMarshallHandler());
pipeline.AddHandlerAfter<Amazon.Runtime.Internal.EndpointResolver>(new Amazon.S3.Internal.AmazonS3KmsHandler());
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.Unmarshaller>(new Amazon.S3.Internal.AmazonS3ResponseHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public IS3PaginatorFactory Paginators
/// <param name="pipeline">Runtime pipeline for the current client.</param>
protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)
{
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonS3AuthSchemeHandler(this.Config.DefaultAWSCredentials));
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.CredentialsRetriever>(new AmazonS3AuthSchemeHandler());
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.Marshaller>(new Amazon.S3.Internal.AmazonS3PreMarshallHandler());
pipeline.AddHandlerAfter<Amazon.Runtime.Internal.EndpointResolver>(new Amazon.S3.Internal.AmazonS3KmsHandler());
pipeline.AddHandlerBefore<Amazon.Runtime.Internal.Unmarshaller>(new Amazon.S3.Internal.AmazonS3ResponseHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected override void CustomizeRuntimePipeline(RuntimePipeline pipeline)
var httpHandler = new HttpHandler<Stream>(_requestFactory, this);

pipeline.ReplaceHandler<HttpHandler<Stream>>(httpHandler);
pipeline.AddHandlerBefore<CredentialsRetriever>(new AmazonElasticTranscoderAuthSchemeHandler(this.Config.DefaultAWSCredentials));
pipeline.AddHandlerBefore<CredentialsRetriever>(new AmazonElasticTranscoderAuthSchemeHandler());
}
}
}

0 comments on commit 46cbc70

Please sign in to comment.