diff --git a/build.gradle b/build.gradle index 070b75e..03b6579 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ repositories { } } -final targetJavaVersion = JavaVersion.VERSION_21 +final targetJavaVersion = JavaVersion.VERSION_25 java { sourceCompatibility = targetJavaVersion diff --git a/gradle.properties b/gradle.properties index 6da07b3..d1f2015 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,7 @@ +<<<<<<< Updated upstream version=1.2.2-SNAPSHOT kestraVersion=1.2.1 +======= +version=1.1.6 +kestraVersion=1.3.0-SNAPSHOT +>>>>>>> Stashed changes diff --git a/src/main/java/io/kestra/plugin/git/AbstractKestraTask.java b/src/main/java/io/kestra/plugin/git/AbstractKestraTask.java index 89a0d91..ecd076b 100644 --- a/src/main/java/io/kestra/plugin/git/AbstractKestraTask.java +++ b/src/main/java/io/kestra/plugin/git/AbstractKestraTask.java @@ -51,10 +51,30 @@ protected KestraClient kestraClient(RunContext runContext) throws IllegalVariabl builder.basicAuth(maybeUsername.get(), maybePassword.get()); return builder.build(); } - throw new IllegalArgumentException("Both username and password are required for HTTP Basic authentication"); + + if (maybeUsername.isPresent() || maybePassword.isPresent()) { + throw new IllegalArgumentException("Both username and password are required for HTTP Basic authentication"); + } + + if (runContext.render(auth.auto).as(Boolean.class).orElse(Boolean.TRUE)) { + Optional autoAuth = runContext.sdk().defaultAuthentication(); + if (autoAuth.isPresent()) { + if (autoAuth.get().username().isPresent() && autoAuth.get().password().isPresent()) { + return builder.basicAuth(autoAuth.get().username().get(), autoAuth.get().password().get()).build(); + } + } + } + throw new IllegalArgumentException("No authentication method provided"); } else { - throw new IllegalArgumentException("Auth is required"); + // try automatic authentication + Optional autoAuth = runContext.sdk().defaultAuthentication(); + if (autoAuth.isPresent()) { + if (autoAuth.get().username().isPresent() && autoAuth.get().password().isPresent()) { + return builder.basicAuth(autoAuth.get().username().get(), autoAuth.get().password().get()).build(); + } + } } + return builder.build(); } @Builder @@ -65,5 +85,16 @@ public static class Auth { @Schema(title = "Password for HTTP Basic authentication.") private Property password; + + @Schema( + title = "Automatically retrieve credentials from Kestra's configuration if available", + description = """ + The default configuration can be configured globally inside the Kestra configuration file: + - Set `kestra.tasks.sdk.authentication.api-token` to use an API token + - Set `kestra.tasks.sdk.authentication.username` and `kestra.tasks.sdk.authentication.password` for HTTP basic authentication + The Enterprise edition also provides setting a default configuration at the Namespace of Tenant level by an administrator.""" + ) + @Builder.Default + private Property auto = Property.ofValue(Boolean.TRUE); } }