Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

flow validation handling #232

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,10 @@ func retryableClient(cInput *client.ClientInput) (*client.APIClient, error) {
// These cases come from the davinci-client-go library and may be subject to change
case strings.Contains(err.Error(), "Error getting admin callback, got: status: 502, body:"):
tflog.Info(ctx, "Found retryable error while initializing client. Retrying...")
fmt.Printf("Sign in retryable Error: %s\n", err.Error())
case strings.Contains(err.Error(), "Error getting SSO callback, got err: status: 502, body:"):
tflog.Info(ctx, "Found retryable error while initializing client. Retrying...")
fmt.Printf("Sign in retryable Error: %s\n", err.Error())
case strings.Contains(err.Error(), "Auth Token not found, unsuccessful login, got: Found. Redirecting to https://console.pingone.com/davinci/index.html#/sso/callback/?error=AuthenticationFailed&error_description=unknownError2"):
tflog.Info(ctx, "Found retryable error while initializing client. Retrying...")
fmt.Printf("Sign in retryable Error: %s\n", err.Error())
default:
return nil, err
}
Expand Down
6 changes: 0 additions & 6 deletions internal/service/davinci/data_source_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ package davinci_test
import (
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/pingidentity/terraform-provider-davinci/internal/acctest"
)

// TestAccDatasourceApplication_Slim - Depends on testAccResourceApplication_Slim_Hcl
func TestAccDatasourceApplication_SlimByAppId(t *testing.T) {
// tflog.Info(ctx, "Rate limit hit, retrying...")
timeElapsed := 4 * time.Second
fmt.Println(timeElapsed)
fmt.Println(timeElapsed)

resourceBase := "davinci_application"
resourceName := acctest.ResourceNameGen()
dataSourceFullName := fmt.Sprintf("data.%s.%s", resourceBase, resourceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func resourceApplicationFlowPolicyRead(ctx context.Context, d *schema.ResourceDa
}

flatResp, err := flattenAppPolicy(resp, policyId)
// fmt.Printf("flatResp: %+v\n", flatResp)
if err != nil {
if strings.Contains(err.Error(), "Unable to find policy with id") {
d.SetId("")
Expand Down
1 change: 0 additions & 1 deletion internal/service/davinci/resource_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func TestAccResourceConnection_HeavyRead(t *testing.T) {
// resourceFullName := fmt.Sprintf("%s.%s", resourceBase, resourceName)

// hcl := testAccResourceConnection_HeavyRead_Hcl(resourceName, "heavy")
// fmt.Printf(`HCL: \n %s \n`, hcl)
testAccResourceConnection_HeavyRead_Hcl(resourceName, "heavy")

// resource.ParallelTest(t, resource.TestCase{
Expand Down
33 changes: 26 additions & 7 deletions internal/service/davinci/resource_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,17 +795,28 @@ func mapSubFlows(d *schema.ResourceData, flowJson string) (*string, error) {

func expandSubFlowProps(subflowProps map[string]interface{}) (*dv.SubFlowProperties, error) {

sfp := subflowProps["subFlowId"].(map[string]interface{})
sfpVal := sfp["value"].(map[string]interface{})
sfp, ok := subflowProps["subFlowId"].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Flow Validation Error: subFlowId key not found in subflow properties")
}
sfpVal, ok := sfp["value"].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Flow Validation Error: subFlowId value not found in subflow properties")
}
sfId := dv.SubFlowID{
Value: dv.SubFlowValue{
Value: sfpVal["value"].(string),
Label: sfpVal["label"].(string),
},
}
subflowVersionId := subflowProps["subFlowVersionId"].(map[string]interface{})
subflowVersionId, ok := subflowProps["subFlowVersionId"].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Flow Validation Error: subFlowVersionId not found in subflow properties")
}
var sfvidString string

if subflowVersionId["value"] == nil {
return nil, fmt.Errorf("Flow Validation Error: subFlowVersionId.value not found in subflow properties")
}
switch subflowVersionId["value"].(type) {
case int:
sfvidString = strconv.Itoa(subflowVersionId["value"].(int))
Expand All @@ -814,14 +825,14 @@ func expandSubFlowProps(subflowProps map[string]interface{}) (*dv.SubFlowPropert
case string:
sfvidString = subflowVersionId["value"].(string)
default:
return nil, fmt.Errorf("Error: subflow versionId is not a string or int")
return nil, fmt.Errorf("Flow Validation Error: subflow versionId is not a string or int")
}

sfv := dv.SubFlowVersionID{
Value: sfvidString,
}
if sfId.Value.Value == "" || sfv.Value == "" {
return nil, fmt.Errorf("Error: subflow value or versionId is empty")
return nil, fmt.Errorf("Flow Validation Error: subflow value or versionId is empty")
}
subflow := dv.SubFlowProperties{
SubFlowID: sfId,
Expand Down Expand Up @@ -886,7 +897,15 @@ func validateFlowDeps(d *schema.ResourceData, diags *diag.Diagnostics) {
// validate subflows
if v.Data.ConnectorID == "flowConnector" && (v.Data.CapabilityName == "startSubFlow" || v.Data.CapabilityName == "startUiSubFlow") {
foundSubflow := false
sfProp, _ := expandSubFlowProps(v.Data.Properties)
sfProp, err := expandSubFlowProps(v.Data.Properties)
if err != nil {
*diags = append(*diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Error Validating flow_json",
Detail: err.Error(),
})
return
}
if subflows, ok := d.GetOk("subflow_link"); ok {
sfList := subflows.(*schema.Set).List()
for _, sfMap := range sfList {
Expand Down