Skip to content

Commit

Permalink
flow validation handling (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
samir-gandhi authored Dec 4, 2023
1 parent a62f73a commit 715565a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
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

0 comments on commit 715565a

Please sign in to comment.