2
2
import os
3
3
import sys
4
4
import re
5
-
6
5
from typing import Any
6
+
7
7
from django .core .management .base import BaseCommand
8
8
from django .conf import settings
9
+
9
10
from awx .conf import settings_registry
10
11
11
12
@@ -40,6 +41,15 @@ class Command(BaseCommand):
40
41
"USER_SEARCH" : False ,
41
42
}
42
43
44
+ def is_enabled (self , settings , keys ):
45
+ missing_fields = []
46
+ for key , required in keys .items ():
47
+ if required and not settings .get (key ):
48
+ missing_fields .append (key )
49
+ if missing_fields :
50
+ return False , missing_fields
51
+ return True , None
52
+
43
53
def get_awx_ldap_settings (self ) -> dict [str , dict [str , Any ]]:
44
54
awx_ldap_settings = {}
45
55
@@ -64,14 +74,16 @@ def get_awx_ldap_settings(self) -> dict[str, dict[str, Any]]:
64
74
65
75
if new_key == "SERVER_URI" and value :
66
76
value = value .split (", " )
77
+ grouped_settings [index ][new_key ] = value
67
78
68
- return grouped_settings
79
+ if type (value ).__name__ == "LDAPSearch" :
80
+ data = []
81
+ data .append (value .base_dn )
82
+ data .append ("SCOPE_SUBTREE" )
83
+ data .append (value .filterstr )
84
+ grouped_settings [index ][new_key ] = data
69
85
70
- def is_enabled (self , settings , keys ):
71
- for key , required in keys .items ():
72
- if required and not settings .get (key ):
73
- return False
74
- return True
86
+ return grouped_settings
75
87
76
88
def get_awx_saml_settings (self ) -> dict [str , Any ]:
77
89
awx_saml_settings = {}
@@ -82,7 +94,7 @@ def get_awx_saml_settings(self) -> dict[str, Any]:
82
94
83
95
def format_config_data (self , enabled , awx_settings , type , keys , name ):
84
96
config = {
85
- "type" : f"awx .authentication.authenticator_plugins.{ type } " ,
97
+ "type" : f"ansible_base .authentication.authenticator_plugins.{ type } " ,
86
98
"name" : name ,
87
99
"enabled" : enabled ,
88
100
"create_objects" : True ,
@@ -130,7 +142,7 @@ def handle(self, *args, **options):
130
142
131
143
# dump SAML settings
132
144
awx_saml_settings = self .get_awx_saml_settings ()
133
- awx_saml_enabled = self .is_enabled (awx_saml_settings , self .DAB_SAML_AUTHENTICATOR_KEYS )
145
+ awx_saml_enabled , saml_missing_fields = self .is_enabled (awx_saml_settings , self .DAB_SAML_AUTHENTICATOR_KEYS )
134
146
if awx_saml_enabled :
135
147
awx_saml_name = awx_saml_settings ["ENABLED_IDPS" ]
136
148
data .append (
@@ -142,21 +154,25 @@ def handle(self, *args, **options):
142
154
awx_saml_name ,
143
155
)
144
156
)
157
+ else :
158
+ data .append ({"SAML_missing_fields" : saml_missing_fields })
145
159
146
160
# dump LDAP settings
147
161
awx_ldap_group_settings = self .get_awx_ldap_settings ()
148
- for awx_ldap_name , awx_ldap_settings in enumerate ( awx_ldap_group_settings .values () ):
149
- enabled = self .is_enabled (awx_ldap_settings , self .DAB_LDAP_AUTHENTICATOR_KEYS )
150
- if enabled :
162
+ for awx_ldap_name , awx_ldap_settings in awx_ldap_group_settings .items ( ):
163
+ awx_ldap_enabled , ldap_missing_fields = self .is_enabled (awx_ldap_settings , self .DAB_LDAP_AUTHENTICATOR_KEYS )
164
+ if awx_ldap_enabled :
151
165
data .append (
152
166
self .format_config_data (
153
- enabled ,
167
+ awx_ldap_enabled ,
154
168
awx_ldap_settings ,
155
169
"ldap" ,
156
170
self .DAB_LDAP_AUTHENTICATOR_KEYS ,
157
- str ( awx_ldap_name ) ,
171
+ f"LDAP_ { awx_ldap_name } " ,
158
172
)
159
173
)
174
+ else :
175
+ data .append ({f"LDAP_{ awx_ldap_name } _missing_fields" : ldap_missing_fields })
160
176
161
177
# write to file if requested
162
178
if options ["output_file" ]:
0 commit comments