Skip to content

Commit

Permalink
Creates a user for the different envs as well to facilitate internal …
Browse files Browse the repository at this point in the history
…calls being made externally (#9)
  • Loading branch information
joerivrij authored Jun 5, 2023
1 parent cfcb0e6 commit 4efd8ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
35 changes: 20 additions & 15 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ ac = http://ac:8000/api/v1
brc = http://brc:8000/api/v1
drc = http://drc:8000/api/v1
nrc = http://nrc:8000/api/v1
vrl = http://vrl:8000/api/v1
zrc = http://zrc:8000/api/v1
ztc = http://ztc:8000/api/v1

[local]
ac = http://localhost:8000/api/v1
brc = http://localhost:8000/api/v1
drc = http://localhost:8000/api/v1
nrc = http://localhost:8000/api/v1
zrc = http://localhost:8000/api/v1
ztc = http://localhost:8000/api/v1

[test]
ac = https://autorisatie-api.test.vng.cloud
brc = https://besluiten-api.test.vng.cloud
drc = https://documenten-api.test.vng.cloud
nrc = https://notificaties-api.test.vng.cloud
vrl = https://referentielijsten-api.vng.cloud
zrc = https://zaken-api.test.vng.cloud
ztc = https://catalogi-api.test.vng.cloud
ac = https://autorisatie-api.test.vng.cloud/api/v1
brc = https://besluiten-api.test.vng.cloud/api/v1
drc = https://documenten-api.test.vng.cloud/api/v1
nrc = https://notificaties-api.test.vng.cloud/api/v1
zrc = https://zaken-api.test.vng.cloud/api/v1
ztc = https://catalogi-api.test.vng.cloud/api/v1

[production]
ac = https://autorisatie-api.vng.cloud
brc = https://besluiten-api.vng.cloud
drc = https://documenten-api.vng.cloud
nrc = https://notificaties-api.vng.cloud
vrl = https://referentielijsten-api.vng.cloud
zrc = https://zaken-api.vng.cloud
ztc = https://catalogi-api.vng.cloud
ac = https://autorisatie-api.vng.cloud/api/v1
brc = https://besluiten-api.vng.cloud/api/v1
drc = https://documenten-api.vng.cloud/api/v1
nrc = https://notificaties-api.vng.cloud/api/v1
zrc = https://zaken-api.vng.cloud/api/v1
ztc = https://catalogi-api.vng.cloud/api/v1
19 changes: 14 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_authenticated_app(
print(error)


def create_common_api_credential(api_config, client_id, secret, namespace, db_connection):
def create_common_api_credential(api_config, internal_config, client_id, secret, namespace, db_connection):
"""
Creates all the services with endpoints in the vng_api_common_apicredential table
So that each api trusts all the other internal apis
Expand All @@ -72,20 +72,27 @@ def create_common_api_credential(api_config, client_id, secret, namespace, db_co
try:
print(f"adding vng_api_common_apicredential with client_id: {client_id}")
cursor = db_connection.cursor()
for name in api_config:
for name in internal_config:
print(f"label set to api: {name}")
print(f"api_root set to: {api_config[name]}")
print(f"api_root set to: {internal_config[name]}")
internal_address = f"http://{name}.{namespace}.svc.cluster.local:8000/api/v1"
print(f"internal_address set to: {internal_address}")
cursor.execute(
"INSERT INTO vng_api_common_apicredential (api_root, client_id, secret, label, user_id, user_representation) VALUES(%s, %s, %s, %s, %s, %s)",
(api_config[name], client_id, secret, name, client_id, client_id),
(internal_config[name], client_id, secret, name, client_id, client_id),
)

cursor.execute(
"INSERT INTO vng_api_common_apicredential (api_root, client_id, secret, label, user_id, user_representation) VALUES(%s, %s, %s, %s, %s, %s)",
(internal_address, client_id, secret, name, client_id, client_id),
)

for n in api_config:
cursor.execute(
"INSERT INTO vng_api_common_apicredential (api_root, client_id, secret, label, user_id, user_representation) VALUES(%s, %s, %s, %s, %s, %s)",
(api_config[n], client_id, secret, n, client_id, client_id),
)

db_connection.commit()
cursor.close()
except (Exception, psycopg2.DatabaseError) as error:
Expand Down Expand Up @@ -134,7 +141,7 @@ def create_auth_config(auth_service, component, db_connection):

if __name__ == "__main__":
# variables will be read from the config.ini
env = os.environ.get("ENV", "kubernetes")
env = os.environ.get("ENV", "test")

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

config = configparser.ConfigParser()
config.read("config.ini")
internal_config = config['kubernetes']
api_config = config[env]

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

0 comments on commit 4efd8ad

Please sign in to comment.