Skip to content

Commit 3078c2f

Browse files
Check for nulls on nullable fields when downloading rules
1 parent 5a46fc6 commit 3078c2f

File tree

1 file changed

+63
-6
lines changed

1 file changed

+63
-6
lines changed

cmd/rule/download.go

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Rule struct {
2727
XMLName xml.Name `xml:"Rule"`
2828
Name string `xml:"name,attr"`
2929
Type string `xml:"type,attr"`
30-
Description string `xml:"Description"`
30+
Description string `xml:"Description,omitempty"`
3131
Signature *Signature
3232
Source string `xml:"Source"`
3333
}
@@ -53,7 +53,7 @@ type Argument struct {
5353
XMLName xml.Name `xml:"Argument"`
5454
Name string `xml:"name,attr"`
5555
Type string `xml:"type,attr,omitempty"`
56-
Description string `xml:"Description"`
56+
Description string `xml:"Description,omitempty"`
5757
}
5858

5959
var cloudRuleTypes = []string{"AttributeGenerator", "AttributeGeneratorFromTemplate", "BeforeProvisioning", "BuildMap", "Correlation", "IdentityAttribute", "ManagerCorrelation"}
@@ -145,7 +145,17 @@ func saveCloudXMLRules(apiClient *sailpoint.APIClient, description string, inclu
145145
}
146146

147147
//Make Rule XML Object
148-
rule := &Rule{Name: v.Object["name"].(string), Type: RuleType, Description: v.Object["description"].(string), Source: "<![CDATA[\n" + v.Object["sourceCode"].(map[string]interface{})["script"].(string) + "\n]]>"}
148+
rule := &Rule{}
149+
rule.Name = v.Object["name"].(string)
150+
rule.Type = RuleType
151+
152+
if v.Object["description"] != nil {
153+
rule.Description = v.Object["description"].(string)
154+
} else {
155+
rule.Description = ""
156+
}
157+
158+
rule.Source = "<![CDATA[\n" + v.Object["sourceCode"].(map[string]interface{})["script"].(string) + "\n]]>"
149159

150160
var ruleSignature = &Signature{}
151161

@@ -154,7 +164,22 @@ func saveCloudXMLRules(apiClient *sailpoint.APIClient, description string, inclu
154164

155165
ruleSignature.Inputs = &Inputs{Argument: []Argument{}}
156166
for _, v := range v.Object["signature"].(map[string]interface{})["input"].([]interface{}) {
157-
argument := Argument{Name: v.(map[string]interface{})["name"].(string), Type: v.(map[string]interface{})["type"].(string), Description: v.(map[string]interface{})["description"].(string)}
167+
argument := Argument{}
168+
169+
argument.Name = v.(map[string]interface{})["name"].(string)
170+
171+
if v.(map[string]interface{})["type"] != nil {
172+
argument.Type = v.(map[string]interface{})["type"].(string)
173+
} else {
174+
argument.Type = ""
175+
}
176+
177+
if v.(map[string]interface{})["description"] != nil {
178+
argument.Description = v.(map[string]interface{})["description"].(string)
179+
} else {
180+
argument.Description = ""
181+
}
182+
158183
ruleSignature.Inputs.Argument = append(ruleSignature.Inputs.Argument, argument)
159184
}
160185

@@ -166,13 +191,45 @@ func saveCloudXMLRules(apiClient *sailpoint.APIClient, description string, inclu
166191

167192
if _, ok := v.Object["signature"].(map[string]interface{})["output"].([]interface{}); ok {
168193
for _, v := range v.Object["signature"].(map[string]interface{})["output"].([]interface{}) {
169-
argument := Argument{Name: v.(map[string]interface{})["name"].(string), Type: v.(map[string]interface{})["type"].(string), Description: v.(map[string]interface{})["description"].(string)}
194+
195+
argument := Argument{}
196+
197+
argument.Name = v.(map[string]interface{})["name"].(string)
198+
199+
if v.(map[string]interface{})["type"] != nil {
200+
argument.Type = v.(map[string]interface{})["type"].(string)
201+
} else {
202+
argument.Type = ""
203+
}
204+
205+
if v.(map[string]interface{})["description"] != nil {
206+
argument.Description = v.(map[string]interface{})["description"].(string)
207+
} else {
208+
argument.Description = ""
209+
}
210+
170211
ruleSignature.Returns.Argument = append(ruleSignature.Returns.Argument, argument)
171212
}
172213

173214
} else {
174215
output := v.Object["signature"].(map[string]interface{})["output"].(map[string]interface{})
175-
argument := Argument{Name: output["name"].(string), Type: output["type"].(string), Description: output["description"].(string)}
216+
217+
argument := Argument{}
218+
219+
argument.Name = output["name"].(string)
220+
221+
if output["type"] != nil {
222+
argument.Type = output["type"].(string)
223+
} else {
224+
argument.Type = ""
225+
}
226+
227+
if output["description"] != nil {
228+
argument.Description = output["description"].(string)
229+
} else {
230+
argument.Description = ""
231+
}
232+
176233
ruleSignature.Returns.Argument = append(ruleSignature.Returns.Argument, argument)
177234
}
178235
}

0 commit comments

Comments
 (0)