|
| 1 | +/* Copyright (c) 2024 Airbyte, Inc., all rights reserved. */ |
| 2 | +package io.airbyte.cdk.command |
| 3 | + |
| 4 | +import com.fasterxml.jackson.annotation.JsonProperty |
| 5 | +import com.fasterxml.jackson.annotation.JsonPropertyDescription |
| 6 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder |
| 7 | +import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDefault |
| 8 | +import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaDescription |
| 9 | +import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject |
| 10 | +import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaTitle |
| 11 | +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings |
| 12 | + |
| 13 | +/** |
| 14 | + * Base ConfigurationSpecification for JDBC sources with common properties. |
| 15 | + * |
| 16 | + * Connector-specific implementations should extend this class and add their unique properties (like |
| 17 | + * replication methods, SSL modes, etc.). |
| 18 | + */ |
| 19 | +@SuppressFBWarnings(value = ["NP_NONNULL_RETURN_VIOLATION"], justification = "Micronaut DI") |
| 20 | +abstract class JdbcSourceConfigurationSpecification : ConfigurationSpecification() { |
| 21 | + |
| 22 | + @JsonProperty("host") |
| 23 | + @JsonSchemaTitle("Host") |
| 24 | + @JsonPropertyDescription("Hostname of the database.") |
| 25 | + @JsonSchemaInject(json = """{"order":0,"always_show":true}""") |
| 26 | + lateinit var host: String |
| 27 | + |
| 28 | + @JsonProperty("username") |
| 29 | + @JsonSchemaTitle("Username") |
| 30 | + @JsonPropertyDescription("The username which is used to access the database.") |
| 31 | + @JsonSchemaInject(json = """{"order":2,"always_show":true}""") |
| 32 | + lateinit var username: String |
| 33 | + |
| 34 | + @JsonProperty("password") |
| 35 | + @JsonSchemaTitle("Password") |
| 36 | + @JsonPropertyDescription("The password associated with the username.") |
| 37 | + @JsonSchemaInject(json = """{"order":3,"always_show":true,"airbyte_secret":true}""") |
| 38 | + var password: String? = null |
| 39 | + |
| 40 | + @JsonProperty("database") |
| 41 | + @JsonSchemaTitle("Database") |
| 42 | + @JsonPropertyDescription("Name of the database.") |
| 43 | + @JsonSchemaInject(json = """{"order":4,"always_show":true}""") |
| 44 | + lateinit var database: String |
| 45 | + |
| 46 | + @JsonProperty("schemas") |
| 47 | + @JsonSchemaTitle("Schemas") |
| 48 | + @JsonPropertyDescription( |
| 49 | + "The list of schemas to sync from. " + |
| 50 | + "If not specified, all accessible schemas will be synced. " + |
| 51 | + "The exact meaning depends on the database (schema names, database names, etc.)." |
| 52 | + ) |
| 53 | + @JsonSchemaInject(json = """{"order":1,"always_show":true,"group":"optional"}""") |
| 54 | + var schemas: List<String>? = null |
| 55 | + |
| 56 | + @JsonProperty("table_filters") |
| 57 | + @JsonSchemaTitle("Table Filters") |
| 58 | + @JsonPropertyDescription( |
| 59 | + "Optional filters to include only specific tables from specific schemas. " + |
| 60 | + "Works in combination with the 'Schemas' config above." |
| 61 | + ) |
| 62 | + @JsonSchemaInject(json = """{"order":2,"always_show":true,"group":"optional"}""") |
| 63 | + var tableFilters: List<TableFilter>? = emptyList() |
| 64 | + |
| 65 | + @JsonProperty("jdbc_url_params") |
| 66 | + @JsonSchemaTitle("JDBC URL Params") |
| 67 | + @JsonPropertyDescription( |
| 68 | + "Additional properties to pass to the JDBC URL string when connecting to the database " + |
| 69 | + "formatted as 'key=value' pairs separated by the symbol '&'. " + |
| 70 | + "(example: key1=value1&key2=value2&key3=value3)." |
| 71 | + ) |
| 72 | + @JsonSchemaInject(json = """{"order":3,"group":"optional"}""") |
| 73 | + var jdbcUrlParams: String? = null |
| 74 | + |
| 75 | + @JsonProperty("check_privileges") |
| 76 | + @JsonSchemaTitle("Check Table and Column Access Privileges") |
| 77 | + @JsonSchemaInject(json = """{"order":4,"group":"optional"}""") |
| 78 | + @JsonSchemaDefault("true") |
| 79 | + @JsonPropertyDescription( |
| 80 | + "When this feature is enabled, during schema discovery the connector " + |
| 81 | + "will query each table or view individually to check access privileges " + |
| 82 | + "and inaccessible tables, views, or columns therein will be removed. " + |
| 83 | + "In large schemas, this might cause schema discovery to take too long, " + |
| 84 | + "in which case it might be advisable to disable this feature.", |
| 85 | + ) |
| 86 | + var checkPrivileges: Boolean? = true |
| 87 | +} |
| 88 | + |
| 89 | +@JsonSchemaTitle("Table Filter") |
| 90 | +@JsonSchemaDescription("Inclusion filter configuration for table selection per schema.") |
| 91 | +@JsonPropertyOrder("schema_name", "table_name_patterns") |
| 92 | +@SuppressFBWarnings(value = ["NP_NONNULL_RETURN_VIOLATION"], justification = "Micronaut DI") |
| 93 | +class TableFilter { |
| 94 | + @JsonProperty("schema_name", required = true) |
| 95 | + @JsonSchemaTitle("Schema Name") |
| 96 | + @JsonPropertyDescription( |
| 97 | + "The name of the schema to apply this filter to. " + |
| 98 | + "Should match a schema defined in \"Schemas\" field above." |
| 99 | + ) |
| 100 | + @JsonSchemaInject(json = """{"order":1,"always_show":true}""") |
| 101 | + lateinit var schemaName: String |
| 102 | + |
| 103 | + @JsonProperty("table_name_patterns", required = true) |
| 104 | + @JsonSchemaTitle("Table Filter Patterns") |
| 105 | + @JsonPropertyDescription( |
| 106 | + "List of table name patterns to include from this schema. " + |
| 107 | + "Should be a SQL LIKE pattern." |
| 108 | + ) |
| 109 | + @JsonSchemaInject(json = """{"order":2,"always_show":true,"minItems":1}""") |
| 110 | + lateinit var patterns: List<String> |
| 111 | +} |
0 commit comments