From 97382b52c3f82db5bc0c302f54c68b7695738365 Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Fri, 30 Jun 2023 18:55:53 +0100 Subject: [PATCH 1/8] Add draft workspace settings --- agreementmanagement/GNUmakefile | 11 +- .../generate-replace-regex.go | 594 ++++++++++++++++++ pingone-go.code-workspace | 47 ++ scripts/generate.sh | 33 + 4 files changed, 684 insertions(+), 1 deletion(-) create mode 100644 agreementmanagement/generate-postprocessing/generate-replace-regex.go create mode 100644 pingone-go.code-workspace create mode 100755 scripts/generate.sh diff --git a/agreementmanagement/GNUmakefile b/agreementmanagement/GNUmakefile index 585c3a95..1b8feeb2 100644 --- a/agreementmanagement/GNUmakefile +++ b/agreementmanagement/GNUmakefile @@ -1,4 +1,7 @@ TEST?=$$(go list ./...) +OWNER=patrickcping +REPO=pingone-go-sdk-v2 +MODULE=agreementmanagement default: build @@ -32,4 +35,10 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint \ No newline at end of file +generate: + @echo "==> Running generate for $(MODULE)..." + @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) + +devcheck: build vet lint gosec test testacc + +.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file diff --git a/agreementmanagement/generate-postprocessing/generate-replace-regex.go b/agreementmanagement/generate-postprocessing/generate-replace-regex.go new file mode 100644 index 00000000..b78dc69b --- /dev/null +++ b/agreementmanagement/generate-postprocessing/generate-replace-regex.go @@ -0,0 +1,594 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" +) + +func main() { + // Get the target directory from the command line argument + if len(os.Args) < 2 { + println("Usage: go run script.go ") + return + } + dir := os.Args[1] + + for _, rule := range replaceRules { + // Get a list of all files with the given extension in the directory + files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern)) + if err != nil { + panic(err) + } + + // Iterate over the files and apply the regex replacement rules + for _, file := range files { + // Read the file contents + content, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + panic(err) + } + + // Apply the regex replacement rule + re := regexp.MustCompile(rule.pattern) + content = re.ReplaceAll(content, []byte(rule.repl)) + + // Write the updated file contents + err = os.WriteFile(file, content, os.ModePerm) + if err != nil { + panic(err) + } + } + } +} + +var ( + // Define the full list of regex replacement rules + replaceRules = []struct { + fileSelectPattern string + pattern string + repl string + }{ + + ///////////////////////// + // ALL configuration.go + ///////////////////////// + + { + fileSelectPattern: "configuration.go", + pattern: `"OpenAPI-Generator/([0-9]+\.[0-9]+\.[0-9]+)/go",`, + repl: `"PingOne-GOLANG-SDK/$1/go",`, + }, + + ///////////////////////// + // ALL API + ///////////////////////// + + // Add retryability to typed output + { + fileSelectPattern: "api_*.go", + pattern: `func \(([a-zA-Z0-9\* ]+)\) ([a-zA-Z])([a-zA-Z0-9]+Execute)\(([a-zA-Z0-9 ]*)\) \(([\*a-zA-Z0-9]*), \*http\.Response, error\) {`, + repl: `func ($1) $2$3($4) ($5, *http.Response, error) { + obj, response, error := processResponse( + func() (interface{}, *http.Response, error) { + return r.ApiService.internal$2$3(r) + }, + ) + return obj.($5), response, error +} + +func ($1) internal$2$3($4) ($5, *http.Response, error) {`, + }, + + // Add retryability to non-typed outputs + { + fileSelectPattern: "api_*.go", + pattern: `func \(([a-zA-Z0-9\* ]+)\) ([a-zA-Z])([a-zA-Z0-9]+Execute)\(([a-zA-Z0-9 ]*)\) \(\*http\.Response, error\) {`, + repl: `func ($1) $2$3($4) (*http.Response, error) { + _, response, error := processResponse( + func() (interface{}, *http.Response, error) { + resp, err := r.ApiService.internal$2$3(r) + return nil, resp, err + }, + ) + return response, error +} + +func ($1) internal$2$3($4) (*http.Response, error) {`, + }, + + // Handle errors for Github code scanning + { + fileSelectPattern: "api_*.go", + pattern: ` localVarHTTPResponse\.Body\.Close\(\)`, + repl: ` _ = localVarHTTPResponse.Body.Close()`, + }, + + ///////////////////////// + // Management: Password policy + ///////////////////////// + + // Password policy model + { + fileSelectPattern: "model_password_policy_min_characters.go", + pattern: `______`, + repl: `SpecialChar`, + }, + + { + fileSelectPattern: "model_password_policy_min_characters.go", + pattern: `json:"~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?,omitempty"`, + repl: `json:"specialchar,omitempty"`, + }, + + { + fileSelectPattern: "model_password_policy_min_characters.go", + pattern: `toSerialize\["~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?"]\ =\ o\.SpecialChar`, + repl: `toSerialize["~!@#$%^&*()-_=+[]{}|;:,.<>/?"] = o.SpecialChar`, + }, + + ///////////////////////// + // Management: Certificate + ///////////////////////// + + // Certificate model + { + fileSelectPattern: "model_certificate.go", + pattern: `int64`, + repl: `big.Int`, + }, + { + fileSelectPattern: "model_certificate.go", + pattern: `import \(`, + repl: `import ( + "math/big"`, + }, + + ///////////////////////// + // Risk: Risk Predictor + ///////////////////////// + + // RiskPredictor model + { + fileSelectPattern: "model_risk_predictor.go", + pattern: `(func \(dst \*RiskPredictor\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *RiskPredictor) UnmarshalJSON(data []byte) error { + + var common RiskPredictorCommon + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.RiskPredictorAnonymousNetwork = nil + dst.RiskPredictorComposite = nil + dst.RiskPredictorCustom = nil + dst.RiskPredictorGeovelocity = nil + dst.RiskPredictorIPReputation = nil + dst.RiskPredictorDevice = nil + dst.RiskPredictorUserRiskBehavior = nil + dst.RiskPredictorUserLocationAnomaly = nil + dst.RiskPredictorVelocity = nil + + switch common.GetType() { + case ENUMPREDICTORTYPE_ANONYMOUS_NETWORK: + if err := json.Unmarshal(data, &dst.RiskPredictorAnonymousNetwork); err != nil { + return err + } + case ENUMPREDICTORTYPE_COMPOSITE: + if err := json.Unmarshal(data, &dst.RiskPredictorComposite); err != nil { + return err + } + case ENUMPREDICTORTYPE_MAP: + if err := json.Unmarshal(data, &dst.RiskPredictorCustom); err != nil { + return err + } + case ENUMPREDICTORTYPE_GEO_VELOCITY: + if err := json.Unmarshal(data, &dst.RiskPredictorGeovelocity); err != nil { + return err + } + case ENUMPREDICTORTYPE_IP_REPUTATION: + if err := json.Unmarshal(data, &dst.RiskPredictorIPReputation); err != nil { + return err + } + case ENUMPREDICTORTYPE_DEVICE: + if err := json.Unmarshal(data, &dst.RiskPredictorDevice); err != nil { + return err + } + case ENUMPREDICTORTYPE_USER_RISK_BEHAVIOR: + if err := json.Unmarshal(data, &dst.RiskPredictorUserRiskBehavior); err != nil { + return err + } + case ENUMPREDICTORTYPE_USER_LOCATION_ANOMALY: + if err := json.Unmarshal(data, &dst.RiskPredictorUserLocationAnomaly); err != nil { + return err + } + case ENUMPREDICTORTYPE_VELOCITY: + if err := json.Unmarshal(data, &dst.RiskPredictorVelocity); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(RiskPredictor)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + // RiskPredictorCompositeCondition model + { + fileSelectPattern: "model_risk_predictor_composite_condition.go", + pattern: `(func \(dst \*RiskPredictorCompositeCondition\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *RiskPredictorCompositeCondition) UnmarshalJSON(data []byte) error { + + match := 0 + var common map[string]interface{} + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeConditionOneOf = nil + dst.RiskPredictorCompositeConditionOneOf1 = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + if common["and"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { + return err + } + match++ + } + + if common["or"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { + return err + } + match++ + } + + if common["not"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { + return err + } + match++ + } + + if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_STRING_LIST) { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf); err != nil { + return err + } + match++ + } + + if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_VALUE_COMPARISON) { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf1); err != nil { + return err + } + match++ + } + + if match > 1 { // more than 1 match + // reset to nil + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeConditionOneOf = nil + dst.RiskPredictorCompositeConditionOneOf1 = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeCondition)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeCondition)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + // RiskPredictorCompositeConditionBase model + { + fileSelectPattern: "model_risk_predictor_composite_condition_base.go", + pattern: `(func \(dst \*RiskPredictorCompositeConditionBase\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *RiskPredictorCompositeConditionBase) UnmarshalJSON(data []byte) error { + + match := 0 + var common map[string]interface{} + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + if common["and"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { + return err + } + match++ + } + + if common["or"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { + return err + } + match++ + } + + if common["not"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { + return err + } + match++ + } + + if match > 1 { // more than 1 match + // reset to nil + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeConditionBase)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeConditionBase)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + ///////////////////////// + // Credentials: EntityArrayEmbeddedItemsInner + ///////////////////////// + + // EntityArrayEmbeddedItemsInner model + { + fileSelectPattern: "model_entity_array__embedded_items_inner.go", + pattern: `(func \(dst \*EntityArrayEmbeddedItemsInner\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *EntityArrayEmbeddedItemsInner) UnmarshalJSON(data []byte) error { + + var err error + // try to unmarshal JSON data into CredentialType + err = json.Unmarshal(data, &dst.CredentialType); + if err == nil { + jsonCredentialType, _ := json.Marshal(dst.CredentialType) + if string(jsonCredentialType) == "{}" { // empty struct + dst.CredentialType = nil + } else { + if dst.CredentialType.CardDesignTemplate != "" { + return nil // data stored in dst.CredentialType, return on the first match + } else { + dst.CredentialType = nil + } + } + } else { + dst.CredentialType = nil + } + + // try to unmarshal JSON data into UserCredential + err = json.Unmarshal(data, &dst.UserCredential); + if err == nil { + jsonUserCredential, _ := json.Marshal(dst.UserCredential) + if string(jsonUserCredential) == "{}" { // empty struct + dst.UserCredential = nil + } else { + if dst.UserCredential.User.Id != "" { + return nil // data stored in dst.UserCredential, return on the first match + } else { + dst.UserCredential = nil + } + } + } else { + dst.UserCredential = nil + } + + return fmt.Errorf("data failed to match schemas in anyOf(EntityArrayEmbeddedItemsInner)") +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + // Management: FormField model + { + fileSelectPattern: "model_form_field.go", + pattern: `(func \(dst \*FormField\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *FormField) UnmarshalJSON(data []byte) error { + + var common FormFieldCommon + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.FormFieldCheckbox = nil + dst.FormFieldCombobox = nil + dst.FormFieldDivider = nil + dst.FormFieldDropdown = nil + dst.FormFieldEmptyField = nil + dst.FormFieldErrorDisplay = nil + dst.FormFieldFlowButton = nil + dst.FormFieldFlowLink = nil + dst.FormFieldPassword = nil + dst.FormFieldPasswordVerify = nil + dst.FormFieldQrCode = nil + dst.FormFieldRadio = nil + dst.FormFieldRecaptchaV2 = nil + dst.FormFieldSlateTextblob = nil + dst.FormFieldSocialLoginButton = nil + dst.FormFieldSubmitButton = nil + dst.FormFieldText = nil + + switch common.GetType() { + case ENUMFORMFIELDTYPE_TEXT: + if err := json.Unmarshal(data, &dst.FormFieldText); err != nil { + return err + } + case ENUMFORMFIELDTYPE_PASSWORD: + if err := json.Unmarshal(data, &dst.FormFieldPassword); err != nil { + return err + } + case ENUMFORMFIELDTYPE_PASSWORD_VERIFY: + if err := json.Unmarshal(data, &dst.FormFieldPasswordVerify); err != nil { + return err + } + case ENUMFORMFIELDTYPE_RADIO: + if err := json.Unmarshal(data, &dst.FormFieldRadio); err != nil { + return err + } + case ENUMFORMFIELDTYPE_CHECKBOX: + if err := json.Unmarshal(data, &dst.FormFieldCheckbox); err != nil { + return err + } + case ENUMFORMFIELDTYPE_DROPDOWN: + if err := json.Unmarshal(data, &dst.FormFieldDropdown); err != nil { + return err + } + case ENUMFORMFIELDTYPE_COMBOBOX: + if err := json.Unmarshal(data, &dst.FormFieldCombobox); err != nil { + return err + } + case ENUMFORMFIELDTYPE_DIVIDER: + if err := json.Unmarshal(data, &dst.FormFieldDivider); err != nil { + return err + } + case ENUMFORMFIELDTYPE_EMPTY_FIELD: + if err := json.Unmarshal(data, &dst.FormFieldEmptyField); err != nil { + return err + } + case ENUMFORMFIELDTYPE_TEXTBLOB: + if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { + return err + } + case ENUMFORMFIELDTYPE_SLATE_TEXTBLOB: + if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { + return err + } + case ENUMFORMFIELDTYPE_SUBMIT_BUTTON: + if err := json.Unmarshal(data, &dst.FormFieldSubmitButton); err != nil { + return err + } + case ENUMFORMFIELDTYPE_ERROR_DISPLAY: + if err := json.Unmarshal(data, &dst.FormFieldErrorDisplay); err != nil { + return err + } + case ENUMFORMFIELDTYPE_FLOW_LINK: + if err := json.Unmarshal(data, &dst.FormFieldFlowLink); err != nil { + return err + } + case ENUMFORMFIELDTYPE_FLOW_BUTTON: + if err := json.Unmarshal(data, &dst.FormFieldFlowButton); err != nil { + return err + } + case ENUMFORMFIELDTYPE_RECAPTCHA_V2: + if err := json.Unmarshal(data, &dst.FormFieldRecaptchaV2); err != nil { + return err + } + case ENUMFORMFIELDTYPE_QR_CODE: + if err := json.Unmarshal(data, &dst.FormFieldQrCode); err != nil { + return err + } + case ENUMFORMFIELDTYPE_SOCIAL_LOGIN_BUTTON: + if err := json.Unmarshal(data, &dst.FormFieldSocialLoginButton); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(FormField)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + // Management: NotificationsSettingsPhoneDeliverySettings model + { + fileSelectPattern: "model_notifications_settings_phone_delivery_settings.go", + pattern: `(func \(dst \*NotificationsSettingsPhoneDeliverySettings\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *NotificationsSettingsPhoneDeliverySettings) UnmarshalJSON(data []byte) error { + + var common NotificationsSettingsPhoneDeliverySettingsCommon + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.NotificationsSettingsPhoneDeliverySettingsCustom = nil + dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse = nil + + switch common.GetProvider() { + case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_TWILIO: + if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { + return err + } + case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_SYNIVERSE: + if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { + return err + } + case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_PROVIDER: + if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsCustom); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(NotificationsSettingsPhoneDeliverySettings)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + ///////////////////////// + // MFA: Push Notification Request + ///////////////////////// + + // MFAPushCredentialRequest model + { + fileSelectPattern: "model_mfa_push_credential_request.go", + pattern: `(func \(dst \*MFAPushCredentialRequest\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *MFAPushCredentialRequest) UnmarshalJSON(data []byte) error { + + var common MFAPushCredential + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.MFAPushCredentialAPNS = nil + dst.MFAPushCredentialFCM = nil + dst.MFAPushCredentialFCMHTTPV1 = nil + dst.MFAPushCredentialHMS = nil + + switch common.GetType() { + case ENUMMFAPUSHCREDENTIALATTRTYPE_APNS: + if err := json.Unmarshal(data, &dst.MFAPushCredentialAPNS); err != nil { + return err + } + case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM: + if err := json.Unmarshal(data, &dst.MFAPushCredentialFCM); err != nil { + return err + } + case ENUMMFAPUSHCREDENTIALATTRTYPE_HMS: + if err := json.Unmarshal(data, &dst.MFAPushCredentialHMS); err != nil { + return err + } + case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM_HTTP_V1: + if err := json.Unmarshal(data, &dst.MFAPushCredentialFCMHTTPV1); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(MFAPushCredentialRequest)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + } +) diff --git a/pingone-go.code-workspace b/pingone-go.code-workspace new file mode 100644 index 00000000..f6314a31 --- /dev/null +++ b/pingone-go.code-workspace @@ -0,0 +1,47 @@ +{ + "folders": [ + { + "name": "core-module", + "path": "." + }, + { + "name": "module-agreementmanagement", + "path": "agreementmanagement" + }, + { + "name": "module-authorize", + "path": "authorize" + }, + { + "name": "module-credentials", + "path": "credentials" + }, + { + "name": "module-management", + "path": "management" + }, + { + "name": "module-mfa", + "path": "mfa" + }, + { + "name": "module-risk", + "path": "risk" + }, + { + "name": "module-verify", + "path": "verify" + }, + ], + "settings": { + "files.exclude": { + "agreementmanagement": true, + "authorize": true, + "credentials": true, + "management": true, + "mfa": true, + "risk": true, + "verify": true, + }, + }, +} \ No newline at end of file diff --git a/scripts/generate.sh b/scripts/generate.sh new file mode 100755 index 00000000..4012e049 --- /dev/null +++ b/scripts/generate.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +if [ ! -d "../$3" ]; then + echo "Module $3 not found. Run this file from the module directory itself. Skipping..." + +else + echo "Module $3 found. Running generate.." + + # Generate from OpenAPI + version=$(head -n 1 .version) + + if [[ -f "../pingone-$3.yml" ]]; then \ + echo "==> Running codegen-$3..." + openapi-generator generate -i ../pingone-$3.yml -g go --additional-properties=packageName=$3,packageVersion=$version,isGoSubmodule=true,enumClassPrefix=true -o . --git-repo-id $2 --git-user-id $1; \ + go get -u ./... + go mod tidy + go mod vendor + + echo "==> Copying custom templated files..." + template=$(cat ../scripts/client_ext.go.tmpl) + template=${template//PACKAGENAME/$3} + echo "$template" > "client_ext.go" + + echo "==> Applying common postprocessing..." + go run ../scripts/generate-replace-regex.go . + + echo "==> Applying module specific postprocessing..." + go run generate-postprocessing/generate-replace-regex.go . + + else \ + echo "pingone-$3.yml missing. Skipping"; \ + fi +fi From a6c403eb878585f8aa80f0805e20ae682ea3f14f Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Fri, 30 Jun 2023 19:25:16 +0100 Subject: [PATCH 2/8] added postprocessing and build scripts --- .../generate-replace-regex.go | 544 +----------------- authorize/GNUmakefile | 11 +- .../generate-replace-regex.go | 52 ++ credentials/GNUmakefile | 11 +- .../generate-replace-regex.go | 100 ++++ management/GNUmakefile | 11 +- .../generate-replace-regex.go | 234 ++++++++ mfa/GNUmakefile | 11 +- .../generate-replace-regex.go | 96 ++++ risk/GNUmakefile | 11 +- .../generate-replace-regex.go | 249 ++++++++ scripts/generate-all.sh | 29 +- scripts/generate-replace-regex.go | 487 ---------------- verify/GNUmakefile | 11 +- .../generate-replace-regex.go | 52 ++ 15 files changed, 845 insertions(+), 1064 deletions(-) create mode 100644 authorize/generate-postprocessing/generate-replace-regex.go create mode 100644 credentials/generate-postprocessing/generate-replace-regex.go create mode 100644 management/generate-postprocessing/generate-replace-regex.go create mode 100644 mfa/generate-postprocessing/generate-replace-regex.go create mode 100644 risk/generate-postprocessing/generate-replace-regex.go create mode 100644 verify/generate-postprocessing/generate-replace-regex.go diff --git a/agreementmanagement/generate-postprocessing/generate-replace-regex.go b/agreementmanagement/generate-postprocessing/generate-replace-regex.go index b78dc69b..da47b2aa 100644 --- a/agreementmanagement/generate-postprocessing/generate-replace-regex.go +++ b/agreementmanagement/generate-postprocessing/generate-replace-regex.go @@ -48,547 +48,5 @@ var ( fileSelectPattern string pattern string repl string - }{ - - ///////////////////////// - // ALL configuration.go - ///////////////////////// - - { - fileSelectPattern: "configuration.go", - pattern: `"OpenAPI-Generator/([0-9]+\.[0-9]+\.[0-9]+)/go",`, - repl: `"PingOne-GOLANG-SDK/$1/go",`, - }, - - ///////////////////////// - // ALL API - ///////////////////////// - - // Add retryability to typed output - { - fileSelectPattern: "api_*.go", - pattern: `func \(([a-zA-Z0-9\* ]+)\) ([a-zA-Z])([a-zA-Z0-9]+Execute)\(([a-zA-Z0-9 ]*)\) \(([\*a-zA-Z0-9]*), \*http\.Response, error\) {`, - repl: `func ($1) $2$3($4) ($5, *http.Response, error) { - obj, response, error := processResponse( - func() (interface{}, *http.Response, error) { - return r.ApiService.internal$2$3(r) - }, - ) - return obj.($5), response, error -} - -func ($1) internal$2$3($4) ($5, *http.Response, error) {`, - }, - - // Add retryability to non-typed outputs - { - fileSelectPattern: "api_*.go", - pattern: `func \(([a-zA-Z0-9\* ]+)\) ([a-zA-Z])([a-zA-Z0-9]+Execute)\(([a-zA-Z0-9 ]*)\) \(\*http\.Response, error\) {`, - repl: `func ($1) $2$3($4) (*http.Response, error) { - _, response, error := processResponse( - func() (interface{}, *http.Response, error) { - resp, err := r.ApiService.internal$2$3(r) - return nil, resp, err - }, - ) - return response, error -} - -func ($1) internal$2$3($4) (*http.Response, error) {`, - }, - - // Handle errors for Github code scanning - { - fileSelectPattern: "api_*.go", - pattern: ` localVarHTTPResponse\.Body\.Close\(\)`, - repl: ` _ = localVarHTTPResponse.Body.Close()`, - }, - - ///////////////////////// - // Management: Password policy - ///////////////////////// - - // Password policy model - { - fileSelectPattern: "model_password_policy_min_characters.go", - pattern: `______`, - repl: `SpecialChar`, - }, - - { - fileSelectPattern: "model_password_policy_min_characters.go", - pattern: `json:"~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?,omitempty"`, - repl: `json:"specialchar,omitempty"`, - }, - - { - fileSelectPattern: "model_password_policy_min_characters.go", - pattern: `toSerialize\["~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?"]\ =\ o\.SpecialChar`, - repl: `toSerialize["~!@#$%^&*()-_=+[]{}|;:,.<>/?"] = o.SpecialChar`, - }, - - ///////////////////////// - // Management: Certificate - ///////////////////////// - - // Certificate model - { - fileSelectPattern: "model_certificate.go", - pattern: `int64`, - repl: `big.Int`, - }, - { - fileSelectPattern: "model_certificate.go", - pattern: `import \(`, - repl: `import ( - "math/big"`, - }, - - ///////////////////////// - // Risk: Risk Predictor - ///////////////////////// - - // RiskPredictor model - { - fileSelectPattern: "model_risk_predictor.go", - pattern: `(func \(dst \*RiskPredictor\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *RiskPredictor) UnmarshalJSON(data []byte) error { - - var common RiskPredictorCommon - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.RiskPredictorAnonymousNetwork = nil - dst.RiskPredictorComposite = nil - dst.RiskPredictorCustom = nil - dst.RiskPredictorGeovelocity = nil - dst.RiskPredictorIPReputation = nil - dst.RiskPredictorDevice = nil - dst.RiskPredictorUserRiskBehavior = nil - dst.RiskPredictorUserLocationAnomaly = nil - dst.RiskPredictorVelocity = nil - - switch common.GetType() { - case ENUMPREDICTORTYPE_ANONYMOUS_NETWORK: - if err := json.Unmarshal(data, &dst.RiskPredictorAnonymousNetwork); err != nil { - return err - } - case ENUMPREDICTORTYPE_COMPOSITE: - if err := json.Unmarshal(data, &dst.RiskPredictorComposite); err != nil { - return err - } - case ENUMPREDICTORTYPE_MAP: - if err := json.Unmarshal(data, &dst.RiskPredictorCustom); err != nil { - return err - } - case ENUMPREDICTORTYPE_GEO_VELOCITY: - if err := json.Unmarshal(data, &dst.RiskPredictorGeovelocity); err != nil { - return err - } - case ENUMPREDICTORTYPE_IP_REPUTATION: - if err := json.Unmarshal(data, &dst.RiskPredictorIPReputation); err != nil { - return err - } - case ENUMPREDICTORTYPE_DEVICE: - if err := json.Unmarshal(data, &dst.RiskPredictorDevice); err != nil { - return err - } - case ENUMPREDICTORTYPE_USER_RISK_BEHAVIOR: - if err := json.Unmarshal(data, &dst.RiskPredictorUserRiskBehavior); err != nil { - return err - } - case ENUMPREDICTORTYPE_USER_LOCATION_ANOMALY: - if err := json.Unmarshal(data, &dst.RiskPredictorUserLocationAnomaly); err != nil { - return err - } - case ENUMPREDICTORTYPE_VELOCITY: - if err := json.Unmarshal(data, &dst.RiskPredictorVelocity); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(RiskPredictor)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // RiskPredictorCompositeCondition model - { - fileSelectPattern: "model_risk_predictor_composite_condition.go", - pattern: `(func \(dst \*RiskPredictorCompositeCondition\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *RiskPredictorCompositeCondition) UnmarshalJSON(data []byte) error { - - match := 0 - var common map[string]interface{} - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeConditionOneOf = nil - dst.RiskPredictorCompositeConditionOneOf1 = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - if common["and"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { - return err - } - match++ - } - - if common["or"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { - return err - } - match++ - } - - if common["not"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { - return err - } - match++ - } - - if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_STRING_LIST) { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf); err != nil { - return err - } - match++ - } - - if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_VALUE_COMPARISON) { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf1); err != nil { - return err - } - match++ - } - - if match > 1 { // more than 1 match - // reset to nil - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeConditionOneOf = nil - dst.RiskPredictorCompositeConditionOneOf1 = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeCondition)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeCondition)") - } -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // RiskPredictorCompositeConditionBase model - { - fileSelectPattern: "model_risk_predictor_composite_condition_base.go", - pattern: `(func \(dst \*RiskPredictorCompositeConditionBase\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *RiskPredictorCompositeConditionBase) UnmarshalJSON(data []byte) error { - - match := 0 - var common map[string]interface{} - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - if common["and"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { - return err - } - match++ - } - - if common["or"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { - return err - } - match++ - } - - if common["not"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { - return err - } - match++ - } - - if match > 1 { // more than 1 match - // reset to nil - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeConditionBase)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeConditionBase)") - } -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - ///////////////////////// - // Credentials: EntityArrayEmbeddedItemsInner - ///////////////////////// - - // EntityArrayEmbeddedItemsInner model - { - fileSelectPattern: "model_entity_array__embedded_items_inner.go", - pattern: `(func \(dst \*EntityArrayEmbeddedItemsInner\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *EntityArrayEmbeddedItemsInner) UnmarshalJSON(data []byte) error { - - var err error - // try to unmarshal JSON data into CredentialType - err = json.Unmarshal(data, &dst.CredentialType); - if err == nil { - jsonCredentialType, _ := json.Marshal(dst.CredentialType) - if string(jsonCredentialType) == "{}" { // empty struct - dst.CredentialType = nil - } else { - if dst.CredentialType.CardDesignTemplate != "" { - return nil // data stored in dst.CredentialType, return on the first match - } else { - dst.CredentialType = nil - } - } - } else { - dst.CredentialType = nil - } - - // try to unmarshal JSON data into UserCredential - err = json.Unmarshal(data, &dst.UserCredential); - if err == nil { - jsonUserCredential, _ := json.Marshal(dst.UserCredential) - if string(jsonUserCredential) == "{}" { // empty struct - dst.UserCredential = nil - } else { - if dst.UserCredential.User.Id != "" { - return nil // data stored in dst.UserCredential, return on the first match - } else { - dst.UserCredential = nil - } - } - } else { - dst.UserCredential = nil - } - - return fmt.Errorf("data failed to match schemas in anyOf(EntityArrayEmbeddedItemsInner)") -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // Management: FormField model - { - fileSelectPattern: "model_form_field.go", - pattern: `(func \(dst \*FormField\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *FormField) UnmarshalJSON(data []byte) error { - - var common FormFieldCommon - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.FormFieldCheckbox = nil - dst.FormFieldCombobox = nil - dst.FormFieldDivider = nil - dst.FormFieldDropdown = nil - dst.FormFieldEmptyField = nil - dst.FormFieldErrorDisplay = nil - dst.FormFieldFlowButton = nil - dst.FormFieldFlowLink = nil - dst.FormFieldPassword = nil - dst.FormFieldPasswordVerify = nil - dst.FormFieldQrCode = nil - dst.FormFieldRadio = nil - dst.FormFieldRecaptchaV2 = nil - dst.FormFieldSlateTextblob = nil - dst.FormFieldSocialLoginButton = nil - dst.FormFieldSubmitButton = nil - dst.FormFieldText = nil - - switch common.GetType() { - case ENUMFORMFIELDTYPE_TEXT: - if err := json.Unmarshal(data, &dst.FormFieldText); err != nil { - return err - } - case ENUMFORMFIELDTYPE_PASSWORD: - if err := json.Unmarshal(data, &dst.FormFieldPassword); err != nil { - return err - } - case ENUMFORMFIELDTYPE_PASSWORD_VERIFY: - if err := json.Unmarshal(data, &dst.FormFieldPasswordVerify); err != nil { - return err - } - case ENUMFORMFIELDTYPE_RADIO: - if err := json.Unmarshal(data, &dst.FormFieldRadio); err != nil { - return err - } - case ENUMFORMFIELDTYPE_CHECKBOX: - if err := json.Unmarshal(data, &dst.FormFieldCheckbox); err != nil { - return err - } - case ENUMFORMFIELDTYPE_DROPDOWN: - if err := json.Unmarshal(data, &dst.FormFieldDropdown); err != nil { - return err - } - case ENUMFORMFIELDTYPE_COMBOBOX: - if err := json.Unmarshal(data, &dst.FormFieldCombobox); err != nil { - return err - } - case ENUMFORMFIELDTYPE_DIVIDER: - if err := json.Unmarshal(data, &dst.FormFieldDivider); err != nil { - return err - } - case ENUMFORMFIELDTYPE_EMPTY_FIELD: - if err := json.Unmarshal(data, &dst.FormFieldEmptyField); err != nil { - return err - } - case ENUMFORMFIELDTYPE_TEXTBLOB: - if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { - return err - } - case ENUMFORMFIELDTYPE_SLATE_TEXTBLOB: - if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { - return err - } - case ENUMFORMFIELDTYPE_SUBMIT_BUTTON: - if err := json.Unmarshal(data, &dst.FormFieldSubmitButton); err != nil { - return err - } - case ENUMFORMFIELDTYPE_ERROR_DISPLAY: - if err := json.Unmarshal(data, &dst.FormFieldErrorDisplay); err != nil { - return err - } - case ENUMFORMFIELDTYPE_FLOW_LINK: - if err := json.Unmarshal(data, &dst.FormFieldFlowLink); err != nil { - return err - } - case ENUMFORMFIELDTYPE_FLOW_BUTTON: - if err := json.Unmarshal(data, &dst.FormFieldFlowButton); err != nil { - return err - } - case ENUMFORMFIELDTYPE_RECAPTCHA_V2: - if err := json.Unmarshal(data, &dst.FormFieldRecaptchaV2); err != nil { - return err - } - case ENUMFORMFIELDTYPE_QR_CODE: - if err := json.Unmarshal(data, &dst.FormFieldQrCode); err != nil { - return err - } - case ENUMFORMFIELDTYPE_SOCIAL_LOGIN_BUTTON: - if err := json.Unmarshal(data, &dst.FormFieldSocialLoginButton); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(FormField)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // Management: NotificationsSettingsPhoneDeliverySettings model - { - fileSelectPattern: "model_notifications_settings_phone_delivery_settings.go", - pattern: `(func \(dst \*NotificationsSettingsPhoneDeliverySettings\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *NotificationsSettingsPhoneDeliverySettings) UnmarshalJSON(data []byte) error { - - var common NotificationsSettingsPhoneDeliverySettingsCommon - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.NotificationsSettingsPhoneDeliverySettingsCustom = nil - dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse = nil - - switch common.GetProvider() { - case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_TWILIO: - if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { - return err - } - case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_SYNIVERSE: - if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { - return err - } - case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_PROVIDER: - if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsCustom); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(NotificationsSettingsPhoneDeliverySettings)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - ///////////////////////// - // MFA: Push Notification Request - ///////////////////////// - - // MFAPushCredentialRequest model - { - fileSelectPattern: "model_mfa_push_credential_request.go", - pattern: `(func \(dst \*MFAPushCredentialRequest\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *MFAPushCredentialRequest) UnmarshalJSON(data []byte) error { - - var common MFAPushCredential - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.MFAPushCredentialAPNS = nil - dst.MFAPushCredentialFCM = nil - dst.MFAPushCredentialFCMHTTPV1 = nil - dst.MFAPushCredentialHMS = nil - - switch common.GetType() { - case ENUMMFAPUSHCREDENTIALATTRTYPE_APNS: - if err := json.Unmarshal(data, &dst.MFAPushCredentialAPNS); err != nil { - return err - } - case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM: - if err := json.Unmarshal(data, &dst.MFAPushCredentialFCM); err != nil { - return err - } - case ENUMMFAPUSHCREDENTIALATTRTYPE_HMS: - if err := json.Unmarshal(data, &dst.MFAPushCredentialHMS); err != nil { - return err - } - case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM_HTTP_V1: - if err := json.Unmarshal(data, &dst.MFAPushCredentialFCMHTTPV1); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(MFAPushCredentialRequest)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - } + }{} ) diff --git a/authorize/GNUmakefile b/authorize/GNUmakefile index 585c3a95..5dd0069c 100644 --- a/authorize/GNUmakefile +++ b/authorize/GNUmakefile @@ -1,4 +1,7 @@ TEST?=$$(go list ./...) +OWNER=patrickcping +REPO=pingone-go-sdk-v2 +MODULE=authorize default: build @@ -32,4 +35,10 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint \ No newline at end of file +generate: + @echo "==> Running generate for $(MODULE)..." + @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) + +devcheck: build vet lint gosec test testacc + +.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file diff --git a/authorize/generate-postprocessing/generate-replace-regex.go b/authorize/generate-postprocessing/generate-replace-regex.go new file mode 100644 index 00000000..da47b2aa --- /dev/null +++ b/authorize/generate-postprocessing/generate-replace-regex.go @@ -0,0 +1,52 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" +) + +func main() { + // Get the target directory from the command line argument + if len(os.Args) < 2 { + println("Usage: go run script.go ") + return + } + dir := os.Args[1] + + for _, rule := range replaceRules { + // Get a list of all files with the given extension in the directory + files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern)) + if err != nil { + panic(err) + } + + // Iterate over the files and apply the regex replacement rules + for _, file := range files { + // Read the file contents + content, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + panic(err) + } + + // Apply the regex replacement rule + re := regexp.MustCompile(rule.pattern) + content = re.ReplaceAll(content, []byte(rule.repl)) + + // Write the updated file contents + err = os.WriteFile(file, content, os.ModePerm) + if err != nil { + panic(err) + } + } + } +} + +var ( + // Define the full list of regex replacement rules + replaceRules = []struct { + fileSelectPattern string + pattern string + repl string + }{} +) diff --git a/credentials/GNUmakefile b/credentials/GNUmakefile index 585c3a95..08d1c6a3 100644 --- a/credentials/GNUmakefile +++ b/credentials/GNUmakefile @@ -1,4 +1,7 @@ TEST?=$$(go list ./...) +OWNER=patrickcping +REPO=pingone-go-sdk-v2 +MODULE=credentials default: build @@ -32,4 +35,10 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint \ No newline at end of file +generate: + @echo "==> Running generate for $(MODULE)..." + @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) + +devcheck: build vet lint gosec test testacc + +.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file diff --git a/credentials/generate-postprocessing/generate-replace-regex.go b/credentials/generate-postprocessing/generate-replace-regex.go new file mode 100644 index 00000000..83a90b15 --- /dev/null +++ b/credentials/generate-postprocessing/generate-replace-regex.go @@ -0,0 +1,100 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" +) + +func main() { + // Get the target directory from the command line argument + if len(os.Args) < 2 { + println("Usage: go run script.go ") + return + } + dir := os.Args[1] + + for _, rule := range replaceRules { + // Get a list of all files with the given extension in the directory + files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern)) + if err != nil { + panic(err) + } + + // Iterate over the files and apply the regex replacement rules + for _, file := range files { + // Read the file contents + content, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + panic(err) + } + + // Apply the regex replacement rule + re := regexp.MustCompile(rule.pattern) + content = re.ReplaceAll(content, []byte(rule.repl)) + + // Write the updated file contents + err = os.WriteFile(file, content, os.ModePerm) + if err != nil { + panic(err) + } + } + } +} + +var ( + // Define the full list of regex replacement rules + replaceRules = []struct { + fileSelectPattern string + pattern string + repl string + }{ + + // EntityArrayEmbeddedItemsInner model + { + fileSelectPattern: "model_entity_array__embedded_items_inner.go", + pattern: `(func \(dst \*EntityArrayEmbeddedItemsInner\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *EntityArrayEmbeddedItemsInner) UnmarshalJSON(data []byte) error { + + var err error + // try to unmarshal JSON data into CredentialType + err = json.Unmarshal(data, &dst.CredentialType); + if err == nil { + jsonCredentialType, _ := json.Marshal(dst.CredentialType) + if string(jsonCredentialType) == "{}" { // empty struct + dst.CredentialType = nil + } else { + if dst.CredentialType.CardDesignTemplate != "" { + return nil // data stored in dst.CredentialType, return on the first match + } else { + dst.CredentialType = nil + } + } + } else { + dst.CredentialType = nil + } + + // try to unmarshal JSON data into UserCredential + err = json.Unmarshal(data, &dst.UserCredential); + if err == nil { + jsonUserCredential, _ := json.Marshal(dst.UserCredential) + if string(jsonUserCredential) == "{}" { // empty struct + dst.UserCredential = nil + } else { + if dst.UserCredential.User.Id != "" { + return nil // data stored in dst.UserCredential, return on the first match + } else { + dst.UserCredential = nil + } + } + } else { + dst.UserCredential = nil + } + + return fmt.Errorf("data failed to match schemas in anyOf(EntityArrayEmbeddedItemsInner)") +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + } +) diff --git a/management/GNUmakefile b/management/GNUmakefile index 585c3a95..199c314a 100644 --- a/management/GNUmakefile +++ b/management/GNUmakefile @@ -1,4 +1,7 @@ TEST?=$$(go list ./...) +OWNER=patrickcping +REPO=pingone-go-sdk-v2 +MODULE=management default: build @@ -32,4 +35,10 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint \ No newline at end of file +generate: + @echo "==> Running generate for $(MODULE)..." + @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) + +devcheck: build vet lint gosec test testacc + +.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file diff --git a/management/generate-postprocessing/generate-replace-regex.go b/management/generate-postprocessing/generate-replace-regex.go new file mode 100644 index 00000000..c49caf5b --- /dev/null +++ b/management/generate-postprocessing/generate-replace-regex.go @@ -0,0 +1,234 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" +) + +func main() { + // Get the target directory from the command line argument + if len(os.Args) < 2 { + println("Usage: go run script.go ") + return + } + dir := os.Args[1] + + for _, rule := range replaceRules { + // Get a list of all files with the given extension in the directory + files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern)) + if err != nil { + panic(err) + } + + // Iterate over the files and apply the regex replacement rules + for _, file := range files { + // Read the file contents + content, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + panic(err) + } + + // Apply the regex replacement rule + re := regexp.MustCompile(rule.pattern) + content = re.ReplaceAll(content, []byte(rule.repl)) + + // Write the updated file contents + err = os.WriteFile(file, content, os.ModePerm) + if err != nil { + panic(err) + } + } + } +} + +var ( + // Define the full list of regex replacement rules + replaceRules = []struct { + fileSelectPattern string + pattern string + repl string + }{ + + // Password policy model + { + fileSelectPattern: "model_password_policy_min_characters.go", + pattern: `______`, + repl: `SpecialChar`, + }, + + { + fileSelectPattern: "model_password_policy_min_characters.go", + pattern: `json:"~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?,omitempty"`, + repl: `json:"specialchar,omitempty"`, + }, + + { + fileSelectPattern: "model_password_policy_min_characters.go", + pattern: `toSerialize\["~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?"]\ =\ o\.SpecialChar`, + repl: `toSerialize["~!@#$%^&*()-_=+[]{}|;:,.<>/?"] = o.SpecialChar`, + }, + + // Certificate model + { + fileSelectPattern: "model_certificate.go", + pattern: `int64`, + repl: `big.Int`, + }, + { + fileSelectPattern: "model_certificate.go", + pattern: `import \(`, + repl: `import ( + "math/big"`, + }, + + // Management: FormField model + { + fileSelectPattern: "model_form_field.go", + pattern: `(func \(dst \*FormField\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *FormField) UnmarshalJSON(data []byte) error { + + var common FormFieldCommon + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.FormFieldCheckbox = nil + dst.FormFieldCombobox = nil + dst.FormFieldDivider = nil + dst.FormFieldDropdown = nil + dst.FormFieldEmptyField = nil + dst.FormFieldErrorDisplay = nil + dst.FormFieldFlowButton = nil + dst.FormFieldFlowLink = nil + dst.FormFieldPassword = nil + dst.FormFieldPasswordVerify = nil + dst.FormFieldQrCode = nil + dst.FormFieldRadio = nil + dst.FormFieldRecaptchaV2 = nil + dst.FormFieldSlateTextblob = nil + dst.FormFieldSocialLoginButton = nil + dst.FormFieldSubmitButton = nil + dst.FormFieldText = nil + + switch common.GetType() { + case ENUMFORMFIELDTYPE_TEXT: + if err := json.Unmarshal(data, &dst.FormFieldText); err != nil { + return err + } + case ENUMFORMFIELDTYPE_PASSWORD: + if err := json.Unmarshal(data, &dst.FormFieldPassword); err != nil { + return err + } + case ENUMFORMFIELDTYPE_PASSWORD_VERIFY: + if err := json.Unmarshal(data, &dst.FormFieldPasswordVerify); err != nil { + return err + } + case ENUMFORMFIELDTYPE_RADIO: + if err := json.Unmarshal(data, &dst.FormFieldRadio); err != nil { + return err + } + case ENUMFORMFIELDTYPE_CHECKBOX: + if err := json.Unmarshal(data, &dst.FormFieldCheckbox); err != nil { + return err + } + case ENUMFORMFIELDTYPE_DROPDOWN: + if err := json.Unmarshal(data, &dst.FormFieldDropdown); err != nil { + return err + } + case ENUMFORMFIELDTYPE_COMBOBOX: + if err := json.Unmarshal(data, &dst.FormFieldCombobox); err != nil { + return err + } + case ENUMFORMFIELDTYPE_DIVIDER: + if err := json.Unmarshal(data, &dst.FormFieldDivider); err != nil { + return err + } + case ENUMFORMFIELDTYPE_EMPTY_FIELD: + if err := json.Unmarshal(data, &dst.FormFieldEmptyField); err != nil { + return err + } + case ENUMFORMFIELDTYPE_TEXTBLOB: + if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { + return err + } + case ENUMFORMFIELDTYPE_SLATE_TEXTBLOB: + if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { + return err + } + case ENUMFORMFIELDTYPE_SUBMIT_BUTTON: + if err := json.Unmarshal(data, &dst.FormFieldSubmitButton); err != nil { + return err + } + case ENUMFORMFIELDTYPE_ERROR_DISPLAY: + if err := json.Unmarshal(data, &dst.FormFieldErrorDisplay); err != nil { + return err + } + case ENUMFORMFIELDTYPE_FLOW_LINK: + if err := json.Unmarshal(data, &dst.FormFieldFlowLink); err != nil { + return err + } + case ENUMFORMFIELDTYPE_FLOW_BUTTON: + if err := json.Unmarshal(data, &dst.FormFieldFlowButton); err != nil { + return err + } + case ENUMFORMFIELDTYPE_RECAPTCHA_V2: + if err := json.Unmarshal(data, &dst.FormFieldRecaptchaV2); err != nil { + return err + } + case ENUMFORMFIELDTYPE_QR_CODE: + if err := json.Unmarshal(data, &dst.FormFieldQrCode); err != nil { + return err + } + case ENUMFORMFIELDTYPE_SOCIAL_LOGIN_BUTTON: + if err := json.Unmarshal(data, &dst.FormFieldSocialLoginButton); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(FormField)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + // Management: NotificationsSettingsPhoneDeliverySettings model + { + fileSelectPattern: "model_notifications_settings_phone_delivery_settings.go", + pattern: `(func \(dst \*NotificationsSettingsPhoneDeliverySettings\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *NotificationsSettingsPhoneDeliverySettings) UnmarshalJSON(data []byte) error { + + var common NotificationsSettingsPhoneDeliverySettingsCommon + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.NotificationsSettingsPhoneDeliverySettingsCustom = nil + dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse = nil + + switch common.GetProvider() { + case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_TWILIO: + if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { + return err + } + case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_SYNIVERSE: + if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { + return err + } + case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_PROVIDER: + if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsCustom); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(NotificationsSettingsPhoneDeliverySettings)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + } +) diff --git a/mfa/GNUmakefile b/mfa/GNUmakefile index 585c3a95..7bd0be49 100644 --- a/mfa/GNUmakefile +++ b/mfa/GNUmakefile @@ -1,4 +1,7 @@ TEST?=$$(go list ./...) +OWNER=patrickcping +REPO=pingone-go-sdk-v2 +MODULE=mfa default: build @@ -32,4 +35,10 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint \ No newline at end of file +generate: + @echo "==> Running generate for $(MODULE)..." + @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) + +devcheck: build vet lint gosec test testacc + +.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file diff --git a/mfa/generate-postprocessing/generate-replace-regex.go b/mfa/generate-postprocessing/generate-replace-regex.go new file mode 100644 index 00000000..b0e10ee4 --- /dev/null +++ b/mfa/generate-postprocessing/generate-replace-regex.go @@ -0,0 +1,96 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" +) + +func main() { + // Get the target directory from the command line argument + if len(os.Args) < 2 { + println("Usage: go run script.go ") + return + } + dir := os.Args[1] + + for _, rule := range replaceRules { + // Get a list of all files with the given extension in the directory + files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern)) + if err != nil { + panic(err) + } + + // Iterate over the files and apply the regex replacement rules + for _, file := range files { + // Read the file contents + content, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + panic(err) + } + + // Apply the regex replacement rule + re := regexp.MustCompile(rule.pattern) + content = re.ReplaceAll(content, []byte(rule.repl)) + + // Write the updated file contents + err = os.WriteFile(file, content, os.ModePerm) + if err != nil { + panic(err) + } + } + } +} + +var ( + // Define the full list of regex replacement rules + replaceRules = []struct { + fileSelectPattern string + pattern string + repl string + }{ + + // MFAPushCredentialRequest model + { + fileSelectPattern: "model_mfa_push_credential_request.go", + pattern: `(func \(dst \*MFAPushCredentialRequest\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *MFAPushCredentialRequest) UnmarshalJSON(data []byte) error { + + var common MFAPushCredential + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.MFAPushCredentialAPNS = nil + dst.MFAPushCredentialFCM = nil + dst.MFAPushCredentialFCMHTTPV1 = nil + dst.MFAPushCredentialHMS = nil + + switch common.GetType() { + case ENUMMFAPUSHCREDENTIALATTRTYPE_APNS: + if err := json.Unmarshal(data, &dst.MFAPushCredentialAPNS); err != nil { + return err + } + case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM: + if err := json.Unmarshal(data, &dst.MFAPushCredentialFCM); err != nil { + return err + } + case ENUMMFAPUSHCREDENTIALATTRTYPE_HMS: + if err := json.Unmarshal(data, &dst.MFAPushCredentialHMS); err != nil { + return err + } + case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM_HTTP_V1: + if err := json.Unmarshal(data, &dst.MFAPushCredentialFCMHTTPV1); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(MFAPushCredentialRequest)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + } +) diff --git a/risk/GNUmakefile b/risk/GNUmakefile index 585c3a95..287af2d4 100644 --- a/risk/GNUmakefile +++ b/risk/GNUmakefile @@ -1,4 +1,7 @@ TEST?=$$(go list ./...) +OWNER=patrickcping +REPO=pingone-go-sdk-v2 +MODULE=risk default: build @@ -32,4 +35,10 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint \ No newline at end of file +generate: + @echo "==> Running generate for $(MODULE)..." + @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) + +devcheck: build vet lint gosec test testacc + +.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file diff --git a/risk/generate-postprocessing/generate-replace-regex.go b/risk/generate-postprocessing/generate-replace-regex.go new file mode 100644 index 00000000..082f4034 --- /dev/null +++ b/risk/generate-postprocessing/generate-replace-regex.go @@ -0,0 +1,249 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" +) + +func main() { + // Get the target directory from the command line argument + if len(os.Args) < 2 { + println("Usage: go run script.go ") + return + } + dir := os.Args[1] + + for _, rule := range replaceRules { + // Get a list of all files with the given extension in the directory + files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern)) + if err != nil { + panic(err) + } + + // Iterate over the files and apply the regex replacement rules + for _, file := range files { + // Read the file contents + content, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + panic(err) + } + + // Apply the regex replacement rule + re := regexp.MustCompile(rule.pattern) + content = re.ReplaceAll(content, []byte(rule.repl)) + + // Write the updated file contents + err = os.WriteFile(file, content, os.ModePerm) + if err != nil { + panic(err) + } + } + } +} + +var ( + // Define the full list of regex replacement rules + replaceRules = []struct { + fileSelectPattern string + pattern string + repl string + }{ + + // RiskPredictor model + { + fileSelectPattern: "model_risk_predictor.go", + pattern: `(func \(dst \*RiskPredictor\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *RiskPredictor) UnmarshalJSON(data []byte) error { + + var common RiskPredictorCommon + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.RiskPredictorAnonymousNetwork = nil + dst.RiskPredictorComposite = nil + dst.RiskPredictorCustom = nil + dst.RiskPredictorGeovelocity = nil + dst.RiskPredictorIPReputation = nil + dst.RiskPredictorDevice = nil + dst.RiskPredictorUserRiskBehavior = nil + dst.RiskPredictorUserLocationAnomaly = nil + dst.RiskPredictorVelocity = nil + + switch common.GetType() { + case ENUMPREDICTORTYPE_ANONYMOUS_NETWORK: + if err := json.Unmarshal(data, &dst.RiskPredictorAnonymousNetwork); err != nil { + return err + } + case ENUMPREDICTORTYPE_COMPOSITE: + if err := json.Unmarshal(data, &dst.RiskPredictorComposite); err != nil { + return err + } + case ENUMPREDICTORTYPE_MAP: + if err := json.Unmarshal(data, &dst.RiskPredictorCustom); err != nil { + return err + } + case ENUMPREDICTORTYPE_GEO_VELOCITY: + if err := json.Unmarshal(data, &dst.RiskPredictorGeovelocity); err != nil { + return err + } + case ENUMPREDICTORTYPE_IP_REPUTATION: + if err := json.Unmarshal(data, &dst.RiskPredictorIPReputation); err != nil { + return err + } + case ENUMPREDICTORTYPE_DEVICE: + if err := json.Unmarshal(data, &dst.RiskPredictorDevice); err != nil { + return err + } + case ENUMPREDICTORTYPE_USER_RISK_BEHAVIOR: + if err := json.Unmarshal(data, &dst.RiskPredictorUserRiskBehavior); err != nil { + return err + } + case ENUMPREDICTORTYPE_USER_LOCATION_ANOMALY: + if err := json.Unmarshal(data, &dst.RiskPredictorUserLocationAnomaly); err != nil { + return err + } + case ENUMPREDICTORTYPE_VELOCITY: + if err := json.Unmarshal(data, &dst.RiskPredictorVelocity); err != nil { + return err + } + default: + return fmt.Errorf("Data failed to match schemas in oneOf(RiskPredictor)") + } + return nil +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + // RiskPredictorCompositeCondition model + { + fileSelectPattern: "model_risk_predictor_composite_condition.go", + pattern: `(func \(dst \*RiskPredictorCompositeCondition\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *RiskPredictorCompositeCondition) UnmarshalJSON(data []byte) error { + + match := 0 + var common map[string]interface{} + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeConditionOneOf = nil + dst.RiskPredictorCompositeConditionOneOf1 = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + if common["and"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { + return err + } + match++ + } + + if common["or"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { + return err + } + match++ + } + + if common["not"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { + return err + } + match++ + } + + if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_STRING_LIST) { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf); err != nil { + return err + } + match++ + } + + if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_VALUE_COMPARISON) { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf1); err != nil { + return err + } + match++ + } + + if match > 1 { // more than 1 match + // reset to nil + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeConditionOneOf = nil + dst.RiskPredictorCompositeConditionOneOf1 = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeCondition)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeCondition)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + + // RiskPredictorCompositeConditionBase model + { + fileSelectPattern: "model_risk_predictor_composite_condition_base.go", + pattern: `(func \(dst \*RiskPredictorCompositeConditionBase\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, + repl: `func (dst *RiskPredictorCompositeConditionBase) UnmarshalJSON(data []byte) error { + + match := 0 + var common map[string]interface{} + + if err := json.Unmarshal(data, &common); err != nil { + return err + } + + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + if common["and"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { + return err + } + match++ + } + + if common["or"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { + return err + } + match++ + } + + if common["not"] != nil { + if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { + return err + } + match++ + } + + if match > 1 { // more than 1 match + // reset to nil + dst.RiskPredictorCompositeAnd = nil + dst.RiskPredictorCompositeNot = nil + dst.RiskPredictorCompositeOr = nil + + return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeConditionBase)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeConditionBase)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON`, + }, + } +) diff --git a/scripts/generate-all.sh b/scripts/generate-all.sh index c71e3612..8ef35b72 100755 --- a/scripts/generate-all.sh +++ b/scripts/generate-all.sh @@ -6,39 +6,12 @@ declare -a arr=("agreementmanagement" "authorize" "credentials" "davinci" "manag ## now loop through the above array for i in "${arr[@]}" do - echo "$i ...." - if [ ! -d "$i" ]; then echo "Module $i not found. Skipping..." else - echo "Module $i found. Running generate.." - - # Generate from OpenAPI pushd $i - echo "==> Running codegen-$i..." - - version=$(head -n 1 .version) - - if [[ -f "../pingone-$i.yml" ]]; then \ - openapi-generator generate -i ../pingone-$i.yml -g go --additional-properties=packageName=$i,packageVersion=$version,isGoSubmodule=true,enumClassPrefix=true -o . --git-repo-id $2 --git-user-id $1; \ - go get -u ./... - go mod tidy - go mod vendor - - # Generate the retry code - template=$(cat ../scripts/client_ext.go.tmpl) - template=${template//PACKAGENAME/$i} - echo "$template" > "client_ext.go" - - go run ../scripts/generate-replace-regex.go . - - else \ - echo "pingone-$i.yml missing. Skipping"; \ - fi + make generate popd - fi - done - diff --git a/scripts/generate-replace-regex.go b/scripts/generate-replace-regex.go index b78dc69b..42a0c9d5 100644 --- a/scripts/generate-replace-regex.go +++ b/scripts/generate-replace-regex.go @@ -103,492 +103,5 @@ func ($1) internal$2$3($4) (*http.Response, error) {`, pattern: ` localVarHTTPResponse\.Body\.Close\(\)`, repl: ` _ = localVarHTTPResponse.Body.Close()`, }, - - ///////////////////////// - // Management: Password policy - ///////////////////////// - - // Password policy model - { - fileSelectPattern: "model_password_policy_min_characters.go", - pattern: `______`, - repl: `SpecialChar`, - }, - - { - fileSelectPattern: "model_password_policy_min_characters.go", - pattern: `json:"~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?,omitempty"`, - repl: `json:"specialchar,omitempty"`, - }, - - { - fileSelectPattern: "model_password_policy_min_characters.go", - pattern: `toSerialize\["~!@\#\$%\^&\*\(\)-_&\#x3D;\+\[]\{}\|;:,\.<>/\?"]\ =\ o\.SpecialChar`, - repl: `toSerialize["~!@#$%^&*()-_=+[]{}|;:,.<>/?"] = o.SpecialChar`, - }, - - ///////////////////////// - // Management: Certificate - ///////////////////////// - - // Certificate model - { - fileSelectPattern: "model_certificate.go", - pattern: `int64`, - repl: `big.Int`, - }, - { - fileSelectPattern: "model_certificate.go", - pattern: `import \(`, - repl: `import ( - "math/big"`, - }, - - ///////////////////////// - // Risk: Risk Predictor - ///////////////////////// - - // RiskPredictor model - { - fileSelectPattern: "model_risk_predictor.go", - pattern: `(func \(dst \*RiskPredictor\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *RiskPredictor) UnmarshalJSON(data []byte) error { - - var common RiskPredictorCommon - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.RiskPredictorAnonymousNetwork = nil - dst.RiskPredictorComposite = nil - dst.RiskPredictorCustom = nil - dst.RiskPredictorGeovelocity = nil - dst.RiskPredictorIPReputation = nil - dst.RiskPredictorDevice = nil - dst.RiskPredictorUserRiskBehavior = nil - dst.RiskPredictorUserLocationAnomaly = nil - dst.RiskPredictorVelocity = nil - - switch common.GetType() { - case ENUMPREDICTORTYPE_ANONYMOUS_NETWORK: - if err := json.Unmarshal(data, &dst.RiskPredictorAnonymousNetwork); err != nil { - return err - } - case ENUMPREDICTORTYPE_COMPOSITE: - if err := json.Unmarshal(data, &dst.RiskPredictorComposite); err != nil { - return err - } - case ENUMPREDICTORTYPE_MAP: - if err := json.Unmarshal(data, &dst.RiskPredictorCustom); err != nil { - return err - } - case ENUMPREDICTORTYPE_GEO_VELOCITY: - if err := json.Unmarshal(data, &dst.RiskPredictorGeovelocity); err != nil { - return err - } - case ENUMPREDICTORTYPE_IP_REPUTATION: - if err := json.Unmarshal(data, &dst.RiskPredictorIPReputation); err != nil { - return err - } - case ENUMPREDICTORTYPE_DEVICE: - if err := json.Unmarshal(data, &dst.RiskPredictorDevice); err != nil { - return err - } - case ENUMPREDICTORTYPE_USER_RISK_BEHAVIOR: - if err := json.Unmarshal(data, &dst.RiskPredictorUserRiskBehavior); err != nil { - return err - } - case ENUMPREDICTORTYPE_USER_LOCATION_ANOMALY: - if err := json.Unmarshal(data, &dst.RiskPredictorUserLocationAnomaly); err != nil { - return err - } - case ENUMPREDICTORTYPE_VELOCITY: - if err := json.Unmarshal(data, &dst.RiskPredictorVelocity); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(RiskPredictor)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // RiskPredictorCompositeCondition model - { - fileSelectPattern: "model_risk_predictor_composite_condition.go", - pattern: `(func \(dst \*RiskPredictorCompositeCondition\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *RiskPredictorCompositeCondition) UnmarshalJSON(data []byte) error { - - match := 0 - var common map[string]interface{} - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeConditionOneOf = nil - dst.RiskPredictorCompositeConditionOneOf1 = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - if common["and"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { - return err - } - match++ - } - - if common["or"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { - return err - } - match++ - } - - if common["not"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { - return err - } - match++ - } - - if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_STRING_LIST) { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf); err != nil { - return err - } - match++ - } - - if v, ok := common["type"].(string); ok && v == string(ENUMPREDICTORCOMPOSITECONDITIONTYPE_VALUE_COMPARISON) { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeConditionOneOf1); err != nil { - return err - } - match++ - } - - if match > 1 { // more than 1 match - // reset to nil - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeConditionOneOf = nil - dst.RiskPredictorCompositeConditionOneOf1 = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeCondition)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeCondition)") - } -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // RiskPredictorCompositeConditionBase model - { - fileSelectPattern: "model_risk_predictor_composite_condition_base.go", - pattern: `(func \(dst \*RiskPredictorCompositeConditionBase\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *RiskPredictorCompositeConditionBase) UnmarshalJSON(data []byte) error { - - match := 0 - var common map[string]interface{} - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - if common["and"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeAnd); err != nil { - return err - } - match++ - } - - if common["or"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeOr); err != nil { - return err - } - match++ - } - - if common["not"] != nil { - if err := json.Unmarshal(data, &dst.RiskPredictorCompositeNot); err != nil { - return err - } - match++ - } - - if match > 1 { // more than 1 match - // reset to nil - dst.RiskPredictorCompositeAnd = nil - dst.RiskPredictorCompositeNot = nil - dst.RiskPredictorCompositeOr = nil - - return fmt.Errorf("data matches more than one schema in oneOf(RiskPredictorCompositeConditionBase)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("data failed to match schemas in oneOf(RiskPredictorCompositeConditionBase)") - } -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - ///////////////////////// - // Credentials: EntityArrayEmbeddedItemsInner - ///////////////////////// - - // EntityArrayEmbeddedItemsInner model - { - fileSelectPattern: "model_entity_array__embedded_items_inner.go", - pattern: `(func \(dst \*EntityArrayEmbeddedItemsInner\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *EntityArrayEmbeddedItemsInner) UnmarshalJSON(data []byte) error { - - var err error - // try to unmarshal JSON data into CredentialType - err = json.Unmarshal(data, &dst.CredentialType); - if err == nil { - jsonCredentialType, _ := json.Marshal(dst.CredentialType) - if string(jsonCredentialType) == "{}" { // empty struct - dst.CredentialType = nil - } else { - if dst.CredentialType.CardDesignTemplate != "" { - return nil // data stored in dst.CredentialType, return on the first match - } else { - dst.CredentialType = nil - } - } - } else { - dst.CredentialType = nil - } - - // try to unmarshal JSON data into UserCredential - err = json.Unmarshal(data, &dst.UserCredential); - if err == nil { - jsonUserCredential, _ := json.Marshal(dst.UserCredential) - if string(jsonUserCredential) == "{}" { // empty struct - dst.UserCredential = nil - } else { - if dst.UserCredential.User.Id != "" { - return nil // data stored in dst.UserCredential, return on the first match - } else { - dst.UserCredential = nil - } - } - } else { - dst.UserCredential = nil - } - - return fmt.Errorf("data failed to match schemas in anyOf(EntityArrayEmbeddedItemsInner)") -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // Management: FormField model - { - fileSelectPattern: "model_form_field.go", - pattern: `(func \(dst \*FormField\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *FormField) UnmarshalJSON(data []byte) error { - - var common FormFieldCommon - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.FormFieldCheckbox = nil - dst.FormFieldCombobox = nil - dst.FormFieldDivider = nil - dst.FormFieldDropdown = nil - dst.FormFieldEmptyField = nil - dst.FormFieldErrorDisplay = nil - dst.FormFieldFlowButton = nil - dst.FormFieldFlowLink = nil - dst.FormFieldPassword = nil - dst.FormFieldPasswordVerify = nil - dst.FormFieldQrCode = nil - dst.FormFieldRadio = nil - dst.FormFieldRecaptchaV2 = nil - dst.FormFieldSlateTextblob = nil - dst.FormFieldSocialLoginButton = nil - dst.FormFieldSubmitButton = nil - dst.FormFieldText = nil - - switch common.GetType() { - case ENUMFORMFIELDTYPE_TEXT: - if err := json.Unmarshal(data, &dst.FormFieldText); err != nil { - return err - } - case ENUMFORMFIELDTYPE_PASSWORD: - if err := json.Unmarshal(data, &dst.FormFieldPassword); err != nil { - return err - } - case ENUMFORMFIELDTYPE_PASSWORD_VERIFY: - if err := json.Unmarshal(data, &dst.FormFieldPasswordVerify); err != nil { - return err - } - case ENUMFORMFIELDTYPE_RADIO: - if err := json.Unmarshal(data, &dst.FormFieldRadio); err != nil { - return err - } - case ENUMFORMFIELDTYPE_CHECKBOX: - if err := json.Unmarshal(data, &dst.FormFieldCheckbox); err != nil { - return err - } - case ENUMFORMFIELDTYPE_DROPDOWN: - if err := json.Unmarshal(data, &dst.FormFieldDropdown); err != nil { - return err - } - case ENUMFORMFIELDTYPE_COMBOBOX: - if err := json.Unmarshal(data, &dst.FormFieldCombobox); err != nil { - return err - } - case ENUMFORMFIELDTYPE_DIVIDER: - if err := json.Unmarshal(data, &dst.FormFieldDivider); err != nil { - return err - } - case ENUMFORMFIELDTYPE_EMPTY_FIELD: - if err := json.Unmarshal(data, &dst.FormFieldEmptyField); err != nil { - return err - } - case ENUMFORMFIELDTYPE_TEXTBLOB: - if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { - return err - } - case ENUMFORMFIELDTYPE_SLATE_TEXTBLOB: - if err := json.Unmarshal(data, &dst.FormFieldSlateTextblob); err != nil { - return err - } - case ENUMFORMFIELDTYPE_SUBMIT_BUTTON: - if err := json.Unmarshal(data, &dst.FormFieldSubmitButton); err != nil { - return err - } - case ENUMFORMFIELDTYPE_ERROR_DISPLAY: - if err := json.Unmarshal(data, &dst.FormFieldErrorDisplay); err != nil { - return err - } - case ENUMFORMFIELDTYPE_FLOW_LINK: - if err := json.Unmarshal(data, &dst.FormFieldFlowLink); err != nil { - return err - } - case ENUMFORMFIELDTYPE_FLOW_BUTTON: - if err := json.Unmarshal(data, &dst.FormFieldFlowButton); err != nil { - return err - } - case ENUMFORMFIELDTYPE_RECAPTCHA_V2: - if err := json.Unmarshal(data, &dst.FormFieldRecaptchaV2); err != nil { - return err - } - case ENUMFORMFIELDTYPE_QR_CODE: - if err := json.Unmarshal(data, &dst.FormFieldQrCode); err != nil { - return err - } - case ENUMFORMFIELDTYPE_SOCIAL_LOGIN_BUTTON: - if err := json.Unmarshal(data, &dst.FormFieldSocialLoginButton); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(FormField)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - // Management: NotificationsSettingsPhoneDeliverySettings model - { - fileSelectPattern: "model_notifications_settings_phone_delivery_settings.go", - pattern: `(func \(dst \*NotificationsSettingsPhoneDeliverySettings\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *NotificationsSettingsPhoneDeliverySettings) UnmarshalJSON(data []byte) error { - - var common NotificationsSettingsPhoneDeliverySettingsCommon - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.NotificationsSettingsPhoneDeliverySettingsCustom = nil - dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse = nil - - switch common.GetProvider() { - case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_TWILIO: - if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { - return err - } - case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_SYNIVERSE: - if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse); err != nil { - return err - } - case ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_PROVIDER: - if err := json.Unmarshal(data, &dst.NotificationsSettingsPhoneDeliverySettingsCustom); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(NotificationsSettingsPhoneDeliverySettings)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, - - ///////////////////////// - // MFA: Push Notification Request - ///////////////////////// - - // MFAPushCredentialRequest model - { - fileSelectPattern: "model_mfa_push_credential_request.go", - pattern: `(func \(dst \*MFAPushCredentialRequest\) UnmarshalJSON\(data \[\]byte\) error \{\n)((.*)\n)*\}\n\n\/\/ Marshal data from the first non-nil pointers in the struct to JSON`, - repl: `func (dst *MFAPushCredentialRequest) UnmarshalJSON(data []byte) error { - - var common MFAPushCredential - - if err := json.Unmarshal(data, &common); err != nil { - return err - } - - dst.MFAPushCredentialAPNS = nil - dst.MFAPushCredentialFCM = nil - dst.MFAPushCredentialFCMHTTPV1 = nil - dst.MFAPushCredentialHMS = nil - - switch common.GetType() { - case ENUMMFAPUSHCREDENTIALATTRTYPE_APNS: - if err := json.Unmarshal(data, &dst.MFAPushCredentialAPNS); err != nil { - return err - } - case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM: - if err := json.Unmarshal(data, &dst.MFAPushCredentialFCM); err != nil { - return err - } - case ENUMMFAPUSHCREDENTIALATTRTYPE_HMS: - if err := json.Unmarshal(data, &dst.MFAPushCredentialHMS); err != nil { - return err - } - case ENUMMFAPUSHCREDENTIALATTRTYPE_FCM_HTTP_V1: - if err := json.Unmarshal(data, &dst.MFAPushCredentialFCMHTTPV1); err != nil { - return err - } - default: - return fmt.Errorf("Data failed to match schemas in oneOf(MFAPushCredentialRequest)") - } - return nil -} - -// Marshal data from the first non-nil pointers in the struct to JSON`, - }, } ) diff --git a/verify/GNUmakefile b/verify/GNUmakefile index 585c3a95..8145ac29 100644 --- a/verify/GNUmakefile +++ b/verify/GNUmakefile @@ -1,4 +1,7 @@ TEST?=$$(go list ./...) +OWNER=patrickcping +REPO=pingone-go-sdk-v2 +MODULE=verify default: build @@ -32,4 +35,10 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint \ No newline at end of file +generate: + @echo "==> Running generate for $(MODULE)..." + @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) + +devcheck: build vet lint gosec test testacc + +.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file diff --git a/verify/generate-postprocessing/generate-replace-regex.go b/verify/generate-postprocessing/generate-replace-regex.go new file mode 100644 index 00000000..da47b2aa --- /dev/null +++ b/verify/generate-postprocessing/generate-replace-regex.go @@ -0,0 +1,52 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" +) + +func main() { + // Get the target directory from the command line argument + if len(os.Args) < 2 { + println("Usage: go run script.go ") + return + } + dir := os.Args[1] + + for _, rule := range replaceRules { + // Get a list of all files with the given extension in the directory + files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern)) + if err != nil { + panic(err) + } + + // Iterate over the files and apply the regex replacement rules + for _, file := range files { + // Read the file contents + content, err := os.ReadFile(filepath.Clean(file)) + if err != nil { + panic(err) + } + + // Apply the regex replacement rule + re := regexp.MustCompile(rule.pattern) + content = re.ReplaceAll(content, []byte(rule.repl)) + + // Write the updated file contents + err = os.WriteFile(file, content, os.ModePerm) + if err != nil { + panic(err) + } + } + } +} + +var ( + // Define the full list of regex replacement rules + replaceRules = []struct { + fileSelectPattern string + pattern string + repl string + }{} +) From f5b69aa4c6375fe15e7fe9e21864b8813b91bf45 Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Fri, 30 Jun 2023 19:35:04 +0100 Subject: [PATCH 3/8] add recommended extension --- pingone-go.code-workspace | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pingone-go.code-workspace b/pingone-go.code-workspace index f6314a31..1dab8a5f 100644 --- a/pingone-go.code-workspace +++ b/pingone-go.code-workspace @@ -44,4 +44,9 @@ "verify": true, }, }, + "extensions": { + "recommendations": [ + "golang.go", + ] + } } \ No newline at end of file From 53ad4a80b60e1e0a3c2dfe0d5fb3c1b93815bee0 Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Fri, 30 Jun 2023 19:49:12 +0100 Subject: [PATCH 4/8] organised generate files --- agreementmanagement/.gitignore | 24 ------------------- agreementmanagement/.openapi-generator-ignore | 1 + .../generate/pingone-agreementmanagement.yml | 0 .../postprocessing}/generate-replace-regex.go | 0 authorize/.openapi-generator-ignore | 1 + .../generate/pingone-authorize.yml | 0 .../postprocessing}/generate-replace-regex.go | 0 credentials/.openapi-generator-ignore | 1 + .../generate/pingone-credentials.yml | 0 .../postprocessing}/generate-replace-regex.go | 0 management/.openapi-generator-ignore | 1 + .../generate/pingone-management.yml | 0 .../postprocessing}/generate-replace-regex.go | 0 mfa/.openapi-generator-ignore | 1 + .../generate/pingone-mfa.yml | 0 .../postprocessing}/generate-replace-regex.go | 0 risk/.openapi-generator-ignore | 1 + .../generate/pingone-risk.yml | 0 .../postprocessing}/generate-replace-regex.go | 0 scripts/generate.sh | 6 ++--- verify/.openapi-generator-ignore | 1 + .../generate/pingone-verify.yml | 0 .../postprocessing}/generate-replace-regex.go | 0 23 files changed, 10 insertions(+), 27 deletions(-) delete mode 100644 agreementmanagement/.gitignore rename pingone-agreementmanagement.yml => agreementmanagement/generate/pingone-agreementmanagement.yml (100%) rename agreementmanagement/{generate-postprocessing => generate/postprocessing}/generate-replace-regex.go (100%) rename pingone-authorize.yml => authorize/generate/pingone-authorize.yml (100%) rename authorize/{generate-postprocessing => generate/postprocessing}/generate-replace-regex.go (100%) rename pingone-credentials.yml => credentials/generate/pingone-credentials.yml (100%) rename credentials/{generate-postprocessing => generate/postprocessing}/generate-replace-regex.go (100%) rename pingone-management.yml => management/generate/pingone-management.yml (100%) rename management/{generate-postprocessing => generate/postprocessing}/generate-replace-regex.go (100%) rename pingone-mfa.yml => mfa/generate/pingone-mfa.yml (100%) rename mfa/{generate-postprocessing => generate/postprocessing}/generate-replace-regex.go (100%) rename pingone-risk.yml => risk/generate/pingone-risk.yml (100%) rename risk/{generate-postprocessing => generate/postprocessing}/generate-replace-regex.go (100%) rename pingone-verify.yml => verify/generate/pingone-verify.yml (100%) rename verify/{generate-postprocessing => generate/postprocessing}/generate-replace-regex.go (100%) diff --git a/agreementmanagement/.gitignore b/agreementmanagement/.gitignore deleted file mode 100644 index daf913b1..00000000 --- a/agreementmanagement/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof diff --git a/agreementmanagement/.openapi-generator-ignore b/agreementmanagement/.openapi-generator-ignore index f7df9956..ae925a27 100644 --- a/agreementmanagement/.openapi-generator-ignore +++ b/agreementmanagement/.openapi-generator-ignore @@ -29,5 +29,6 @@ CHANGELOG.md GNUmakefile .version test/* +generate/ client.go \ No newline at end of file diff --git a/pingone-agreementmanagement.yml b/agreementmanagement/generate/pingone-agreementmanagement.yml similarity index 100% rename from pingone-agreementmanagement.yml rename to agreementmanagement/generate/pingone-agreementmanagement.yml diff --git a/agreementmanagement/generate-postprocessing/generate-replace-regex.go b/agreementmanagement/generate/postprocessing/generate-replace-regex.go similarity index 100% rename from agreementmanagement/generate-postprocessing/generate-replace-regex.go rename to agreementmanagement/generate/postprocessing/generate-replace-regex.go diff --git a/authorize/.openapi-generator-ignore b/authorize/.openapi-generator-ignore index f7df9956..e7e234fb 100644 --- a/authorize/.openapi-generator-ignore +++ b/authorize/.openapi-generator-ignore @@ -29,5 +29,6 @@ CHANGELOG.md GNUmakefile .version test/* +generate/* client.go \ No newline at end of file diff --git a/pingone-authorize.yml b/authorize/generate/pingone-authorize.yml similarity index 100% rename from pingone-authorize.yml rename to authorize/generate/pingone-authorize.yml diff --git a/authorize/generate-postprocessing/generate-replace-regex.go b/authorize/generate/postprocessing/generate-replace-regex.go similarity index 100% rename from authorize/generate-postprocessing/generate-replace-regex.go rename to authorize/generate/postprocessing/generate-replace-regex.go diff --git a/credentials/.openapi-generator-ignore b/credentials/.openapi-generator-ignore index f7df9956..e7e234fb 100644 --- a/credentials/.openapi-generator-ignore +++ b/credentials/.openapi-generator-ignore @@ -29,5 +29,6 @@ CHANGELOG.md GNUmakefile .version test/* +generate/* client.go \ No newline at end of file diff --git a/pingone-credentials.yml b/credentials/generate/pingone-credentials.yml similarity index 100% rename from pingone-credentials.yml rename to credentials/generate/pingone-credentials.yml diff --git a/credentials/generate-postprocessing/generate-replace-regex.go b/credentials/generate/postprocessing/generate-replace-regex.go similarity index 100% rename from credentials/generate-postprocessing/generate-replace-regex.go rename to credentials/generate/postprocessing/generate-replace-regex.go diff --git a/management/.openapi-generator-ignore b/management/.openapi-generator-ignore index 8437f536..190e29b0 100644 --- a/management/.openapi-generator-ignore +++ b/management/.openapi-generator-ignore @@ -29,6 +29,7 @@ CHANGELOG.md GNUmakefile .version test/* +generate/* client.go diff --git a/pingone-management.yml b/management/generate/pingone-management.yml similarity index 100% rename from pingone-management.yml rename to management/generate/pingone-management.yml diff --git a/management/generate-postprocessing/generate-replace-regex.go b/management/generate/postprocessing/generate-replace-regex.go similarity index 100% rename from management/generate-postprocessing/generate-replace-regex.go rename to management/generate/postprocessing/generate-replace-regex.go diff --git a/mfa/.openapi-generator-ignore b/mfa/.openapi-generator-ignore index 5ebadf47..09bc62cb 100644 --- a/mfa/.openapi-generator-ignore +++ b/mfa/.openapi-generator-ignore @@ -29,5 +29,6 @@ CHANGELOG.md GNUmakefile .version test/* +generate/* client.go diff --git a/pingone-mfa.yml b/mfa/generate/pingone-mfa.yml similarity index 100% rename from pingone-mfa.yml rename to mfa/generate/pingone-mfa.yml diff --git a/mfa/generate-postprocessing/generate-replace-regex.go b/mfa/generate/postprocessing/generate-replace-regex.go similarity index 100% rename from mfa/generate-postprocessing/generate-replace-regex.go rename to mfa/generate/postprocessing/generate-replace-regex.go diff --git a/risk/.openapi-generator-ignore b/risk/.openapi-generator-ignore index f7df9956..e7e234fb 100644 --- a/risk/.openapi-generator-ignore +++ b/risk/.openapi-generator-ignore @@ -29,5 +29,6 @@ CHANGELOG.md GNUmakefile .version test/* +generate/* client.go \ No newline at end of file diff --git a/pingone-risk.yml b/risk/generate/pingone-risk.yml similarity index 100% rename from pingone-risk.yml rename to risk/generate/pingone-risk.yml diff --git a/risk/generate-postprocessing/generate-replace-regex.go b/risk/generate/postprocessing/generate-replace-regex.go similarity index 100% rename from risk/generate-postprocessing/generate-replace-regex.go rename to risk/generate/postprocessing/generate-replace-regex.go diff --git a/scripts/generate.sh b/scripts/generate.sh index 4012e049..2fd25bff 100755 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -9,9 +9,9 @@ else # Generate from OpenAPI version=$(head -n 1 .version) - if [[ -f "../pingone-$3.yml" ]]; then \ + if [[ -f "generate/pingone-$3.yml" ]]; then \ echo "==> Running codegen-$3..." - openapi-generator generate -i ../pingone-$3.yml -g go --additional-properties=packageName=$3,packageVersion=$version,isGoSubmodule=true,enumClassPrefix=true -o . --git-repo-id $2 --git-user-id $1; \ + openapi-generator generate -i generate/pingone-$3.yml -g go --additional-properties=packageName=$3,packageVersion=$version,isGoSubmodule=true,enumClassPrefix=true -o . --git-repo-id $2 --git-user-id $1; \ go get -u ./... go mod tidy go mod vendor @@ -25,7 +25,7 @@ else go run ../scripts/generate-replace-regex.go . echo "==> Applying module specific postprocessing..." - go run generate-postprocessing/generate-replace-regex.go . + go run generate/postprocessing/generate-replace-regex.go . else \ echo "pingone-$3.yml missing. Skipping"; \ diff --git a/verify/.openapi-generator-ignore b/verify/.openapi-generator-ignore index f7df9956..e7e234fb 100644 --- a/verify/.openapi-generator-ignore +++ b/verify/.openapi-generator-ignore @@ -29,5 +29,6 @@ CHANGELOG.md GNUmakefile .version test/* +generate/* client.go \ No newline at end of file diff --git a/pingone-verify.yml b/verify/generate/pingone-verify.yml similarity index 100% rename from pingone-verify.yml rename to verify/generate/pingone-verify.yml diff --git a/verify/generate-postprocessing/generate-replace-regex.go b/verify/generate/postprocessing/generate-replace-regex.go similarity index 100% rename from verify/generate-postprocessing/generate-replace-regex.go rename to verify/generate/postprocessing/generate-replace-regex.go From cd745657b3e93cf25910d255ebe7efeb0b2cedc6 Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Fri, 30 Jun 2023 19:53:23 +0100 Subject: [PATCH 5/8] update makefile generate task --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index f6b872bc..b7692a9d 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -45,7 +45,7 @@ lint: golangci-lint gosec: @gosec -exclude-generated ./... -generate: +generate-modules: @./scripts/generate-all.sh $(OWNER) $(REPO) devcheck: build vet lint gosec test testacc From 9410056a1e157b5ba054de9aeb85b32d8e9995e5 Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Fri, 30 Jun 2023 20:05:55 +0100 Subject: [PATCH 6/8] makefile updates --- agreementmanagement/GNUmakefile | 9 +++++++-- authorize/GNUmakefile | 9 +++++++-- credentials/GNUmakefile | 9 +++++++-- management/GNUmakefile | 9 +++++++-- mfa/GNUmakefile | 9 +++++++-- risk/GNUmakefile | 9 +++++++-- verify/GNUmakefile | 9 +++++++-- 7 files changed, 49 insertions(+), 14 deletions(-) diff --git a/agreementmanagement/GNUmakefile b/agreementmanagement/GNUmakefile index 1b8feeb2..47489211 100644 --- a/agreementmanagement/GNUmakefile +++ b/agreementmanagement/GNUmakefile @@ -6,7 +6,9 @@ MODULE=agreementmanagement default: build build: fmtcheck - go build + @go mod tidy + @go mod vendor + @go build ./... test: fmtcheck go test $(TEST) $(TESTARGS) -timeout=5m @@ -35,10 +37,13 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... +gosec: + @gosec -exclude-generated ./... + generate: @echo "==> Running generate for $(MODULE)..." @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) devcheck: build vet lint gosec test testacc -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file +.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate \ No newline at end of file diff --git a/authorize/GNUmakefile b/authorize/GNUmakefile index 5dd0069c..f6e7f2e3 100644 --- a/authorize/GNUmakefile +++ b/authorize/GNUmakefile @@ -6,7 +6,9 @@ MODULE=authorize default: build build: fmtcheck - go build + @go mod tidy + @go mod vendor + @go build ./... test: fmtcheck go test $(TEST) $(TESTARGS) -timeout=5m @@ -35,10 +37,13 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... +gosec: + @gosec -exclude-generated ./... + generate: @echo "==> Running generate for $(MODULE)..." @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) devcheck: build vet lint gosec test testacc -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file +.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate \ No newline at end of file diff --git a/credentials/GNUmakefile b/credentials/GNUmakefile index 08d1c6a3..40ec29a9 100644 --- a/credentials/GNUmakefile +++ b/credentials/GNUmakefile @@ -6,7 +6,9 @@ MODULE=credentials default: build build: fmtcheck - go build + @go mod tidy + @go mod vendor + @go build ./... test: fmtcheck go test $(TEST) $(TESTARGS) -timeout=5m @@ -35,10 +37,13 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... +gosec: + @gosec -exclude-generated ./... + generate: @echo "==> Running generate for $(MODULE)..." @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) devcheck: build vet lint gosec test testacc -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file +.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate \ No newline at end of file diff --git a/management/GNUmakefile b/management/GNUmakefile index 199c314a..93c93288 100644 --- a/management/GNUmakefile +++ b/management/GNUmakefile @@ -6,7 +6,9 @@ MODULE=management default: build build: fmtcheck - go build + @go mod tidy + @go mod vendor + @go build ./... test: fmtcheck go test $(TEST) $(TESTARGS) -timeout=5m @@ -35,10 +37,13 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... +gosec: + @gosec -exclude-generated ./... + generate: @echo "==> Running generate for $(MODULE)..." @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) devcheck: build vet lint gosec test testacc -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file +.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate \ No newline at end of file diff --git a/mfa/GNUmakefile b/mfa/GNUmakefile index 7bd0be49..74b2eb2c 100644 --- a/mfa/GNUmakefile +++ b/mfa/GNUmakefile @@ -6,7 +6,9 @@ MODULE=mfa default: build build: fmtcheck - go build + @go mod tidy + @go mod vendor + @go build ./... test: fmtcheck go test $(TEST) $(TESTARGS) -timeout=5m @@ -35,10 +37,13 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... +gosec: + @gosec -exclude-generated ./... + generate: @echo "==> Running generate for $(MODULE)..." @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) devcheck: build vet lint gosec test testacc -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file +.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate \ No newline at end of file diff --git a/risk/GNUmakefile b/risk/GNUmakefile index 287af2d4..552126d8 100644 --- a/risk/GNUmakefile +++ b/risk/GNUmakefile @@ -6,7 +6,9 @@ MODULE=risk default: build build: fmtcheck - go build + @go mod tidy + @go mod vendor + @go build ./... test: fmtcheck go test $(TEST) $(TESTARGS) -timeout=5m @@ -35,10 +37,13 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... +gosec: + @gosec -exclude-generated ./... + generate: @echo "==> Running generate for $(MODULE)..." @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) devcheck: build vet lint gosec test testacc -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file +.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate \ No newline at end of file diff --git a/verify/GNUmakefile b/verify/GNUmakefile index 8145ac29..5980a9fc 100644 --- a/verify/GNUmakefile +++ b/verify/GNUmakefile @@ -6,7 +6,9 @@ MODULE=verify default: build build: fmtcheck - go build + @go mod tidy + @go mod vendor + @go build ./... test: fmtcheck go test $(TEST) $(TESTARGS) -timeout=5m @@ -35,10 +37,13 @@ golangci-lint: @echo "==> Checking source code with golangci-lint..." @golangci-lint run ./... +gosec: + @gosec -exclude-generated ./... + generate: @echo "==> Running generate for $(MODULE)..." @./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE) devcheck: build vet lint gosec test testacc -.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint generate \ No newline at end of file +.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate \ No newline at end of file From 3990e50900493a6dfa8bbaa25445f230c3069ade Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Sun, 2 Jul 2023 11:57:13 +0100 Subject: [PATCH 7/8] readme --- README.md | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 451e7057..ed13b753 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,90 @@ -# pingone-go-sdk-v2 +# PingOne GO SDK +The PingOne GO SDK provides a set of functions and stucts that help with interacting with the PingOne public cloud API. + +The code is intended to be delivered as a sample, until an official GO SDK is released from Ping Identity. As such, the code is highly likely to change significantly between releases. + +Code for each service is generated with the help of the [OpenAPI Generator](https://openapi-generator.tech/). + +## Packages + +The SDK provides a core package, and a package per PingOne service, each with their own directory off the root of the project: + +* **agreementmanagement** for the PingOne end-user agreements managements service +* **authorize** for the PingOne Authorize service +* **credentials** for the PingOne Credentials service, part of PingOne Neo +* **management** for the PingOne platform common and SSO services +* **mfa** for the PingOne MFA service +* **risk** for the PingOne Protect service +* **verify** for the PingOne Verify service, part of PingOne Neo + +## Getting Started + +The client can be invoked using the following syntax: + +```go + +... + +import ( + "context" + + "github.com/patrickcping/pingone-go-sdk-v2/pingone" +) + +... + +config := &pingone.Config{ + ClientID: clientId, + ClientSecret: clientSecret, + EnvironmentID: environmentId, + AccessToken: accessToken, + Region: region, +} + +client, err := config.APIClient(ctx) +if err != nil { + return nil, err +} +``` + +The result is an object with clients initialised for each service: +* `client.AgreementManagementAPIClient` +* `client.AuthorizeAPIClient` +* `client.CredentialsAPIClient` +* `client.ManagementAPIClient` +* `client.MFAAPIClient` +* `client.RiskAPIClient` +* `client.VerifyAPIClient` + +In the above, if an `AccessToken` is provided, this will be verified and used. If the `AccessToken` is not provided, the SDK will retrieve an access token from the provided `ClientID`, `ClientSecret`, `EnvironmentID` and `Region` parameters. + +The client SDK defaults to production hostnames, and the `Region` is used to add the relevant suffix to the hostname. For example, `Europe` as a `Region` value with suffix the service hostname with `.eu`. Hostnames can be overridden with the optional `APIHostnameOverride`, `AgreementMgmtHostnameOverride`, and `AuthHostnameOverride` parameters. + +An API call can be made against the API objects, as in the following example to get all environments in a tenant: + +```go +... + +resp, r, err := client.ManagementAPIClient.EnvironmentsApi.ReadAllEnvironments(ctx).Execute() +if err != nil { + return nil, err +} +... +``` + +## Contributing + +Each package is generated from an underlying OpenAPI 3 specification. Currently the OpenAPI 3 specification is stored in the `./<>/generate/pingone-<>.yml` file, although this will be subject to change in the future. + +* [**agreementmanagement** OpenAPI 3 Specification file](./authorize/generate/pingone-authorize.yml) +* [**authorize** OpenAPI 3 Specification file](./authorize/generate/pingone-authorize.yml) +* [**credentials** OpenAPI 3 Specification file](./credentials/generate/pingone-credentials.yml) +* [**management** OpenAPI 3 Specification file](./management/generate/pingone-management.yml) +* [**mfa** OpenAPI 3 Specification file](./mfa/generate/pingone-mfa.yml) +* [**risk** OpenAPI 3 Specification file](./risk/generate/pingone-risk.yml) +* [**verify** OpenAPI 3 Specification file](./verify/generate/pingone-verify.yml) + +Once this file has been updated, from the module directory itself run `make generate`. This will generate the required `api_*.go` files, `model_*.go` files and associated documentation. + +Before raising a Pull request, the resulting code can be checked using the `make devcheck` command. This will build, lint and verify the code. \ No newline at end of file From fd2026e28b8d26ac61e7740be666629b05db466c Mon Sep 17 00:00:00 2001 From: Patrick Cowland Date: Sun, 2 Jul 2023 11:59:00 +0100 Subject: [PATCH 8/8] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ed13b753..e542c193 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PingOne GO SDK +# PingOne Administration GO SDK The PingOne GO SDK provides a set of functions and stucts that help with interacting with the PingOne public cloud API.