MCPcopy Index your code
hub / github.com/mlco2/codecarbon / configure_fief

Function configure_fief

deploy/deploy.py:204–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202
203
204def configure_fief():
205 fief_settings = FiefSettings()
206 carbonserver_settings = CarbonServerSettings()
207
208 api = requests.Session()
209 api.headers["Authorization"] = f"Bearer {fief_settings.fief_main_admin_api_key}"
210 # TODO: https
211 url = f"http://{fief_settings.fief_domain}/admin/api"
212 print(f"configuring fief at {url}")
213
214 # fief server might not be running yet
215 for _ in range(5):
216 if api.get(url + "/clients", verify=False).status_code == 200:
217 break
218 print("waiting for fief server to come online...")
219 time.sleep(5)
220
221 client = api.get(url + "/clients", verify=False).json()["results"][0]
222 redir_uris = [
223 f"https://{carbonserver_settings.app_hostname}/auth/login",
224 f"http://{carbonserver_settings.app_hostname}/auth/login",
225 f"https://{fief_settings.fief_domain}/docs/oauth2-redirect",
226 f"https://{fief_settings.fief_domain}/admin/auth/callback",
227 f"http://{fief_settings.fief_domain}/docs/oauth2-redirect",
228 f"http://{fief_settings.fief_domain}/admin/auth/callback",
229 f"http://{fief_settings.fief_domain}/callback",
230 "http://localhost/callback",
231 "http://localhost:51562/callback",
232 ]
233 api.patch(
234 f"{url}/clients/{client['id']}",
235 json={"redirect_uris": redir_uris},
236 verify=False,
237 )
238 client = api.get(url + "/clients", verify=False).json()["results"][0]
239
240 # cli client
241 cli_client = api.post(
242 url + "/clients",
243 json={
244 "name": "cli",
245 "first_party": True,
246 "client_type": "public",
247 "redirect_uris": redir_uris,
248 # "authorization_code_lifetime_seconds": 0,
249 # "access_id_token_lifetime_seconds": 0,
250 # "refresh_token_lifetime_seconds": 0,
251 "tenant_id": client["tenant_id"],
252 },
253 ).json()
254 cli_client_id = cli_client["id"]
255 print(
256 f"""Run the following setup to use the cli:
257 export AUTH_SERVER_URL=http://{fief_settings.fief_domain}
258 export API_URL=http://{carbonserver_settings.app_hostname}/api
259 export AUTH_CLIENT_ID={cli_client_id}
260 """
261 )

Callers 1

startFunction · 0.85

Calls 3

FiefSettingsClass · 0.85
jsonMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…