Skip to content

Commit

Permalink
feat: adds internal service address for k8s internal calls
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivrij committed Mar 3, 2023
1 parent f0e1c12 commit fbd36e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ def create_authenticated_app(
print(error)


def create_common_api_credential(api_config, client_id, secret, db_connection):
def create_common_api_credential(api_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
The internal service address is also added so you can use the full internal address since
the short version will fail some URL regexes
:param api_config: a list of api names and endpoints (provided by config.ini)
:param client_id: a client_id part of the JWT
:param secret: the secret to identify the client_id
Expand All @@ -73,10 +75,17 @@ def create_common_api_credential(api_config, client_id, secret, db_connection):
for name in api_config:
print(f"label set to api: {name}")
print(f"api_root set to: {api_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),
)

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),
)
db_connection.commit()
cursor.close()
except (Exception, psycopg2.DatabaseError) as error:
Expand Down Expand Up @@ -133,6 +142,9 @@ def create_auth_config(auth_service, component, db_connection):
DB_USER = os.environ.get("DB_USER", "postgres")
DB_PASSWORD = os.environ.get("DB_PASSWORD", "supersecretpassword")

#namespace
NAMESPACE = os.environ.get("NAMESPACE", "vng")

# Identifier for the token-issuer
IDENTIFIER = os.environ.get("TOKEN_ISSUER_NAME", "token_issuer_demo")
# Secret for the token-issuer
Expand Down Expand Up @@ -182,6 +194,7 @@ def create_auth_config(auth_service, component, db_connection):
api_config=api_config,
client_id=SERVICE_NAME,
secret=INTERNAL_API_SECRET,
namespace=NAMESPACE,
db_connection=connection,
)

Expand Down

0 comments on commit fbd36e4

Please sign in to comment.