From 5da414b81ae433d89713ff880f8de177f7d33cfb Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Tue, 5 Dec 2023 16:03:18 -0500 Subject: [PATCH 1/3] update tfsdk tag script, tags updated, rogue .txt --- .../model_authorization_server_settings.go | 4 +- configurationapi/model_idp_browser_sso.go | 2 +- configurationapi/model_idp_connection.go | 2 +- ...odel_idp_o_auth_grant_attribute_mapping.go | 2 +- configurationapi/model_ldap_data_store.go | 2 +- .../model_open_id_connect_policy.go | 2 +- scripts/generateTfsdkTags.py | 43 ++++++++++++------- text.txt | 16 ------- 8 files changed, 35 insertions(+), 38 deletions(-) delete mode 100644 text.txt diff --git a/configurationapi/model_authorization_server_settings.go b/configurationapi/model_authorization_server_settings.go index 8853cd1..5e88581 100644 --- a/configurationapi/model_authorization_server_settings.go +++ b/configurationapi/model_authorization_server_settings.go @@ -68,9 +68,9 @@ type AuthorizationServerSettings struct { AllowUnidentifiedClientExtensionGrants *bool `json:"allowUnidentifiedClientExtensionGrants,omitempty" tfsdk:"allow_unidentified_client_extension_grants"` AdminWebServicePcvRef *ResourceLink `json:"adminWebServicePcvRef,omitempty" tfsdk:"admin_web_service_pcv_ref"` // The ID of the Access Token Manager used for OAuth enabled grant management. - AtmIdForOAuthGrantManagement *string `json:"atmIdForOAuthGrantManagement,omitempty" tfsdk:"atm_id_for_oa_uth_grant_management"` + AtmIdForOAuthGrantManagement *string `json:"atmIdForOAuthGrantManagement,omitempty" tfsdk:"atm_id_for_oauth_grant_management"` // The OAuth scope to validate when accessing grant management service. - ScopeForOAuthGrantManagement *string `json:"scopeForOAuthGrantManagement,omitempty" tfsdk:"scope_for_oa_uth_grant_management"` + ScopeForOAuthGrantManagement *string `json:"scopeForOAuthGrantManagement,omitempty" tfsdk:"scope_for_oauth_grant_management"` // The list of allowed origins. AllowedOrigins []string `json:"allowedOrigins,omitempty" tfsdk:"allowed_origins"` // The URL used to generate 'verification_url' and 'verification_url_complete' values in a Device Authorization request diff --git a/configurationapi/model_idp_browser_sso.go b/configurationapi/model_idp_browser_sso.go index 6370b4b..2a9c448 100644 --- a/configurationapi/model_idp_browser_sso.go +++ b/configurationapi/model_idp_browser_sso.go @@ -53,7 +53,7 @@ type IdpBrowserSso struct { AdapterMappings []SpAdapterMapping `json:"adapterMappings,omitempty" tfsdk:"adapter_mappings"` // A list of Authentication Policy Contracts that map to incoming assertions. AuthenticationPolicyContractMappings []AuthenticationPolicyContractMapping `json:"authenticationPolicyContractMappings,omitempty" tfsdk:"authentication_policy_contract_mappings"` - SsoOAuthMapping *SsoOAuthMapping `json:"ssoOAuthMapping,omitempty" tfsdk:"sso_oa_uth_mapping"` + SsoOAuthMapping *SsoOAuthMapping `json:"ssoOAuthMapping,omitempty" tfsdk:"sso_oauth_mapping"` OauthAuthenticationPolicyContractRef *ResourceLink `json:"oauthAuthenticationPolicyContractRef,omitempty" tfsdk:"oauth_authentication_policy_contract_ref"` JitProvisioning *JitProvisioning `json:"jitProvisioning,omitempty" tfsdk:"jit_provisioning"` } diff --git a/configurationapi/model_idp_connection.go b/configurationapi/model_idp_connection.go index 5138f9a..13745d5 100644 --- a/configurationapi/model_idp_connection.go +++ b/configurationapi/model_idp_connection.go @@ -23,7 +23,7 @@ type IdpConnection struct { OidcClientCredentials *OIDCClientCredentials `json:"oidcClientCredentials,omitempty" tfsdk:"oidc_client_credentials"` IdpBrowserSso *IdpBrowserSso `json:"idpBrowserSso,omitempty" tfsdk:"idp_browser_sso"` AttributeQuery *IdpAttributeQuery `json:"attributeQuery,omitempty" tfsdk:"attribute_query"` - IdpOAuthGrantAttributeMapping *IdpOAuthGrantAttributeMapping `json:"idpOAuthGrantAttributeMapping,omitempty" tfsdk:"idp_oa_uth_grant_attribute_mapping"` + IdpOAuthGrantAttributeMapping *IdpOAuthGrantAttributeMapping `json:"idpOAuthGrantAttributeMapping,omitempty" tfsdk:"idp_oauth_grant_attribute_mapping"` WsTrust *IdpWsTrust `json:"wsTrust,omitempty" tfsdk:"ws_trust"` InboundProvisioning *IdpInboundProvisioning `json:"inboundProvisioning,omitempty" tfsdk:"inbound_provisioning"` // Identifier that specifies the message displayed on a user-facing error page. diff --git a/configurationapi/model_idp_o_auth_grant_attribute_mapping.go b/configurationapi/model_idp_o_auth_grant_attribute_mapping.go index 598e04a..eadb167 100644 --- a/configurationapi/model_idp_o_auth_grant_attribute_mapping.go +++ b/configurationapi/model_idp_o_auth_grant_attribute_mapping.go @@ -21,7 +21,7 @@ var _ MappedNullable = &IdpOAuthGrantAttributeMapping{} type IdpOAuthGrantAttributeMapping struct { // A mapping in a connection that defines how access tokens are created. AccessTokenManagerMappings []AccessTokenManagerMapping `json:"accessTokenManagerMappings,omitempty" tfsdk:"access_token_manager_mappings"` - IdpOAuthAttributeContract *IdpOAuthAttributeContract `json:"idpOAuthAttributeContract,omitempty" tfsdk:"idp_oa_uth_attribute_contract"` + IdpOAuthAttributeContract *IdpOAuthAttributeContract `json:"idpOAuthAttributeContract,omitempty" tfsdk:"idp_oauth_attribute_contract"` } // NewIdpOAuthGrantAttributeMapping instantiates a new IdpOAuthGrantAttributeMapping object diff --git a/configurationapi/model_ldap_data_store.go b/configurationapi/model_ldap_data_store.go index 4cd2769..6a9ecee 100644 --- a/configurationapi/model_ldap_data_store.go +++ b/configurationapi/model_ldap_data_store.go @@ -41,7 +41,7 @@ type LdapDataStore struct { // Use DNS SRV Records to discover LDAP server information. The default value is false. UseDnsSrvRecords *bool `json:"useDnsSrvRecords,omitempty" tfsdk:"use_dns_srv_records"` // Follow LDAP Referrals in the domain tree. The default value is false. This property does not apply to PingDirectory as this functionality is configured in PingDirectory. - FollowLDAPReferrals *bool `json:"followLDAPReferrals,omitempty" tfsdk:"follow_ldapr_eferrals"` + FollowLDAPReferrals *bool `json:"followLDAPReferrals,omitempty" tfsdk:"follow_ldap_referrals"` // Indicates whether objects are validated before being borrowed from the pool. TestOnBorrow *bool `json:"testOnBorrow,omitempty" tfsdk:"test_on_borrow"` // Indicates whether objects are validated before being returned to the pool. diff --git a/configurationapi/model_open_id_connect_policy.go b/configurationapi/model_open_id_connect_policy.go index a4d4c92..60d4a12 100644 --- a/configurationapi/model_open_id_connect_policy.go +++ b/configurationapi/model_open_id_connect_policy.go @@ -31,7 +31,7 @@ type OpenIdConnectPolicy struct { // Determines whether the User Info is always included in the ID token. IncludeUserInfoInIdToken *bool `json:"includeUserInfoInIdToken,omitempty" tfsdk:"include_user_info_in_id_token"` // Determines whether the State Hash should be included in the ID token. - IncludeSHashInIdToken *bool `json:"includeSHashInIdToken,omitempty" tfsdk:"include_sh_ash_in_id_token"` + IncludeSHashInIdToken *bool `json:"includeSHashInIdToken,omitempty" tfsdk:"include_shash_in_id_token"` // Determines whether an ID Token should be returned when refresh grant is requested or not. ReturnIdTokenOnRefreshGrant *bool `json:"returnIdTokenOnRefreshGrant,omitempty" tfsdk:"return_id_token_on_refresh_grant"` // Determines whether a new ID Token should be returned during token request of the hybrid flow. diff --git a/scripts/generateTfsdkTags.py b/scripts/generateTfsdkTags.py index 2d16416..ff2d0f9 100755 --- a/scripts/generateTfsdkTags.py +++ b/scripts/generateTfsdkTags.py @@ -7,6 +7,30 @@ modelFiles = glob.glob('model_*.go') jsonRegex = re.compile('`json:\"([0-9A-Za-z]*)[\",]') +def removeUnderscore(group) -> str: + return re.sub(r'_', '', group) + +def replaceCharWithUnderscorePlusChar(attribute) -> str: + underscoreAttribute = "" + match = re.findall(r'[0-9A-Z]', attribute) + if match != None: + underscoreAttribute = re.sub(r'([A-Z])', r'_\g<0>', attribute).lower() + fourUpperChars = re.findall(r'[A-Z]{4,4}', attribute) + threeUpperChars = re.findall(r'[A-Z]{3,3}', attribute) + twoUpperChars = re.findall(r'[A-Z]{2,2}', attribute) + if len(fourUpperChars) > 0: + underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscore(m.group()) + "_", underscoreAttribute).lower() + elif len(threeUpperChars) > 0: + underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscore(m.group(0)[:-1]) + m.group(0)[-1] + "_", underscoreAttribute).lower() + elif len(twoUpperChars) > 0 : + underscoreAttribute = re.sub(r'_[a-z]_[a-z]', lambda m: "_" + removeUnderscore(m.group(0)), underscoreAttribute).lower() + underscoreAttribute = underscoreAttribute.replace("__", "_") + else: + underscoreAttribute = attribute + if underscoreAttribute.endswith("_"): + underscoreAttribute = underscoreAttribute[:-1] + return underscoreAttribute + for modelFile in modelFiles: updatedLines = [] with open(modelFile, 'r') as model: @@ -16,23 +40,12 @@ # Ensure we don't add tfsdk tags to a line that already has one if match != None and "tfsdk:" not in line: # Get the attribute name from the json tag - attribute = match.group(1) - # Create a tfsdk tag for the attribute - underscoreAttribute = "" - i = 0 - lastCharUpper = False - while i < len(attribute): - if i > 0 and attribute[i].isupper() != attribute[i - 1].isupper(): - underscoreAttribute += "_" - underscoreAttribute += attribute[i].lower() - i += 1 - if i < len(attribute): - underscoreAttribute += attribute[i].lower() - i += 1 + attribute = str(match.group(1)) + finalAttribute = replaceCharWithUnderscorePlusChar(attribute) # Add the tfsdk tag to the line - line = line.replace("\"`", "\" tfsdk:\"{}\"`".format(underscoreAttribute)) + line = line.replace("\"`", "\" tfsdk:\"{}\"`".format(finalAttribute)) updatedLines.append(line) # Rewrite the file with open(modelFile, 'w') as model: for line in updatedLines: - model.write(line) + model.write(line) \ No newline at end of file diff --git a/text.txt b/text.txt deleted file mode 100644 index 6959de8..0000000 --- a/text.txt +++ /dev/null @@ -1,16 +0,0 @@ -curl 'https://localhost:9999/pf-admin-api' --header 'Authorization: Basic YWRtaW5pc3RyYXRvcjoyRmVkZXJhdGVNMHJl' \ - -H 'x-xsrf-header: PingFederate' \ - --insecure \ - -o text.json \ - -v - - - - -curl 'https://localhost:9999/pf-admin-api/v1/oauth/issuers' \ ---insecure \ --X POST \ - -H 'Accept: application/json'\ - -H 'Content-Type: application/json' -H 'X-XSRF-Header: PingFederate'\ - -H 'Authorization: Basic QWRtaW5pc3RyYXRvcjoyRmVkZXJhdGVNMHJl'\ - --data-raw $'{"name": "asdrgernfffmghrthre","description": "derhtsc","host": "hostnarthmey","path": "/pathhty3"}' \ No newline at end of file From 4733319651843a147ae082e1e1f61cae125cc1ec Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Tue, 5 Dec 2023 16:09:56 -0500 Subject: [PATCH 2/3] updated name of methods --- scripts/generateTfsdkTags.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/generateTfsdkTags.py b/scripts/generateTfsdkTags.py index ff2d0f9..085b43b 100755 --- a/scripts/generateTfsdkTags.py +++ b/scripts/generateTfsdkTags.py @@ -7,10 +7,10 @@ modelFiles = glob.glob('model_*.go') jsonRegex = re.compile('`json:\"([0-9A-Za-z]*)[\",]') -def removeUnderscore(group) -> str: +def removeUnderscoresFromGroup(group) -> str: return re.sub(r'_', '', group) -def replaceCharWithUnderscorePlusChar(attribute) -> str: +def buildAttributeValue(attribute) -> str: underscoreAttribute = "" match = re.findall(r'[0-9A-Z]', attribute) if match != None: @@ -19,11 +19,11 @@ def replaceCharWithUnderscorePlusChar(attribute) -> str: threeUpperChars = re.findall(r'[A-Z]{3,3}', attribute) twoUpperChars = re.findall(r'[A-Z]{2,2}', attribute) if len(fourUpperChars) > 0: - underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscore(m.group()) + "_", underscoreAttribute).lower() + underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group()) + "_", underscoreAttribute).lower() elif len(threeUpperChars) > 0: - underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscore(m.group(0)[:-1]) + m.group(0)[-1] + "_", underscoreAttribute).lower() + underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group(0)[:-1]) + m.group(0)[-1] + "_", underscoreAttribute).lower() elif len(twoUpperChars) > 0 : - underscoreAttribute = re.sub(r'_[a-z]_[a-z]', lambda m: "_" + removeUnderscore(m.group(0)), underscoreAttribute).lower() + underscoreAttribute = re.sub(r'_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group(0)), underscoreAttribute).lower() underscoreAttribute = underscoreAttribute.replace("__", "_") else: underscoreAttribute = attribute @@ -41,7 +41,7 @@ def replaceCharWithUnderscorePlusChar(attribute) -> str: if match != None and "tfsdk:" not in line: # Get the attribute name from the json tag attribute = str(match.group(1)) - finalAttribute = replaceCharWithUnderscorePlusChar(attribute) + finalAttribute = buildAttributeValue(attribute) # Add the tfsdk tag to the line line = line.replace("\"`", "\" tfsdk:\"{}\"`".format(finalAttribute)) updatedLines.append(line) From e0e24dabc47c95e64dfa886b42c395167a16f3a5 Mon Sep 17 00:00:00 2001 From: wesleymccollam Date: Tue, 5 Dec 2023 16:48:32 -0500 Subject: [PATCH 3/3] lambda consistency --- scripts/generateTfsdkTags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generateTfsdkTags.py b/scripts/generateTfsdkTags.py index 085b43b..9dc04c9 100755 --- a/scripts/generateTfsdkTags.py +++ b/scripts/generateTfsdkTags.py @@ -21,9 +21,9 @@ def buildAttributeValue(attribute) -> str: if len(fourUpperChars) > 0: underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group()) + "_", underscoreAttribute).lower() elif len(threeUpperChars) > 0: - underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group(0)[:-1]) + m.group(0)[-1] + "_", underscoreAttribute).lower() + underscoreAttribute = re.sub(r'_[a-z]_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group()) + "_", underscoreAttribute).lower() elif len(twoUpperChars) > 0 : - underscoreAttribute = re.sub(r'_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group(0)), underscoreAttribute).lower() + underscoreAttribute = re.sub(r'_[a-z]_[a-z]', lambda m: "_" + removeUnderscoresFromGroup(m.group()), underscoreAttribute).lower() underscoreAttribute = underscoreAttribute.replace("__", "_") else: underscoreAttribute = attribute