Skip to content

Commit

Permalink
Merge pull request #2 from kestra-io/init_plugin
Browse files Browse the repository at this point in the history
feat: create typsense plugin
  • Loading branch information
nkwiatkowski authored Dec 9, 2024
2 parents 12ec266 + 505d52f commit a59184d
Show file tree
Hide file tree
Showing 23 changed files with 1,046 additions and 206 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<br />

<p align="center">
<a href="https://twitter.com/kestra_io"><img height="25" src="https://kestra.io/twitter.svg" alt="twitter" /></a> &nbsp;
<a href="https://www.linkedin.com/company/kestra/"><img height="25" src="https://kestra.io/linkedin.svg" alt="linkedin" /></a> &nbsp;
<a href="https://www.youtube.com/@kestra-io"><img height="25" src="https://kestra.io/youtube.svg" alt="youtube" /></a> &nbsp;
<a href="https://twitter.com/kestra_io"><img height="25" src="https://kestra.io/twitter.svg" alt="twitter" /></a>  
<a href="https://www.linkedin.com/company/kestra/"><img height="25" src="https://kestra.io/linkedin.svg" alt="linkedin" /></a>  
<a href="https://www.youtube.com/@kestra-io"><img height="25" src="https://kestra.io/youtube.svg" alt="youtube" /></a>  
</p>

<br />
Expand All @@ -32,24 +32,22 @@
</p>
<p align="center" style="color:grey;"><i>Get started with Kestra in 4 minutes.</i></p>

# Kestra Plugin Typesense

# Kestra Plugin Template

> A template for creating Kestra plugins
> Plugin to interact with Typesens data base
This repository serves as a general template for creating a new [Kestra](https://github.com/kestra-io/kestra) plugin. It should take only a few minutes! Use this repository as a scaffold to ensure that you've set up the plugin correctly, including unit tests and CI/CD workflows.

![Kestra orchestrator](https://kestra.io/video.gif)


## Documentation

* Full documentation can be found under: [kestra.io/docs](https://kestra.io/docs)
* Documentation for developing a plugin is included in the [Plugin Developer Guide](https://kestra.io/docs/plugin-developer-guide/)


## License
Apache 2.0 © [Kestra Technologies](https://kestra.io)

Apache 2.0 © [Kestra Technologies](https://kestra.io)

## Stay up to date

Expand Down
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ java {
}

group "io.kestra.plugin"
description 'Plugin template for Kestra'
description 'Plugin typesense for Kestra'

tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
Expand All @@ -51,6 +51,9 @@ dependencies {
annotationProcessor group: "io.kestra", name: "processor", version: kestraVersion
compileOnly group: "io.kestra", name: "core", version: kestraVersion
compileOnly group: "io.kestra", name: "script", version: kestraVersion

// Typesense
implementation 'org.typesense:typesense-java:1.1.0'
}


Expand Down Expand Up @@ -98,6 +101,11 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.hamcrest:hamcrest"
testImplementation "org.hamcrest:hamcrest-library"

//test container
testImplementation 'org.testcontainers:testcontainers:1.20.4'

testImplementation group: 'com.devskiller.friendly-id', name: 'friendly-id'
}

/**********************************************************************************************************************\
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'plugin-template'
rootProject.name = 'plugin-typesense'
72 changes: 0 additions & 72 deletions src/main/java/io/kestra/plugin/templates/Example.java

This file was deleted.

58 changes: 0 additions & 58 deletions src/main/java/io/kestra/plugin/templates/Trigger.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package io.kestra.plugin.typesense;

import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.runners.RunContext;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.time.Duration;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.typesense.api.Client;
import org.typesense.api.Configuration;
import org.typesense.resources.Node;

@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class AbstractTypesenseTask extends Task {

@Schema(
title = "The host of the typesense DB"
)
@NotNull
protected Property<String> host;

@Schema(
title = "The port of the typesense DB"
)
@NotNull
protected Property<String> port;

@Schema(
title = "The API key to connect to the typesense DB"
)
@NotNull
protected Property<String> apiKey;

@Schema(
title = "The name of the typesense collection"
)
@NotNull
protected Property<String> collection;

@Schema(
title = "Is HTTPS used",
description = "By default, HTTP protocol will be use. Set this value to true tu use HTTPS"
)
protected Property<Boolean> https;

protected Client getClient(RunContext context) throws IllegalVariableEvaluationException {
Configuration configuration = new Configuration(
List.of(new Node(
context.render(https).as(Boolean.class).orElse(false) ? "https": "http",
context.render(host).as(String.class).orElseThrow(),
context.render(port).as(String.class).orElseThrow())
),
Duration.ofSeconds(2),context.render(apiKey).as(String.class).orElseThrow());
return new Client(configuration);
}

protected String renderCollection(RunContext context)
throws IllegalVariableEvaluationException {
return context.render(collection).as(String.class).orElseThrow();
}

protected String renderString(Property<String> property, RunContext context)
throws IllegalVariableEvaluationException {
return context.render(property).as(String.class).orElseThrow();
}

}
Loading

0 comments on commit a59184d

Please sign in to comment.