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

add OAuth2 config dump #15133

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions awx/main/management/commands/dump_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class Command(BaseCommand):
"USER_SEARCH": False,
}

DAB_OAUTH2_AUTHENTICATOR_KEYS = {
"CALLBACK_URL": False,
"KEY": True,
"SECRET": False,
"AUTH_EXTRA_ARGUMENTS": False,
}

def is_enabled(self, settings, keys):
missing_fields = []
for key, required in keys.items():
Expand Down Expand Up @@ -92,6 +99,13 @@ def get_awx_saml_settings(self) -> dict[str, Any]:

return awx_saml_settings

def get_awx_oauth2_settings(self) -> dict[str, Any]:
awx_oauth2_settings = {}
for awx_oauth2_setting in settings_registry.get_registered_settings(category_slug='google-oauth2'):
awx_oauth2_settings[awx_oauth2_setting.removeprefix("SOCIAL_AUTH_GOOGLE_OAUTH2_")] = getattr(settings, awx_oauth2_setting, None)

return awx_oauth2_settings

def format_config_data(self, enabled, awx_settings, type, keys, name):
config = {
"type": f"ansible_base.authentication.authenticator_plugins.{type}",
Expand Down Expand Up @@ -174,6 +188,22 @@ def handle(self, *args, **options):
else:
data.append({f"LDAP_{awx_ldap_name}_missing_fields": ldap_missing_fields})

# dump OAUTH2 settings
awx_oauth2_settings = self.get_awx_oauth2_settings()
awx_oauth2_enabled, oauth2_missing_fields = self.is_enabled(awx_oauth2_settings, self.DAB_OAUTH2_AUTHENTICATOR_KEYS)
if awx_oauth2_enabled:
data.append(
self.format_config_data(
awx_oauth2_enabled,
awx_oauth2_settings,
"google_oauth2",
self.DAB_OAUTH2_AUTHENTICATOR_KEYS,
"GOOGLE_OAUTH2",
)
)
else:
data.append({"OAUTH2_missing_fields": oauth2_missing_fields})

# write to file if requested
if options["output_file"]:
# Define the path for the output JSON file
Expand Down