io.kestra.plugin.airbyte.AbstractAirbyteConnection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin-airbyte Show documentation
Show all versions of plugin-airbyte Show documentation
Seamlessly integrate Airbyte connectors into your Kestra workflows.
package io.kestra.plugin.airbyte;
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.tasks.DynamicTask;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.runners.RunContext;
import io.micronaut.core.type.Argument;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.MutableHttpRequest;
import io.micronaut.http.client.DefaultHttpClientConfiguration;
import io.micronaut.http.client.HttpClient;
import io.micronaut.http.client.exceptions.HttpClientResponseException;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.validation.constraints.NotNull;
@SuperBuilder
@ToString
@EqualsAndHashCode
@Getter
@NoArgsConstructor
public abstract class AbstractAirbyteConnection extends Task implements DynamicTask {
@Schema(
title = "The url of your Airbyte instance"
)
@PluginProperty(dynamic = true)
@NotNull
String url;
@Schema(
title = "Basic auth username"
)
@PluginProperty(dynamic = true)
String username;
@Schema(
title = "Basic auth password"
)
@PluginProperty(dynamic = true)
String password;
@Schema(
title = "API key"
)
@PluginProperty(dynamic = true)
String token;
protected HttpClient client() throws IllegalVariableEvaluationException, MalformedURLException, URISyntaxException {
return HttpClient.create(URI.create(this.url).toURL(), new DefaultHttpClientConfiguration());
}
protected HttpResponse request(RunContext runContext, MutableHttpRequest request, Argument argument) throws HttpClientResponseException {
try {
request = request
.contentType(MediaType.APPLICATION_JSON);
if (this.token != null) {
request = request.bearerAuth(runContext.render(this.token));
}
if (this.username != null && this.password != null) {
request = request.basicAuth(runContext.render(this.username), runContext.render(this.password));
}
try (HttpClient client = this.client()) {
return client.toBlocking().exchange(request, argument);
}
} catch (HttpClientResponseException e) {
throw new HttpClientResponseException(
"Request failed '" + e.getStatus().getCode() + "' and body '" + e.getResponse().getBody(String.class).orElse("null") + "'",
e,
e.getResponse()
);
} catch (IllegalVariableEvaluationException | MalformedURLException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy