Skip to content

Commit 2e338ea

Browse files
committed
Fix policyBuilder
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 968e6b9 commit 2e338ea

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

experimental/fluent/func/src/test/java/io/serverlessworkflow/fluent/func/FuncDSLTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.listen;
2525
import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.toOne;
2626
import static io.serverlessworkflow.fluent.spec.dsl.DSL.auth;
27+
import static io.serverlessworkflow.fluent.spec.dsl.DSL.use;
2728
import static org.junit.jupiter.api.Assertions.assertEquals;
2829
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
2930
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -263,7 +264,7 @@ void get_convenience_creates_http_get() {
263264
void get_named_with_authentication_uses_auth_policy() {
264265
Workflow wf =
265266
FuncWorkflowBuilder.workflow("http-get-auth")
266-
.tasks(get("fetchUsers", "http://service/api/users", auth("user-service-auth")))
267+
.tasks(get("fetchUsers", "http://service/api/users", use("user-service-auth")))
267268
.build();
268269

269270
List<TaskItem> items = wf.getDo();

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/ReferenceableAuthenticationPolicyBuilder.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,44 @@
2121
import java.util.function.Consumer;
2222

2323
public class ReferenceableAuthenticationPolicyBuilder {
24-
final AuthenticationPolicyUnion authenticationPolicy;
25-
final AuthenticationPolicyReference authenticationPolicyReference;
24+
private AuthenticationPolicyUnion authenticationPolicy;
25+
private AuthenticationPolicyReference authenticationPolicyReference;
2626

27-
public ReferenceableAuthenticationPolicyBuilder() {
28-
this.authenticationPolicy = new AuthenticationPolicyUnion();
29-
this.authenticationPolicyReference = new AuthenticationPolicyReference();
30-
}
27+
public ReferenceableAuthenticationPolicyBuilder() {}
3128

3229
public ReferenceableAuthenticationPolicyBuilder basic(
3330
Consumer<BasicAuthenticationPolicyBuilder> basicConsumer) {
34-
final BasicAuthenticationPolicyBuilder basicAuthenticationPolicyBuilder =
35-
new BasicAuthenticationPolicyBuilder();
36-
basicConsumer.accept(basicAuthenticationPolicyBuilder);
37-
this.authenticationPolicy.setBasicAuthenticationPolicy(
38-
basicAuthenticationPolicyBuilder.build());
31+
final BasicAuthenticationPolicyBuilder builder = new BasicAuthenticationPolicyBuilder();
32+
basicConsumer.accept(builder);
33+
this.authenticationPolicy =
34+
new AuthenticationPolicyUnion().withBasicAuthenticationPolicy(builder.build());
3935
return this;
4036
}
4137

4238
public ReferenceableAuthenticationPolicyBuilder bearer(
4339
Consumer<BearerAuthenticationPolicyBuilder> bearerConsumer) {
44-
final BearerAuthenticationPolicyBuilder bearerAuthenticationPolicyBuilder =
45-
new BearerAuthenticationPolicyBuilder();
46-
bearerConsumer.accept(bearerAuthenticationPolicyBuilder);
47-
this.authenticationPolicy.setBearerAuthenticationPolicy(
48-
bearerAuthenticationPolicyBuilder.build());
40+
final BearerAuthenticationPolicyBuilder builder = new BearerAuthenticationPolicyBuilder();
41+
bearerConsumer.accept(builder);
42+
this.authenticationPolicy =
43+
new AuthenticationPolicyUnion().withBearerAuthenticationPolicy(builder.build());
4944
return this;
5045
}
5146

5247
public ReferenceableAuthenticationPolicyBuilder digest(
5348
Consumer<DigestAuthenticationPolicyBuilder> digestConsumer) {
54-
final DigestAuthenticationPolicyBuilder digestAuthenticationPolicyBuilder =
55-
new DigestAuthenticationPolicyBuilder();
56-
digestConsumer.accept(digestAuthenticationPolicyBuilder);
57-
this.authenticationPolicy.setDigestAuthenticationPolicy(
58-
digestAuthenticationPolicyBuilder.build());
49+
final DigestAuthenticationPolicyBuilder builder = new DigestAuthenticationPolicyBuilder();
50+
digestConsumer.accept(builder);
51+
this.authenticationPolicy =
52+
new AuthenticationPolicyUnion().withDigestAuthenticationPolicy(builder.build());
5953
return this;
6054
}
6155

6256
public ReferenceableAuthenticationPolicyBuilder oauth2(
6357
Consumer<OAuth2AuthenticationPolicyBuilder> oauth2Consumer) {
64-
final OAuth2AuthenticationPolicyBuilder oauth2AuthenticationPolicyBuilder =
65-
new OAuth2AuthenticationPolicyBuilder();
66-
oauth2Consumer.accept(oauth2AuthenticationPolicyBuilder);
67-
this.authenticationPolicy.setOAuth2AuthenticationPolicy(
68-
oauth2AuthenticationPolicyBuilder.build());
58+
final OAuth2AuthenticationPolicyBuilder builder = new OAuth2AuthenticationPolicyBuilder();
59+
oauth2Consumer.accept(builder);
60+
this.authenticationPolicy =
61+
new AuthenticationPolicyUnion().withOAuth2AuthenticationPolicy(builder.build());
6962
return this;
7063
}
7164

@@ -74,12 +67,13 @@ public ReferenceableAuthenticationPolicyBuilder openIDConnect(
7467
final OpenIdConnectAuthenticationPolicyBuilder builder =
7568
new OpenIdConnectAuthenticationPolicyBuilder();
7669
openIdConnectConsumer.accept(builder);
77-
this.authenticationPolicy.setOpenIdConnectAuthenticationPolicy(builder.build());
70+
this.authenticationPolicy =
71+
new AuthenticationPolicyUnion().withOpenIdConnectAuthenticationPolicy(builder.build());
7872
return this;
7973
}
8074

8175
public ReferenceableAuthenticationPolicyBuilder use(String use) {
82-
this.authenticationPolicyReference.setUse(use);
76+
this.authenticationPolicyReference = new AuthenticationPolicyReference().withUse(use);
8377
return this;
8478
}
8579

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/DSL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public static Consumer<TryTaskBuilder.CatchErrorsBuilder> errorFilter(
319319
* @param authName the name of a reusable authentication policy
320320
* @return an {@link AuthenticationConfigurer} that sets {@code use(authName)}
321321
*/
322-
public static AuthenticationConfigurer auth(String authName) {
322+
public static AuthenticationConfigurer use(String authName) {
323323
return a -> a.use(authName);
324324
}
325325

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/CallHttpTaskFluent.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.serverlessworkflow.api.types.CallHTTP;
2020
import io.serverlessworkflow.api.types.Endpoint;
2121
import io.serverlessworkflow.api.types.EndpointConfiguration;
22+
import io.serverlessworkflow.api.types.EndpointUri;
2223
import io.serverlessworkflow.api.types.HTTPArguments;
2324
import io.serverlessworkflow.api.types.HTTPHeaders;
2425
import io.serverlessworkflow.api.types.HTTPQuery;
@@ -59,14 +60,17 @@ default SELF endpoint(URI endpoint) {
5960
default SELF endpoint(URI endpoint, Consumer<ReferenceableAuthenticationPolicyBuilder> auth) {
6061
final ReferenceableAuthenticationPolicyBuilder policy =
6162
new ReferenceableAuthenticationPolicyBuilder();
63+
final UriTemplate uriTemplate = new UriTemplate().withLiteralUri(endpoint);
6264
auth.accept(policy);
6365
((CallHTTP) this.self().getTask())
6466
.getWith()
6567
.setEndpoint(
6668
new Endpoint()
6769
.withEndpointConfiguration(
68-
new EndpointConfiguration().withAuthentication(policy.build()))
69-
.withUriTemplate(new UriTemplate().withLiteralUri(endpoint)));
70+
new EndpointConfiguration()
71+
.withUri(new EndpointUri().withLiteralEndpointURI(uriTemplate))
72+
.withAuthentication(policy.build()))
73+
.withUriTemplate(uriTemplate));
7074
return self();
7175
}
7276

0 commit comments

Comments
 (0)