Skip to content

Commit cec1775

Browse files
committed
surface a profile variable that can be set in the customer's entrypoint
1 parent 45fbc66 commit cec1775

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/datacustomcode/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
reader_config:
22
type_config_name: QueryAPIDataCloudReader
3+
options:
4+
credentials_profile: default
35

46
writer_config:
57
type_config_name: PrintDataCloudWriter
8+
options:
9+
credentials_profile: default
610

711
spark_config:
812
app_name: DC Custom Code Python SDK Testing

src/datacustomcode/credentials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ def from_env(cls) -> Credentials:
6565
) from exc
6666

6767
@classmethod
68-
def from_available(cls) -> Credentials:
68+
def from_available(cls, profile: str = "default") -> Credentials:
6969
if os.environ.get("SFDC_USERNAME"):
7070
return cls.from_env()
7171
if os.path.exists(INI_FILE):
72-
return cls.from_ini()
72+
return cls.from_ini(profile=profile)
7373
raise ValueError(
7474
"Credentials not found in env or ini file. "
7575
"Run `datacustomcode configure` to create a credentials file."

src/datacustomcode/io/reader/query_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ class QueryAPIDataCloudReader(BaseDataCloudReader):
7575

7676
CONFIG_NAME = "QueryAPIDataCloudReader"
7777

78-
def __init__(self, spark: SparkSession) -> None:
78+
def __init__(
79+
self, spark: SparkSession, credentials_profile: str = "default"
80+
) -> None:
7981
self.spark = spark
80-
credentials = Credentials.from_available()
82+
credentials = Credentials.from_available(profile=credentials_profile)
8183

8284
self._conn = SalesforceCDPConnection(
8385
credentials.login_url,

src/datacustomcode/io/writer/print.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ class PrintDataCloudWriter(BaseDataCloudWriter):
2626
CONFIG_NAME = "PrintDataCloudWriter"
2727

2828
def __init__(
29-
self, spark: SparkSession, reader: Optional[QueryAPIDataCloudReader] = None
29+
self,
30+
spark: SparkSession,
31+
reader: Optional[QueryAPIDataCloudReader] = None,
32+
credentials_profile: str = "default",
3033
) -> None:
3134
super().__init__(spark)
32-
self.reader = QueryAPIDataCloudReader(self.spark) if reader is None else reader
35+
self.reader = (
36+
QueryAPIDataCloudReader(self.spark, credentials_profile)
37+
if reader is None
38+
else reader
39+
)
3340

3441
def validate_dataframe_columns_against_dlo(
3542
self,

0 commit comments

Comments
 (0)