MCPcopy Create free account
hub / github.com/IQEngine/IQEngine / update_datasource

Function update_datasource

api/handlers/datasources.py:108–148  ·  view source on GitHub ↗
(
    account: str,
    container: str,
    datasource: DataSource,
    datasources_collection: AgnosticCollection = Depends(datasource_repo.collection),
    access_allowed=Depends(check_access),
)

Source from the content-addressed store, hash-verified

106
107@router.put("/api/datasources/{account}/{container}/datasource", status_code=204)
108async def update_datasource(
109 account: str,
110 container: str,
111 datasource: DataSource,
112 datasources_collection: AgnosticCollection = Depends(datasource_repo.collection),
113 access_allowed=Depends(check_access),
114):
115 if access_allowed is None:
116 raise HTTPException(status_code=403, detail="No Access")
117 existing_datasource = await datasources_collection.find_one(
118 {
119 "account": account,
120 "container": container,
121 }
122 )
123 if not existing_datasource:
124 raise HTTPException(status_code=404, detail="Datasource not found")
125 # If the incoming datasource has a sasToken or account_key, encrypt it and replace the existing one
126 if datasource.sasToken and (datasource.sasToken.get_secret_value() != "**********"):
127 datasource.sasToken = encrypt(datasource.sasToken) # returns a str
128 if datasource.accountKey and (datasource.accountKey.get_secret_value() != "**********"):
129 datasource.accountKey = encrypt(datasource.accountKey)
130 datasource_dict = datasource.dict(by_alias=True, exclude_unset=True)
131 # if sasToken is "" or null then set it to a empty str instead of SecretStr
132 if not datasource.sasToken:
133 datasource_dict["sasToken"] = ""
134 if not datasource.accountKey:
135 datasource_dict["accountKey"] = ""
136
137 # if sasToken or accountKey is SecretStr, pop it from the dict so not to overwrite the existing one
138 # as incoming datasource parameter will not have sasToken or accountKey but ***********
139 if isinstance(datasource_dict["sasToken"], SecretStr):
140 datasource_dict.pop("sasToken")
141 if isinstance(datasource_dict["accountKey"], SecretStr):
142 datasource_dict.pop("accountKey")
143
144 await datasources_collection.update_one(
145 {"account": account, "container": container},
146 {"$set": datasource_dict},
147 )
148 return
149
150
151@router.put("/api/datasources/{account}/{container}/sync", status_code=204)

Callers

nothing calls this directly

Calls 1

encryptFunction · 0.90

Tested by

no test coverage detected