Skip to content

Commit 9f10888

Browse files
committed
feat(connection): inject additional API OAuth secrets into connection entries
1 parent 3b70eef commit 9f10888

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

core/dbio/connection/connection_local.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,23 @@ func GetLocalConns(options ...any) ConnEntries {
247247
}
248248

249249
connArr := lo.Values(connsMap)
250+
251+
// inject any additional API OAuth secrets
252+
oauthMap := env.GetOAuthMap()
253+
for i, entry := range connArr {
254+
secrets := cast.ToStringMap(connArr[i].Connection.Data["secrets"])
255+
specConnector := strings.ToLower(entry.Connection.DataS(true)["spec"])
256+
if connData, ok := oauthMap[specConnector]; ok {
257+
for k, v := range connData {
258+
if _, ok := secrets[k]; !ok {
259+
secrets[k] = v // write if not exist
260+
}
261+
}
262+
connArr[i].Connection.Data["secrets"] = secrets // update secrets
263+
}
264+
}
265+
oauthMap = nil
266+
250267
sort.Slice(connArr, func(i, j int) bool {
251268
return cast.ToString(connArr[i].Name) < cast.ToString(connArr[j].Name)
252269
})

core/env/env.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
Executable = ""
3535
IsThreadChild = cast.ToBool(os.Getenv("SLING_THREAD_CHILD"))
3636
IsAgentMode = os.Getenv("SLING_AGENT_ID") != ""
37+
GetOAuthMap = func() map[string]map[string]any { return map[string]map[string]any{} }
3738
setupOtel = func() {}
3839
)
3940

0 commit comments

Comments
 (0)