Skip to content

Commit 538f5d9

Browse files
committed
Creates a user for the different envs as well to facilitate internal calls being made externally
1 parent cfcb0e6 commit 538f5d9

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

config.ini

+20-15
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ ac = http://ac:8000/api/v1
33
brc = http://brc:8000/api/v1
44
drc = http://drc:8000/api/v1
55
nrc = http://nrc:8000/api/v1
6-
vrl = http://vrl:8000/api/v1
76
zrc = http://zrc:8000/api/v1
87
ztc = http://ztc:8000/api/v1
98

9+
[local]
10+
ac = http://localhost:8000/api/v1
11+
brc = http://localhost:8000/api/v1
12+
drc = http://localhost:8000/api/v1
13+
nrc = http://localhost:8000/api/v1
14+
zrc = http://localhost:8000/api/v1
15+
ztc = http://localhost:8000/api/v1
16+
1017
[test]
11-
ac = https://autorisatie-api.test.vng.cloud
12-
brc = https://besluiten-api.test.vng.cloud
13-
drc = https://documenten-api.test.vng.cloud
14-
nrc = https://notificaties-api.test.vng.cloud
15-
vrl = https://referentielijsten-api.vng.cloud
16-
zrc = https://zaken-api.test.vng.cloud
17-
ztc = https://catalogi-api.test.vng.cloud
18+
ac = https://autorisatie-api.test.vng.cloud/api/v1
19+
brc = https://besluiten-api.test.vng.cloud/api/v1
20+
drc = https://documenten-api.test.vng.cloud/api/v1
21+
nrc = https://notificaties-api.test.vng.cloud/api/v1
22+
zrc = https://zaken-api.test.vng.cloud/api/v1
23+
ztc = https://catalogi-api.test.vng.cloud/api/v1
1824

1925
[production]
20-
ac = https://autorisatie-api.vng.cloud
21-
brc = https://besluiten-api.vng.cloud
22-
drc = https://documenten-api.vng.cloud
23-
nrc = https://notificaties-api.vng.cloud
24-
vrl = https://referentielijsten-api.vng.cloud
25-
zrc = https://zaken-api.vng.cloud
26-
ztc = https://catalogi-api.vng.cloud
26+
ac = https://autorisatie-api.vng.cloud/api/v1
27+
brc = https://besluiten-api.vng.cloud/api/v1
28+
drc = https://documenten-api.vng.cloud/api/v1
29+
nrc = https://notificaties-api.vng.cloud/api/v1
30+
zrc = https://zaken-api.vng.cloud/api/v1
31+
ztc = https://catalogi-api.vng.cloud/api/v1

main.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def create_authenticated_app(
5757
print(error)
5858

5959

60-
def create_common_api_credential(api_config, client_id, secret, namespace, db_connection):
60+
def create_common_api_credential(api_config, internal_config, client_id, secret, namespace, db_connection):
6161
"""
6262
Creates all the services with endpoints in the vng_api_common_apicredential table
6363
So that each api trusts all the other internal apis
@@ -72,20 +72,27 @@ def create_common_api_credential(api_config, client_id, secret, namespace, db_co
7272
try:
7373
print(f"adding vng_api_common_apicredential with client_id: {client_id}")
7474
cursor = db_connection.cursor()
75-
for name in api_config:
75+
for name in internal_config:
7676
print(f"label set to api: {name}")
77-
print(f"api_root set to: {api_config[name]}")
77+
print(f"api_root set to: {internal_config[name]}")
7878
internal_address = f"http://{name}.{namespace}.svc.cluster.local:8000/api/v1"
7979
print(f"internal_address set to: {internal_address}")
8080
cursor.execute(
8181
"INSERT INTO vng_api_common_apicredential (api_root, client_id, secret, label, user_id, user_representation) VALUES(%s, %s, %s, %s, %s, %s)",
82-
(api_config[name], client_id, secret, name, client_id, client_id),
82+
(internal_config[name], client_id, secret, name, client_id, client_id),
8383
)
8484

8585
cursor.execute(
8686
"INSERT INTO vng_api_common_apicredential (api_root, client_id, secret, label, user_id, user_representation) VALUES(%s, %s, %s, %s, %s, %s)",
8787
(internal_address, client_id, secret, name, client_id, client_id),
8888
)
89+
90+
for n in api_config:
91+
cursor.execute(
92+
"INSERT INTO vng_api_common_apicredential (api_root, client_id, secret, label, user_id, user_representation) VALUES(%s, %s, %s, %s, %s, %s)",
93+
(api_config[n], client_id, secret, n, client_id, client_id),
94+
)
95+
8996
db_connection.commit()
9097
cursor.close()
9198
except (Exception, psycopg2.DatabaseError) as error:
@@ -134,7 +141,7 @@ def create_auth_config(auth_service, component, db_connection):
134141

135142
if __name__ == "__main__":
136143
# variables will be read from the config.ini
137-
env = os.environ.get("ENV", "kubernetes")
144+
env = os.environ.get("ENV", "test")
138145

139146
# variables related to the db connection
140147
DB_NAME = os.environ.get("DB_NAME", "zrc")
@@ -166,6 +173,7 @@ def create_auth_config(auth_service, component, db_connection):
166173

167174
config = configparser.ConfigParser()
168175
config.read("config.ini")
176+
internal_config = config['kubernetes']
169177
api_config = config[env]
170178

171179
print(f"seeding db {DB_NAME}")
@@ -192,6 +200,7 @@ def create_auth_config(auth_service, component, db_connection):
192200
# add all endpoints with the secret so that the SERVICE_NAME will trust the other apis
193201
create_common_api_credential(
194202
api_config=api_config,
203+
internal_config=internal_config,
195204
client_id=SERVICE_NAME,
196205
secret=INTERNAL_API_SECRET,
197206
namespace=NAMESPACE,

0 commit comments

Comments
 (0)