Skip to content

Commit

Permalink
feat(core): load properly secret plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Sep 7, 2023
1 parent 74b83d8 commit 92b1c21
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/io/kestra/core/docs/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Plugin {
private List<String> conditions;
private List<String> controllers;
private List<String> storages;
private List<String> secrets;
private List<String> guides;

public static Plugin of(RegisteredPlugin registeredPlugin) {
Expand Down Expand Up @@ -54,6 +55,7 @@ public static Plugin of(RegisteredPlugin registeredPlugin) {
plugin.conditions = className(filter(registeredPlugin.getConditions()).toArray(Class[]::new));
plugin.controllers = className(filter(registeredPlugin.getControllers()).toArray(Class[]::new));
plugin.storages = className(filter(registeredPlugin.getStorages()).toArray(Class[]::new));
plugin.secrets = className(filter(registeredPlugin.getSecrets()).toArray(Class[]::new));

return plugin;
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/io/kestra/core/plugins/PluginScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.kestra.core.models.conditions.Condition;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.models.triggers.AbstractTrigger;
import io.kestra.core.secret.SecretPluginInterface;
import io.kestra.core.storages.StorageInterface;
import io.micronaut.core.beans.BeanIntrospectionReference;
import io.micronaut.core.io.service.SoftServiceLoader;
Expand Down Expand Up @@ -86,6 +87,7 @@ private RegisteredPlugin scanClassLoader(final ClassLoader classLoader, External
List<Class<? extends AbstractTrigger>> triggers = new ArrayList<>();
List<Class<? extends Condition>> conditions = new ArrayList<>();
List<Class<? extends StorageInterface>> storages = new ArrayList<>();
List<Class<? extends SecretPluginInterface>> secrets = new ArrayList<>();
List<Class<?>> controllers = new ArrayList<>();
List<String> guides = new ArrayList<>();

Expand Down Expand Up @@ -128,6 +130,10 @@ private RegisteredPlugin scanClassLoader(final ClassLoader classLoader, External
storages.add(beanType);
}

if (SecretPluginInterface.class.isAssignableFrom(beanType)) {
secrets.add(beanType);
}

if (beanType.isAnnotationPresent(Controller.class)) {
controllers.add(beanType);
}
Expand Down Expand Up @@ -160,6 +166,7 @@ private RegisteredPlugin scanClassLoader(final ClassLoader classLoader, External
.conditions(conditions)
.controllers(controllers)
.storages(storages)
.secrets(secrets)
.guides(guides)
.build();
}
Expand Down
18 changes: 14 additions & 4 deletions core/src/main/java/io/kestra/core/plugins/RegisteredPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import com.github.jknack.handlebars.internal.lang3.ObjectUtils;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import io.kestra.core.models.conditions.Condition;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.models.triggers.AbstractTrigger;
import io.kestra.core.secret.SecretPluginInterface;
import io.kestra.core.storages.StorageInterface;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.exceptions.HttpStatusException;
import lombok.*;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -36,10 +34,11 @@ public class RegisteredPlugin {
private final List<Class<? extends Condition>> conditions;
private final List<Class<?>> controllers;
private final List<Class<? extends StorageInterface>> storages;
private final List<Class<? extends SecretPluginInterface>> secrets;
private final List<String> guides;

public boolean isValid() {
return tasks.size() > 0 || triggers.size() > 0 || conditions.size() > 0 || controllers.size() > 0 || storages.size() > 0;
return !tasks.isEmpty() || !triggers.isEmpty() || !conditions.isEmpty() || !controllers.isEmpty() || !storages.isEmpty() || !secrets.isEmpty();
}

public boolean hasClass(String cls) {
Expand Down Expand Up @@ -74,6 +73,10 @@ public Class baseClass(String cls) {
return StorageInterface.class;
}

if (this.getSecrets().stream().anyMatch(r -> r.getName().equals(cls))) {
return SecretPluginInterface.class;
}

if (this.getTasks().stream().anyMatch(r -> r.getName().equals(cls))) {
return Task.class;
}
Expand All @@ -99,6 +102,7 @@ public Map<String, List<Class>> allClassGrouped() {
result.put("conditions", Arrays.asList(this.getConditions().toArray(Class[]::new)));
result.put("controllers", Arrays.asList(this.getControllers().toArray(Class[]::new)));
result.put("storages", Arrays.asList(this.getStorages().toArray(Class[]::new)));
result.put("secrets", Arrays.asList(this.getSecrets().toArray(Class[]::new)));

return result;
}
Expand Down Expand Up @@ -234,6 +238,12 @@ public String toString() {
b.append("] ");
}

if (!this.getSecrets().isEmpty()) {
b.append("[Secrets: ");
b.append(this.getSecrets().stream().map(Class::getName).collect(Collectors.joining(", ")));
b.append("] ");
}

return b.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.kestra.core.secret;

public interface SecretPluginInterface {

}

0 comments on commit 92b1c21

Please sign in to comment.