1+ import json
12import os
23from typing import Annotated
34
1011from fastapi import HTTPException
1112from fastapi .security import HTTPBearer
1213
13- import json
14-
1514
1615load_dotenv ()
1716
3029# <<<
3130
3231
33-
3432def get_expose_api_map ():
3533 expose_api = {
3634 'gitlab' : False ,
3735 'github' : False ,
3836 'secret' : False ,
3937 }
4038
41-
4239 if None not in (
4340 GITLAB_SERVER ,
4441 GITLAB_TARGET_REPOSITORY_ID ,
@@ -53,12 +50,12 @@ def get_expose_api_map():
5350 ):
5451 expose_api ['github' ] = True
5552
56-
5753 if SECRET_TOKEN is not None :
5854 expose_api ['secret' ] = True
5955
6056 return expose_api
6157
58+
6259def get_jwt_keys ():
6360 gitlab_server_url = f'{ GITLAB_SERVER } /oauth/discovery/keys'
6461
@@ -89,6 +86,7 @@ def request_gitlab_sync(image):
8986 detail = f'Token server error: { request .text } ' ,
9087 )
9188
89+
9290def request_github_sync (image ):
9391 """
9492 https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
@@ -100,14 +98,14 @@ def request_github_sync(image):
10098 data = json .dumps ({
10199 'ref' : 'action-testing' ,
102100 'inputs' : {
103- 'image' : image
104- }
101+ 'image' : image ,
102+ },
105103 }),
106104 headers = {
107- 'Accept' : " application/vnd.github+json" ,
105+ 'Accept' : ' application/vnd.github+json' ,
108106 'Authorization' : f'Bearer { GITHUB_TOKEN } ' ,
109107 'X-GitHub-Api-Version' : '2022-11-28' ,
110- }
108+ },
111109 )
112110
113111 from pprint import pprint
@@ -133,11 +131,6 @@ def check_authorization(
133131 )
134132
135133
136-
137-
138-
139-
140-
141134app = FastAPI ()
142135
143136expose_api = get_expose_api_map ()
@@ -184,7 +177,6 @@ def sync_jwt(
184177 request_gitlab_sync (image )
185178
186179
187-
188180if expose_api ['secret' ] and expose_api ['gitlab' ]:
189181 @app .post ('/api/gitlab/sync/secret' )
190182 def sync_secret (
@@ -203,8 +195,6 @@ def sync_secret(
203195 request_gitlab_sync (image )
204196
205197
206-
207-
208198if expose_api ['secret' ] and expose_api ['github' ]:
209199 @app .post ('/api/github/sync/secret' )
210200 def sync_secret (
0 commit comments