Skip to content

Commit

Permalink
tsp, generic KeyCredentialPolicy ctor has 3 arguments (#2613)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Mar 8, 2024
1 parent 8346de4 commit 20a8da4
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,18 @@ public static void createHttpPipelineMethod(JavaSettings settings, String defaul
}

private static void createGenericHttpPipelineMethod(JavaSettings settings, String defaultCredentialScopes, SecurityInfo securityInfo, PipelinePolicyDetails pipelinePolicyDetails, JavaBlock function) {
// TODO: generic "createDefaultPipeline" not ready
// function.line("HttpPipeline httpPipeline = HttpPipelineBuilder.createDefaultPipeline();");
// function.methodReturn("httpPipeline");
// // TODO: default pipeline is immutable and we need to add KeyCredential policy to the pipeline depending on securityInfo.

function.line("HttpPipelineBuilder httpPipelineBuilder = new HttpPipelineBuilder();");
if (securityInfo.getSecurityTypes().contains(Scheme.SecuritySchemeType.KEY)) {
function.line("List<HttpPipelinePolicy> policies = new ArrayList<>();");
function.ifBlock("keyCredential != null", action -> {
if (CoreUtils.isNullOrEmpty(securityInfo.getHeaderValuePrefix())) {
function.line("policies.add(new KeyCredentialPolicy(\""
+ securityInfo.getHeaderName()
+ "\", keyCredential));");
} else {
function.line("policies.add(new KeyCredentialPolicy(\""
+ securityInfo.getHeaderName()
+ "\", keyCredential, \""
+ securityInfo.getHeaderValuePrefix()
+ "\"));");
}
final String prefixExpr = CoreUtils.isNullOrEmpty(securityInfo.getHeaderValuePrefix())
? "null"
: ClassType.STRING.defaultValueExpression(securityInfo.getHeaderValuePrefix());
function.line("policies.add(new KeyCredentialPolicy(\""
+ securityInfo.getHeaderName()
+ "\", keyCredential, "
+ prefixExpr
+ "));");
});
function.line("httpPipelineBuilder.policies(policies.toArray(new HttpPipelinePolicy[0]));");
}
Expand Down

0 comments on commit 20a8da4

Please sign in to comment.