Skip to content

Commit c9c41eb

Browse files
authored
[Fix #930] Adding authorization runtime expression (#940)
Signed-off-by: fjtirado <ftirados@redhat.com>
1 parent 0ac2c5e commit c9c41eb

File tree

52 files changed

+405
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+405
-125
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
public record AuthorizationDescriptor(String scheme, String parameter) {}

impl/core/src/main/java/io/serverlessworkflow/impl/TaskContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class TaskContext implements TaskContextData {
3838
private Instant completedAt;
3939
private TransitionInfo transition;
4040
private short retryAttempt;
41+
private AuthorizationDescriptor authorization;
4142

4243
public TaskContext(
4344
WorkflowModel input,
@@ -93,6 +94,14 @@ public WorkflowModel rawInput() {
9394
return rawInput;
9495
}
9596

97+
public AuthorizationDescriptor authorization() {
98+
return authorization;
99+
}
100+
101+
public void authorization(String scheme, String parameter) {
102+
this.authorization = new AuthorizationDescriptor(scheme, parameter);
103+
}
104+
96105
@Override
97106
public TaskBase task() {
98107
return task;

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.serverlessworkflow.api.types.Workflow;
2222
import io.serverlessworkflow.impl.additional.WorkflowAdditionalObject;
2323
import io.serverlessworkflow.impl.config.ConfigManager;
24+
import io.serverlessworkflow.impl.config.ConfigSecretManager;
2425
import io.serverlessworkflow.impl.config.SecretManager;
2526
import io.serverlessworkflow.impl.config.SystemPropertyConfigManager;
2627
import io.serverlessworkflow.impl.events.EventConsumer;
@@ -316,7 +317,7 @@ public WorkflowApplication build() {
316317
secretManager =
317318
ServiceLoader.load(SecretManager.class)
318319
.findFirst()
319-
.orElseGet(() -> s -> configManager.config(s, String.class));
320+
.orElseGet(() -> new ConfigSecretManager(configManager));
320321
}
321322
return new WorkflowApplication(this);
322323
}

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowError.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public static Builder authorization() {
2828
return error(Errors.AUTHORIZATION.toString(), Errors.AUTHORIZATION.status());
2929
}
3030

31+
public static Builder expression() {
32+
return error("https://serverlessworkflow.io/spec/1.0.0/errors/expression", 400);
33+
}
34+
3135
public static Builder communication(int status, TaskContext context, Exception ex) {
3236
return communication(status, context, ex.getMessage());
3337
}

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowInstanceData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ public interface WorkflowInstanceData {
3030

3131
WorkflowModel output();
3232

33+
WorkflowModel context();
34+
3335
<T> T outputAs(Class<T> clazz);
3436
}

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowMutableInstance.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ public WorkflowStatus status() {
145145
return status.get();
146146
}
147147

148+
@Override
149+
public WorkflowModel context() {
150+
return workflowContext.context();
151+
}
152+
148153
@Override
149154
public WorkflowModel output() {
150155
CompletableFuture<WorkflowModel> future = futureRef.get();

impl/core/src/main/java/io/serverlessworkflow/impl/additional/ConstantAdditionalObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package io.serverlessworkflow.impl.additional;
1717

18-
import io.serverlessworkflow.impl.TaskContext;
19-
import io.serverlessworkflow.impl.WorkflowContext;
18+
import io.serverlessworkflow.impl.TaskContextData;
19+
import io.serverlessworkflow.impl.WorkflowContextData;
2020

2121
public class ConstantAdditionalObject<T> implements WorkflowAdditionalObject<T> {
2222

@@ -27,7 +27,7 @@ public ConstantAdditionalObject(T object) {
2727
}
2828

2929
@Override
30-
public T apply(WorkflowContext t, TaskContext u) {
30+
public T apply(WorkflowContextData t, TaskContextData u) {
3131
return object;
3232
}
3333
}

impl/core/src/main/java/io/serverlessworkflow/impl/additional/SuppliedAdditionalObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package io.serverlessworkflow.impl.additional;
1717

18-
import io.serverlessworkflow.impl.TaskContext;
19-
import io.serverlessworkflow.impl.WorkflowContext;
18+
import io.serverlessworkflow.impl.TaskContextData;
19+
import io.serverlessworkflow.impl.WorkflowContextData;
2020
import java.util.function.Supplier;
2121

2222
public class SuppliedAdditionalObject<T> implements WorkflowAdditionalObject<T> {
@@ -28,7 +28,7 @@ public SuppliedAdditionalObject(Supplier<T> supplier) {
2828
}
2929

3030
@Override
31-
public T apply(WorkflowContext t, TaskContext u) {
31+
public T apply(WorkflowContextData t, TaskContextData u) {
3232
return supplier.get();
3333
}
3434
}

impl/core/src/main/java/io/serverlessworkflow/impl/additional/WorkflowAdditionalObject.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616
package io.serverlessworkflow.impl.additional;
1717

18-
import io.serverlessworkflow.impl.TaskContext;
19-
import io.serverlessworkflow.impl.WorkflowContext;
18+
import io.serverlessworkflow.impl.TaskContextData;
19+
import io.serverlessworkflow.impl.WorkflowContextData;
2020
import java.util.function.BiFunction;
2121

22-
public interface WorkflowAdditionalObject<T> extends BiFunction<WorkflowContext, TaskContext, T> {}
22+
public interface WorkflowAdditionalObject<T>
23+
extends BiFunction<WorkflowContextData, TaskContextData, T> {}

impl/core/src/main/java/io/serverlessworkflow/impl/config/ConfigManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
import java.util.Optional;
2020

2121
public interface ConfigManager extends ServicePriority {
22+
2223
<T> Optional<T> config(String propName, Class<T> propClass);
24+
25+
Iterable<String> names();
2326
}

0 commit comments

Comments
 (0)