feat: added salesforce oauth (#24154)

This commit is contained in:
Keshav Mohta 2025-11-05 00:59:07 +05:30 committed by GitHub
parent b1ebf7f9c1
commit 8ef6c90622
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 275 additions and 58 deletions

View File

@ -28,6 +28,9 @@ from metadata.generated.schema.entity.services.connections.testConnectionResult
from metadata.ingestion.connections.test_connections import test_connection_steps
from metadata.ingestion.ometa.ometa_api import OpenMetadata
from metadata.utils.constants import THREE_MIN
from metadata.utils.logger import ingestion_logger
logger = ingestion_logger()
def get_connection(connection: SalesforceConnection) -> Salesforce:
@ -36,14 +39,19 @@ def get_connection(connection: SalesforceConnection) -> Salesforce:
"""
return Salesforce(
username=connection.username,
password=connection.password.get_secret_value(),
security_token=connection.securityToken.get_secret_value()
if connection.securityToken
else "",
organizationId=connection.organizationId if connection.organizationId else "",
password=connection.password and connection.password.get_secret_value(),
security_token=connection.securityToken
and connection.securityToken.get_secret_value(),
consumer_key=connection.consumerKey,
consumer_secret=connection.consumerSecret
and connection.consumerSecret.get_secret_value(),
organizationId=connection.organizationId,
domain=connection.salesforceDomain,
version=connection.salesforceApiVersion,
**connection.connectionArguments.root if connection.connectionArguments else {},
**(
(connection.connectionArguments and connection.connectionArguments.root)
or {}
),
)

View File

@ -67,6 +67,41 @@ mock_salesforce_config = {
}
},
}
mock_salesforce_oauth_config = {
"source": {
"type": "salesforce",
"serviceName": "local_salesforce_oauth",
"serviceConnection": {
"config": {
"type": "Salesforce",
"username": "username",
"password": "password",
"consumerKey": "test_consumer_key",
"consumerSecret": "test_consumer_secret",
"salesforceDomain": "login",
"sobjectName": "sobjectName",
}
},
"sourceConfig": {
"config": {
"type": "DatabaseMetadata",
}
},
},
"sink": {
"type": "metadata-rest",
"config": {},
},
"workflowConfig": {
"openMetadataServerConfig": {
"hostPort": "http://localhost:8585/api",
"authProvider": "openmetadata",
"securityConfig": {"jwtToken": "salesforce"},
}
},
}
MOCK_DATABASE_SERVICE = DatabaseService(
id="85811038-099a-11ed-861d-0242ac120002",
name="salesforce_source",
@ -466,6 +501,26 @@ class SalesforceUnitTest(TestCase):
)
assert result == EXPECTED_COLUMN_TYPE[i]
@patch(
"metadata.ingestion.source.database.salesforce.metadata.SalesforceSource.test_connection"
)
@patch("simple_salesforce.api.Salesforce")
def test_oauth_connection(self, salesforce, test_connection) -> None:
test_connection.return_value = False
self.config = OpenMetadataWorkflowConfig.model_validate(
mock_salesforce_oauth_config
)
self.salesforce_source = SalesforceSource.create(
mock_salesforce_oauth_config["source"],
self.config.workflowConfig.openMetadataServerConfig,
)
self.assertTrue(
self.salesforce_source.config.serviceConnection.root.config.consumerKey
)
self.assertTrue(
self.salesforce_source.config.serviceConnection.root.config.consumerSecret
)
@patch(
"metadata.ingestion.source.database.salesforce.metadata.SalesforceSource.test_connection"
)
@ -474,7 +529,7 @@ class SalesforceUnitTest(TestCase):
mock_salesforce_config["source"]["serviceConnection"]["config"]["sslConfig"] = {
"caCertificate": """
-----BEGIN CERTIFICATE-----
sample caCertificateData
sample caCertificateData
-----END CERTIFICATE-----
"""
}
@ -483,7 +538,7 @@ class SalesforceUnitTest(TestCase):
"sslKey"
] = """
-----BEGIN CERTIFICATE-----
sample caCertificateData
sample caCertificateData
-----END CERTIFICATE-----
"""
mock_salesforce_config["source"]["serviceConnection"]["config"]["sslConfig"][

View File

@ -22,18 +22,29 @@
},
"username": {
"title": "Username",
"description": "Username to connect to the Salesforce. This user should have privileges to read all the metadata in Redshift.",
"description": "Username to connect to Salesforce. This user should have privileges to read all the metadata in Salesforce.",
"type": "string"
},
"password": {
"title": "Password",
"description": "Password to connect to the Salesforce.",
"description": "Password to connect to Salesforce.",
"type": "string",
"format": "password"
},
"securityToken": {
"title": "Security Token",
"description": "Salesforce Security Token.",
"description": "Salesforce Security Token for username/password authentication.",
"type": "string",
"format": "password"
},
"consumerKey": {
"title": "Consumer Key",
"description": "Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from your Salesforce Connected App configuration. Required along with Consumer Secret for OAuth authentication.",
"type": "string"
},
"consumerSecret": {
"title": "Consumer Secret",
"description": "Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained from your Salesforce Connected App configuration. Required along with Consumer Key for OAuth authentication.",
"type": "string",
"format": "password"
},
@ -97,6 +108,5 @@
"$ref": "../connectionBasicType.json#/definitions/supportsMetadataExtraction"
}
},
"additionalProperties": false,
"required": ["username"]
"additionalProperties": false
}

View File

@ -32,6 +32,18 @@ $$section
Salesforce Security Token is required to access the metadata through APIs. You can check out <a href="https://help.salesforce.com/s/articleView?id=sf.user_security_token.htm&type=5" target="_blank">this doc</a> on how to get the security token.
$$
$$section
### Consumer Key $(id="consumerKey")
Salesforce Consumer Key for OAuth 2.0 authentication. This is obtained from your Salesforce Connected App configuration.
$$
$$section
### Consumer Secret $(id="consumerSecret")
Salesforce Consumer Secret for OAuth 2.0 authentication. This is obtained from your Salesforce Connected App configuration.
$$
$$section
### Organization ID $(id="organizationId")

View File

@ -778,7 +778,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -863,8 +863,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -1090,6 +1090,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -1105,7 +1117,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -401,7 +401,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -474,8 +474,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -673,6 +673,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*/
@ -686,7 +698,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -2864,7 +2864,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -2952,8 +2952,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -3541,6 +3541,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -3556,7 +3568,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -660,7 +660,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -745,8 +745,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -972,6 +972,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -987,7 +999,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -1224,7 +1224,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -1309,8 +1309,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -1536,6 +1536,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -1551,7 +1563,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -16,6 +16,18 @@
export interface SalesforceConnection {
connectionArguments?: { [key: string]: any };
connectionOptions?: { [key: string]: string };
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Regex to only include/exclude databases that matches the pattern.
*/
@ -30,7 +42,7 @@ export interface SalesforceConnection {
*/
organizationId?: string;
/**
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*/
password?: string;
/**
@ -46,7 +58,7 @@ export interface SalesforceConnection {
*/
schemaFilterPattern?: FilterPattern;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**
@ -67,10 +79,10 @@ export interface SalesforceConnection {
*/
type?: SalesforceType;
/**
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*/
username: string;
username?: string;
}
/**

View File

@ -562,7 +562,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -650,8 +650,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -1239,6 +1239,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -1254,7 +1266,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -524,7 +524,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -597,8 +597,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -796,6 +796,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*/
@ -809,7 +821,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -3379,7 +3379,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -3467,8 +3467,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -4056,6 +4056,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -4071,7 +4083,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -606,7 +606,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -694,8 +694,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -1283,6 +1283,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -1298,7 +1310,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**

View File

@ -646,7 +646,7 @@ export interface ConfigObject {
*
* Password to connect to Redshift.
*
* Password to connect to the Salesforce.
* Password to connect to Salesforce.
*
* Password to connect to SingleStore.
*
@ -734,8 +734,8 @@ export interface ConfigObject {
* Username to connect to Redshift. This user should have privileges to read all the
* metadata in Redshift.
*
* Username to connect to the Salesforce. This user should have privileges to read all the
* metadata in Redshift.
* Username to connect to Salesforce. This user should have privileges to read all the
* metadata in Salesforce.
*
* Username to connect to SingleStore. This user should have privileges to read all the
* metadata in MySQL.
@ -1323,6 +1323,18 @@ export interface ConfigObject {
* Verify ( Connection Argument for SSL ) to connect to Trino.
*/
verify?: string;
/**
* Salesforce Consumer Key (Client ID) for OAuth 2.0 authentication. This is obtained from
* your Salesforce Connected App configuration. Required along with Consumer Secret for
* OAuth authentication.
*/
consumerKey?: string;
/**
* Salesforce Consumer Secret (Client Secret) for OAuth 2.0 authentication. This is obtained
* from your Salesforce Connected App configuration. Required along with Consumer Key for
* OAuth authentication.
*/
consumerSecret?: string;
/**
* Salesforce Organization ID is the unique identifier for your Salesforce identity
*
@ -1338,7 +1350,7 @@ export interface ConfigObject {
*/
salesforceDomain?: string;
/**
* Salesforce Security Token.
* Salesforce Security Token for username/password authentication.
*/
securityToken?: string;
/**