raannakasturi commited on
Commit
a72d007
·
verified ·
1 Parent(s): 12b0c6f

Update getGoogleEAB.py

Browse files
Files changed (1) hide show
  1. getGoogleEAB.py +34 -31
getGoogleEAB.py CHANGED
@@ -1,32 +1,35 @@
1
- import os
2
- from dotenv import load_dotenv
3
- from google.oauth2 import service_account
4
- from google.cloud.security.publicca import PublicCertificateAuthorityServiceClient
5
-
6
- def gen_google_eab_data():
7
- load_dotenv()
8
- data = {
9
- "type": "service_account",
10
- "project_id": os.getenv("PROJECT_ID"),
11
- "private_key_id": os.getenv("PRIVATE_KEY_ID"),
12
- "private_key": os.getenv("PRIVATE_KEY"),
13
- "client_email": os.getenv("CLIENT_EMAIL"),
14
- "client_id": os.getenv("CLIENT_ID"),
15
- "auth_uri": os.getenv("AUTH_URI"),
16
- "token_uri": os.getenv("TOKEN_URI"),
17
- "auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_X509_CERT_URL"),
18
- "client_x509_cert_url": os.getenv("CLIENT_X509_CERT_URL"),
19
- "universe_domain": os.getenv("UNIVERSE_DOMAIN")
20
- }
21
- return data
22
-
23
- def gen_google_eab():
24
- service_account_info = gen_google_eab_data()
25
- credentials = service_account.Credentials.from_service_account_info(service_account_info)
26
- client = PublicCertificateAuthorityServiceClient(credentials=credentials)
27
- project_id = service_account_info['project_id']
28
- parent = f"projects/{project_id}"
29
- response = client.create_external_account_key(parent=parent)
30
- kid = response.key_id
31
- hmac = response.b64_mac_key
 
 
 
32
  return kid, hmac
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from google.oauth2 import service_account
4
+ from google.cloud.security.publicca import PublicCertificateAuthorityServiceClient
5
+
6
+ def gen_google_eab_data():
7
+ load_dotenv()
8
+ data = {
9
+ "type": "service_account",
10
+ "project_id": os.getenv("PROJECT_ID"),
11
+ "private_key_id": os.getenv("PRIVATE_KEY_ID"),
12
+ "private_key": os.getenv("PRIVATE_KEY"),
13
+ "client_email": os.getenv("CLIENT_EMAIL"),
14
+ "client_id": os.getenv("CLIENT_ID"),
15
+ "auth_uri": os.getenv("AUTH_URI"),
16
+ "token_uri": os.getenv("TOKEN_URI"),
17
+ "auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_X509_CERT_URL"),
18
+ "client_x509_cert_url": os.getenv("CLIENT_X509_CERT_URL"),
19
+ "universe_domain": os.getenv("UNIVERSE_DOMAIN")
20
+ }
21
+ return data
22
+
23
+ def gen_google_eab():
24
+ service_account_info = gen_google_eab_data()
25
+ try:
26
+ credentials = service_account.Credentials.from_service_account_info(service_account_info)
27
+ except Exception as e:
28
+ print(e)
29
+ client = PublicCertificateAuthorityServiceClient(credentials=credentials)
30
+ project_id = service_account_info['project_id']
31
+ parent = f"projects/{project_id}"
32
+ response = client.create_external_account_key(parent=parent)
33
+ kid = response.key_id
34
+ hmac = response.b64_mac_key
35
  return kid, hmac