Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds internal service address for k8s internal calls #5

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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