@@ -23,27 +23,27 @@ def get_random_string(length):
23
23
def get_hash (key ):
24
24
return hashlib .md5 (key .encode ('utf-8' )).hexdigest ()
25
25
26
- # gitea connection
26
+ # Gitea connection
27
27
configuration = giteapy .Configuration ()
28
28
configuration .api_key ['access_token' ] = 'superSecret'
29
29
configuration .host = 'https://gitea.example.com/api/v1'
30
30
admin_api_instance = giteapy .AdminApi (giteapy .ApiClient (configuration ))
31
31
user_api_instance = giteapy .UserApi (giteapy .ApiClient (configuration ))
32
32
org_api_instance = giteapy .OrganizationApi (giteapy .ApiClient (configuration ))
33
33
34
- # gitlab connection
34
+ # GitLab connection
35
35
gl = gitlab .Gitlab ('https://gitlab.example.com' , private_token = 'superSecret' )
36
36
37
37
# clean blocked users keys
38
38
for block_gl_user in gl .users .list (blocked = True , page = 1 , per_page = 10000 ):
39
39
print ("Blocked user" , block_gl_user .username )
40
40
for block_gl_user_key in block_gl_user .keys .list ():
41
- print ("Found key" , block_gl_user_key .title )
41
+ print ("Found a key" , block_gl_user_key .title )
42
42
block_gl_user_key .delete ()
43
43
44
- # inspect gitlab
44
+ # inspect GitLab
45
45
dict_gl_users = dict ()
46
- # get gitea users
46
+ # get Gitea users
47
47
gt_users = admin_api_instance .admin_get_all_users ()
48
48
pattern = re .compile ("^id_.+$" )
49
49
@@ -61,7 +61,7 @@ def get_hash(key):
61
61
res = gl .users .list (username = gt_user .login )
62
62
if len (res ) > 0 :
63
63
if res [0 ].attributes ['state' ] == 'blocked' :
64
- print ("Skip blocked user" , gt_user .login )
64
+ print ("Skip the blocked user" , gt_user .login )
65
65
continue
66
66
dict_gl_users [res [0 ].username ] = res [0 ]
67
67
gl_keys_dict = dict ()
@@ -72,7 +72,7 @@ def get_hash(key):
72
72
keys_to_delete = list ()
73
73
for raw_gl_key in gl_keys :
74
74
if pattern .match (raw_gl_key .title ):
75
- print (gt_user .login , "delete key" , raw_gl_key .title )
75
+ print (gt_user .login , "delete the key" , raw_gl_key .title )
76
76
raw_gl_key .delete ()
77
77
else :
78
78
gl_key_hash = get_hash (raw_gl_key .key .strip ().split (' ' )[1 ])
@@ -86,23 +86,23 @@ def get_hash(key):
86
86
if gt_key in gl_keys_dict :
87
87
keys_to_delete .remove (gt_key )
88
88
else :
89
- print (gt_user .login , "missing key" , gt_keys_dict [gt_key ].title )
89
+ print (gt_user .login , "missing a key" , gt_keys_dict [gt_key ].title )
90
90
try :
91
91
res [0 ].keys .create ({'title' : gt_keys_dict [gt_key ].title , 'key' : gt_keys_dict [gt_key ].key })
92
92
res [0 ].save ()
93
93
except :
94
94
all_problem_keys_dict .append (gt_key )
95
- print (gt_user .login , "can not add key" , gt_keys_dict [gt_key ].title )
95
+ print (gt_user .login , "can not add the key" , gt_keys_dict [gt_key ].title )
96
96
for dkey in keys_to_delete :
97
97
if pattern .match (gl_keys_dict [dkey ].title ):
98
- print (gt_user .login , "has additional key" , gl_keys_dict [dkey ].title )
98
+ print (gt_user .login , "has an additional key" , gl_keys_dict [dkey ].title )
99
99
#gl_keys_dict[key].delete()
100
100
else :
101
101
print ("New user" , gt_user .login )
102
102
103
- print ("Get problems key" , len (all_problem_keys_dict ))
103
+ print ("Get problematic key" , len (all_problem_keys_dict ))
104
104
for pkey in all_problem_keys_dict :
105
105
if pkey in all_gl_keys_dict :
106
- print ("Key " , pkey , "has user" , all_gl_keys_dict [pkey ])
106
+ print ("This key " , pkey , "has user" , all_gl_keys_dict [pkey ])
107
107
else :
108
108
print ("Can not find user for key" , pkey )
0 commit comments