Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #113 from symopsio/tarekM/sym-3785-add-text-field
Browse files Browse the repository at this point in the history
Add support for header_text field
  • Loading branch information
tarekM authored Jun 14, 2022
2 parents ae66238 + d826d75 commit 7176532
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ At this point, the registry will be able to provide the new release - check out

## Development

1. Add the asdf plugins: `asdf plugin add golang richgo`
1. Add the asdf plugins: `asdf plugin add golang richgo terraform`
2. Run `asdf install` to install necessary tools from .tool-versions
3. Run `make local` to create the binary locally

Expand Down
6 changes: 6 additions & 0 deletions sym/provider/acceptance_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,15 @@ func (r flowResource) String() string {
p.WriteString(fmt.Sprintf(" allow_revoke = %v\n", r.params.allowRevoke))
p.WriteString(fmt.Sprintf(" schedule_deescalation = %v\n", r.params.scheduleDeescalation))

if r.params.additionalHeaderText != "" {
p.WriteString(fmt.Sprintf(" additional_header_text = \"%s\"\n", r.params.additionalHeaderText))
}

// if allowedSources is not nil, include it in the params
if r.params.allowedSources != "" {
p.WriteString(fmt.Sprintf(" allowed_sources_json = jsonencode(%v)\n", r.params.allowedSources))
}

p.WriteString(" prompt_fields_json = jsonencode([\n")
for _, f := range r.params.promptFields {
p.WriteString(" {\n")
Expand Down Expand Up @@ -416,6 +421,7 @@ type params struct {
strategyId string
allowRevoke bool
allowedSources string
additionalHeaderText string
scheduleDeescalation bool
promptFields []field
}
Expand Down
15 changes: 9 additions & 6 deletions sym/provider/flow_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccSymFlow_basic(t *testing.T) {
resource.TestCheckResourceAttrPair("sym_flow.this", "params.strategy_id", "sym_strategy.sso_main", "id"),
resource.TestCheckResourceAttr("sym_flow.this", "params.allow_revoke", "true"),
resource.TestCheckResourceAttr("sym_flow.this", "params.allowed_sources_json", `["slack","api"]`),
resource.TestCheckResourceAttr("sym_flow.this", "params.additional_header_text", "Additional Header Text"),
resource.TestCheckResourceAttr("sym_flow.this", "params.schedule_deescalation", "false"),
resource.TestCheckResourceAttr("sym_flow.this", "params.prompt_fields_json", `[{"name":"reason","type":"string","required":true,"label":"Reason"},{"name":"urgency","type":"list","required":true,"default":"Low","allowed_values":["Low","Medium","High"]}]`),
),
Expand All @@ -39,6 +40,7 @@ func TestAccSymFlow_basic(t *testing.T) {
resource.TestCheckResourceAttrPair("sym_flow.this", "environment_id", "sym_environment.this", "id"),
resource.TestCheckResourceAttrPair("sym_flow.this", "params.strategy_id", "sym_strategy.sso_main", "id"),
resource.TestCheckResourceAttr("sym_flow.this", "params.allow_revoke", "false"),
resource.TestCheckNoResourceAttr("sym_flow.this", "params.header_text"),
resource.TestCheckResourceAttr("sym_flow.this", "params.schedule_deescalation", "true"),
),
},
Expand Down Expand Up @@ -158,7 +160,7 @@ func TestAccSymFlow_allowedSourcesOnlyAPI(t *testing.T) {
})
}

func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId string, scheduleDeescalation bool, allowedSources string) string {
func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId string, scheduleDeescalation bool, allowedSources string, additionalHeaderText string) string {
return makeTerraformConfig(
providerResource{org: data.OrgSlug},
integrationResource{
Expand Down Expand Up @@ -244,6 +246,7 @@ func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId str
strategyId: strategyId,
allowRevoke: allowRevoke,
allowedSources: allowedSources,
additionalHeaderText: additionalHeaderText,
scheduleDeescalation: scheduleDeescalation,
promptFields: []field{
{
Expand All @@ -267,24 +270,24 @@ func flowConfig(data TestData, implPath string, allowRevoke bool, strategyId str

func createFlowConfig(data TestData) string {
return flowConfig(data, "internal/testdata/before_impl.py", true, "sym_strategy.sso_main.id", false,
`["slack", "api"]`)
`["slack", "api"]`, "Additional Header Text")
}

func updateFlowConfig(data TestData) string {
return flowConfig(data, "internal/testdata/after_impl.py", false, "sym_strategy.sso_main.id", true,
"")
"", "")
}

func createFlowNoStrategyConfig(data TestData) string {
return flowConfig(data, "internal/testdata/before_impl.py", true, "", false,
"")
"", "")
}

func updateFlowNoStrategyConfig(data TestData) string {
return flowConfig(data, "internal/testdata/after_impl.py", false, "", true,
"")
"", "")
}

func createFlowConfigWithOnlyAPISource(data TestData) string {
return flowConfig(data, "internal/testdata/after_impl.py", true, "sym_strategy.sso_main.id", true, `["api"]`)
return flowConfig(data, "internal/testdata/after_impl.py", true, "sym_strategy.sso_main.id", true, `["api"]`, "")
}
19 changes: 14 additions & 5 deletions sym/templates/sym_approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ func fieldResource() *schema.Resource {
func (t *SymApprovalTemplate) ParamResource() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"strategy_id": utils.Optional(schema.TypeString),
"allow_revoke": utils.OptionalWithDefault(schema.TypeBool, true),
"allowed_sources": utils.StringList(false),
"schedule_deescalation": utils.OptionalWithDefault(schema.TypeBool, true),
"prompt_fields": utils.OptionalList(fieldResource()),
"strategy_id": utils.Optional(schema.TypeString),
"allow_revoke": utils.OptionalWithDefault(schema.TypeBool, true),
"allowed_sources": utils.StringList(false),
"schedule_deescalation": utils.OptionalWithDefault(schema.TypeBool, true),
"prompt_fields": utils.OptionalList(fieldResource()),
"additional_header_text": utils.Optional(schema.TypeString),
},
}
}
Expand Down Expand Up @@ -71,6 +72,10 @@ func (t *SymApprovalTemplate) terraformToAPI(params *HCLParamMap) client.APIPara
raw["strategy_id"] = field.Value()
}

if field := params.checkKey("additional_header_text"); field != nil {
raw["additional_header_text"] = field.Value()
}

if field := params.checkKey("allow_revoke"); field != nil {
// If allow_revoke is set, validate that it is a boolean and add it to params
allowRevoke, err := strconv.ParseBool(field.Value())
Expand Down Expand Up @@ -163,6 +168,10 @@ func apiParamsToTFParams(apiParams client.APIParams) (*HCLParamMap, error) {
params["allowed_sources_json"] = allowedSourcesOutput
}

if additionalHeaderTextField, ok := apiParams["additional_header_text"].(string); ok {
params["additional_header_text"] = additionalHeaderTextField
}

if apiParamsStrategyID, ok := apiParams["strategy_id"].(string); ok {
params["strategy_id"] = apiParamsStrategyID
}
Expand Down
14 changes: 8 additions & 6 deletions sym/templates/sym_approval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ func Test_apiParamsToTFParams_allowed_sources(t *testing.T) {
{
"allow-slack-and-api",
client.APIParams{
"prompt_fields": []interface{}{},
"allowed_sources": []interface{}{"slack", "api"},
"prompt_fields": []interface{}{},
"allowed_sources": []interface{}{"slack", "api"},
"additional_header_text": "Default Header Text",
},
&HCLParamMap{
Params: map[string]string{
"allow_revoke": "false",
"schedule_deescalation": "false",
"prompt_fields_json": `[]`,
"allowed_sources_json": `["slack","api"]`,
"allow_revoke": "false",
"schedule_deescalation": "false",
"prompt_fields_json": `[]`,
"allowed_sources_json": `["slack","api"]`,
"additional_header_text": "Default Header Text",
},
},
false,
Expand Down

0 comments on commit 7176532

Please sign in to comment.