:toc:

== Data Source Support
In this section defines all the data sources that Operator Supports and how to configure them and any dependencies it may require.

Please note _any_ property that you want to configure, you can define reference to the value from a `secret` than providing a value directly. For example, the `Password` properties need to be secured, those can defined from secret as below.
----
- name: SPRING_DATASOURCE_SAMPLEDB_PASSWORD
  valueFrom:
     secretKeyRef:
       name: postgresql
       key: password
----

NOTE: When defining a environment property, characters like `.` are not allowed, but you can replace them with character `_` and application will convert them automatically at runtime.

== Configuring Relational Database [[config-jdbc]]
For configuring the translator name in VDB, the follwing translators are supported

- _db2_
- _derby_
- _h2_
- _hana_ (SAP Hana using the JDBC driver)
- _hive-jdbc_ (Hive using the Hive JDBC Driver)
- _hsql_
- _impala_ (Cloudera Impala)
- _informix_
- _ingres_
- _jtds_ (Connect Microsoft SQLServer using JTDS drivers)
- _mysql5_
- _netezza_
- _oracle_
- _osisoft-pi_ (OSISOFT's PI Database using osisoft's JDBC Driver)
- _phoenix_ (Apache Phenix using the Phoenix JDBC Driver)
- _postgresql_
- _presto-jdbc_ (PrestoDB connecting using JDBC Driver)
- _sqlserver_ (Microsoft SQLServer)
- _sybase_
- _teradata_
- _teiid_ (Connecting to another Teiid instance using its JDBC driver)
- _vertica_

For configuring the relational database like Oracle, MS-SQLServer, PostgreSQL etc, the following properties are required.

[Attributes]
|===
|Property Name |Description |Required|Default value

|SPRING_DATASOURCE_{NAME}_JDBCURL | URL For the connection | Yes| n/a
|SPRING_DATASOURCE_{NAME}_USERNAME| User Name| Yes | n/a
|SPRING_DATASOURCE_{NAME}_PASSWORD| Password | Yes | n/a
|SPRING_DATASOURCE_{NAME}_DRIVER_CLASS_NAME| Driver Name | No |n/a
|SPRING_DATASOURCE_{NAME}_IMPORTER_SCHEMA_NAME| Schema Name for import| Yes |n/a
|===

NOTE: where {NAME} denotes the custom name given by the user in UPPER case, that defines the `server` in the VDB's DDL.

You define many more properties to further tune the JDBC translator and schema import behavior. Please check Teiid documentation.

The user is also required to provide a maven dependency for JDBC driver class for the above data source in `spec/dependencies` line in the CR. It is expected that the maven repository is *reachable* by the Operator. If in case the resource is not available in the public/private maven repository then there are other options to solve the issue. Look at section "Attach Private Libraries".


== [[config-mongo]]Configuring MongoDB database
The translator name to use in the VDB's DDL is _mongodb_ with its `Server` definition.

For configuring the MongoDB database the following properties are needed

[Attributes]
|===
|Property Name |Description |Required|Default value
|SPRING_TEIID_DATA_MONGODB_{NAME}_REMOTE_SERVER_LIST | List of MongoDb servers ex:(localhost:27012) | Yes | n/a
|SPRING_TEIID_DATA_MONGODB_{NAME}_USER | User Name | Yes | n/a
|SPRING_TEIID_DATA_MONGODB_{NAME}_PASSWORD | Password | Yes | n/a
|SPRING_TEIID_DATA_MONGODB_{NAME}_DATABASE | Database name to connect to | Yes | n/a
|SPRING_TEIID_DATA_MONGODB_{NAME}_AUTH_DATABASE | Database name for authorization | No | n/a
|SPRING_TEIID_DATA_MONGODB_{NAME}_SSL | Use SSL Connection | No | n/a
|===

User does not need to add any dependencies. The currently supported version is version 3 of the MongoDB.

== Configuring Salesforce [[config-sf]]
The translator name to use in the VDB's DDL is _salesforce_ with its `Server` definition.

For connecting to Salesforce and importing/querying all `SObject`, the user fist needs to create `OAuth` based connection in the Salesforce. Log into your Salesforce account, go to
`SetUp -> Create -> Apps`. Then, create a new "Connected App" and provide details there. When you are done, should get a `client-id` and `client-secret` values. Then to use this application from Teiid to connect to Salesforce by configuring the below properties.

[Attributes]
|===
|Property Name |Description |Required|Default value
|SPRING_TEIID_DATA_SALESFORCE_{NAME}_USER_NAME | User for salesforce.com | Yes | n/a
|SPRING_TEIID_DATA_SALESFORCE_{NAME}_PASSWORD | Password for salesforce.com| Yes | n/a
|SPRING_TEIID_DATA_SALESFORCE_{NAME}_CLIENT_ID | ClientId from connected app | Yes | n/a
|SPRING_TEIID_DATA_SALESFORCE_{NAME}_CLIENT_SECRET | clientSecret from connected app | No | n/a
|===

NOTE: if user does not want to connect using the `username` and `password`, then the module also supports using the `refreshToken`. So for above you can provide `SPRING_TEIID_DATA_SALESFORCE_{NAME}_REFRESH_TOKEN` property and remove username and password properties. Obtaining refresh token is beyond scope of this document.

== Configuring OData Based Source [[config-odata]]
The translator name to use in the VDB's DDL is _odata_ with its `Server` definition for any OData V2 services. For OData V4 service use _odata4_

As per the connection underneath, follow the same properties as <<config-rest, REST based connection>>

== Configuring SAP Gateway Based Source [[config-sap]]
The translator name to use in the VDB's DDL is _sap-gateway_ with its `Server` definition. This uses OData V2 translator underneath to connect to SAP Gateway. Only _Http Basic_ auth has been verified.

As per the connection underneath, follow the same properties as <<config-rest, REST based connection>>

== Configuring OpenAPI Based Source [[config-openapi]]
The translator name to use in the VDB's DDL is _openapi_ with its `Server` definition. When this translator is used, the source will look for either `swagger.json` or `openapi.json` files and build the source model based on it. Security aspects of the service are not understood automatically, only the API document and its responses.

As per the connection underneath, follow the same properties as <<config-rest, REST based connection>>

== Configuring REST Based Source [[config-rest]]
For rest based that are using the rest directly can use _rest_ as the translator name. Note, for sources like OData and SAP there are separate translators based on same configuration here. When used directly the user is provided with `invokeHttp` as defined in the Teiid documents to use to execute any endpoint using SQL.

The REST API based connection uses the following properties

[Attributes]
|===
|Property Name |Description |Required|Default value
|SPRING_TEIID_REST_{NAME}_ENDPOINT | Endpoint for the service | Yes | n/a
|SPRING_TEIID_REST_{NAME}_SECURITY_TYPE | Security type used. Available options are _http-basic_, _openid-connect_ or empty | No | no security
|===

if the _security type_ is defined as _http_basic_ the following properties are needed
[Attributes]
|===
|Property Name |Description |Required|Default value
|SPRING_TEIID_REST_{NAME}_USER_NAME | User Name | Yes | n/a
|SPRING_TEIID_REST_{NAME}_PASSWORD | Password | Yes | n/a
|===

if the _security type_ is defined as _openid-connect_ the following properties are needed
[Attributes]
|===
|Property Name |Description |Required|Default value
|SPRING_TEIID_REST_{NAME}_USER_NAME | User Name | Yes | n/a
|SPRING_TEIID_REST_{NAME}_PASSWORD | Password | Yes | n/a
|SPRING_TEIID_REST_{NAME}_CLIENT_ID | ClientId from connected app | Yes | n/a
|SPRING_TEIID_REST_{NAME}_CLIENT_SECRET | clientSecret from connected app | Yes | n/a
|SPRING_TEIID_REST_{NAME}_AUTHORIZE_URL | clientSecret from connected app | Yes | n/a
|SPRING_TEIID_REST_{NAME}_ACCESS_TOKEN_URL | clientSecret from connected app | Yes | n/a
|SPRING_TEIID_REST_{NAME}_SCOPE | clientSecret from connected app | No | n/a
|===

Alternatively, for the _openid-connect_ you can also supply 'SPRING_TEIID_REST_{NAME}_REFRESH_TOKEN' property and avoid the `USER_NAME` and `PASSWORD` properties, however describing on how to obtaining a refresh token is beyond this document as it is different for different services.

== Configuring Google Sheets as Source [[config-googlesheets]]
The translator name to use in the VDB's DDL is _google-spreadsheet_ with its `Server` definition. This will represent each _Sheet_ on a google spread sheet as a _table_ in Teiid.

Before you can access the Google Spreadsheet using Teiid, one needs to provide OAuth2 specific credentials to Teiid. To provide the access, use instructions from https://developers.google.com/identity/protocols/OAuth2InstalledApp and create project ad select the "Google Spreadsheets API" as library you want to access. Then create a "OAuth Client ID" Credential using the UI. At the end of this exercise, you will have a "Client ID" and "Client Secret". Then using the Google's OAuth2.0 Playground https://developers.google.com/oauthplayground/ select the "Google Sheet API v4" option and select "drive" and "spreadsheets" endpoints as allowable scopes. Then Authorize APIs, you will end up with a "RefreshToken". Then use all these properties for further configuration.

[Attributes]
|===
|Property Name |Description |Required|Default value
|SPRING_TEIID_DATA_GOOGLE_SHEETS_{NAME}_SPREAD_SHEET_NAME |Name of the Google Spreadsheet | Yes | n/a
|SPRING_TEIID_DATA_GOOGLE_SHEETS_{NAME}_SPREAD_SHEET_ID |Spread Sheet Id | Yes | Sheet Id, Look in URL of the Spreadsheet. For more info see https://developers.google.com/sheets/api/guides/concepts#spreadsheet_id
|SPRING_TEIID_DATA_GOOGLE_SHEETS_{NAME}_CLIENT_ID |OAuth2 client id for google sheets | Yes | n/a
|SPRING_TEIID_DATA_GOOGLE_SHEETS_{NAME}_CLIENT_SECRET |OAuth2 client secret for google sheets | Yes | n/a
|SPRING_TEIID_DATA_GOOGLE_SHEETS_{NAME}_REFRESH_TOKEN |OAuth2 refreshToken for google sheets | Yes | n/a
|===
