Skip to content

Commit 76ad5c6

Browse files
authored
Fix nil pointer access across repo (#60)
1 parent 3157c3e commit 76ad5c6

File tree

4 files changed

+41
-124
lines changed

4 files changed

+41
-124
lines changed

internal/provider/models/destination_metadata.go

Lines changed: 23 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -102,81 +102,41 @@ type DestinationMetadataState struct {
102102
}
103103

104104
func (d *DestinationMetadataState) getPartnerOwned(owned *bool) types.Bool {
105-
var partnerOwned types.Bool
106-
107-
if owned != nil {
108-
partnerOwned = types.BoolValue(*owned)
109-
}
105+
partnerOwned := types.BoolPointerValue(owned)
110106

111107
return partnerOwned
112108
}
113109

114110
func (d *DestinationMetadataState) getSupportedPlatforms(platforms api.SupportedPlatforms) *SupportedPlatform {
115111
var supportedPlatform SupportedPlatform
116112

117-
if platforms.Browser != nil {
118-
supportedPlatform.Browser = types.BoolValue(*platforms.Browser)
119-
}
120-
121-
if platforms.Server != nil {
122-
supportedPlatform.Server = types.BoolValue(*platforms.Server)
123-
}
124-
125-
if platforms.Mobile != nil {
126-
supportedPlatform.Mobile = types.BoolValue(*platforms.Mobile)
127-
}
113+
supportedPlatform.Browser = types.BoolPointerValue(platforms.Browser)
114+
supportedPlatform.Server = types.BoolPointerValue(platforms.Server)
115+
supportedPlatform.Mobile = types.BoolPointerValue(platforms.Mobile)
128116

129117
return &supportedPlatform
130118
}
131119

132120
func (d *DestinationMetadataState) getSupportedFeatures(features api.SupportedFeatures) *SupportedFeature {
133121
var supportedFeature SupportedFeature
134122

135-
if features.CloudModeInstances != nil {
136-
supportedFeature.CloudModeInstances = types.StringValue(*features.CloudModeInstances)
137-
}
138-
139-
if features.DeviceModeInstances != nil {
140-
supportedFeature.DeviceModeInstances = types.StringValue(*features.DeviceModeInstances)
141-
}
142-
143-
if features.Replay != nil {
144-
supportedFeature.Replay = types.BoolValue(*features.Replay)
145-
}
146-
147-
if features.BrowserUnbundling != nil {
148-
supportedFeature.BrowseUnbundling = types.BoolValue(*features.BrowserUnbundling)
149-
}
150-
151-
if features.BrowserUnbundlingPublic != nil {
152-
supportedFeature.BrowseUnbundlingPublic = types.BoolValue(*features.BrowserUnbundlingPublic)
153-
}
123+
supportedFeature.CloudModeInstances = types.StringPointerValue(features.CloudModeInstances)
124+
supportedFeature.DeviceModeInstances = types.StringPointerValue(features.DeviceModeInstances)
125+
supportedFeature.Replay = types.BoolPointerValue(features.Replay)
126+
supportedFeature.BrowseUnbundling = types.BoolPointerValue(features.BrowserUnbundling)
127+
supportedFeature.BrowseUnbundlingPublic = types.BoolPointerValue(features.BrowserUnbundlingPublic)
154128

155129
return &supportedFeature
156130
}
157131

158132
func (d *DestinationMetadataState) getSupportedMethods(methods api.SupportedMethods) *SupportedMethod {
159133
var supportedMethod SupportedMethod
160134

161-
if methods.Pageview != nil {
162-
supportedMethod.PageView = types.BoolValue(*methods.Pageview)
163-
}
164-
165-
if methods.Identify != nil {
166-
supportedMethod.Identify = types.BoolValue(*methods.Identify)
167-
}
168-
169-
if methods.Alias != nil {
170-
supportedMethod.Alias = types.BoolValue(*methods.Alias)
171-
}
172-
173-
if methods.Track != nil {
174-
supportedMethod.Track = types.BoolValue(*methods.Track)
175-
}
176-
177-
if methods.Group != nil {
178-
supportedMethod.Group = types.BoolValue(*methods.Group)
179-
}
135+
supportedMethod.PageView = types.BoolPointerValue(methods.Pageview)
136+
supportedMethod.Identify = types.BoolPointerValue(methods.Identify)
137+
supportedMethod.Alias = types.BoolPointerValue(methods.Alias)
138+
supportedMethod.Track = types.BoolPointerValue(methods.Track)
139+
supportedMethod.Group = types.BoolPointerValue(methods.Group)
180140

181141
return &supportedMethod
182142
}
@@ -200,9 +160,7 @@ func (d *DestinationMetadataState) getComponents(components []api.DestinationMet
200160
Code: types.StringValue(c.Code),
201161
}
202162

203-
if c.Owner != nil {
204-
componentToAdd.Owner = types.StringValue(*c.Owner)
205-
}
163+
componentToAdd.Owner = types.StringPointerValue(c.Owner)
206164

207165
componentsToAdd = append(componentsToAdd, componentToAdd)
208166
}
@@ -235,10 +193,10 @@ func (d *DestinationMetadataState) getContacts(contacts []api.Contact) []Contact
235193

236194
for _, c := range contacts {
237195
contactToAdd := Contact{
238-
Name: types.StringValue(*c.Name),
196+
Name: types.StringPointerValue(c.Name),
239197
Email: types.StringValue(c.Email),
240-
Role: types.StringValue(*c.Role),
241-
IsPrimary: types.BoolValue(*c.IsPrimary),
198+
Role: types.StringPointerValue(c.Role),
199+
IsPrimary: types.BoolPointerValue(c.IsPrimary),
242200
}
243201

244202
contactsToAdd = append(contactsToAdd, contactToAdd)
@@ -315,9 +273,7 @@ func (d *DestinationMetadataState) getFields(fields []api.DestinationMetadataAct
315273
AllowNull: types.BoolValue(f.AllowNull),
316274
}
317275

318-
if f.Placeholder != nil {
319-
fieldToAdd.Placeholder = types.StringValue(*f.Placeholder)
320-
}
276+
fieldToAdd.Placeholder = types.StringPointerValue(f.Placeholder)
321277

322278
if f.DefaultValue != nil {
323279
defaultValue, err := json.Marshal(f.DefaultValue)
@@ -345,11 +301,11 @@ func (d *DestinationMetadataState) getLogosDestinationMetadata(logos api.Logos)
345301
}
346302

347303
if logos.Mark.IsSet() {
348-
logosToAdd.Mark = types.StringValue(*logos.Mark.Get())
304+
logosToAdd.Mark = types.StringPointerValue(logos.Mark.Get())
349305
}
350306

351307
if logos.Alt.IsSet() {
352-
logosToAdd.Alt = types.StringValue(*logos.Alt.Get())
308+
logosToAdd.Alt = types.StringPointerValue(logos.Alt.Get())
353309
}
354310

355311
return &logosToAdd
@@ -365,13 +321,9 @@ func getOptions(options []api.IntegrationOptionBeta) ([]IntegrationOptionState,
365321
Required: types.BoolValue(opt.Required),
366322
}
367323

368-
if opt.Description != nil {
369-
integrationOption.Description = types.StringValue(*opt.Description)
370-
}
324+
integrationOption.Description = types.StringPointerValue(opt.Description)
371325

372-
if opt.Label != nil {
373-
integrationOption.Label = types.StringValue(*opt.Label)
374-
}
326+
integrationOption.Label = types.StringPointerValue(opt.Label)
375327

376328
if opt.DefaultValue != nil {
377329
defaultValue, err := json.Marshal(opt.DefaultValue)

internal/provider/models/source.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ type SourceState struct {
3434

3535
func (s *SourceState) Fill(source api.Source4) error {
3636
s.ID = types.StringValue(source.Id)
37-
if source.Name != nil {
38-
s.Name = types.StringValue(*source.Name)
39-
}
37+
s.Name = types.StringPointerValue(source.Name)
4038
s.Slug = types.StringValue(source.Slug)
4139
s.Enabled = types.BoolValue(source.Enabled)
4240
s.WorkspaceID = types.StringValue(source.WorkspaceId)

internal/provider/models/source_metadata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ func getLogos(logos api.Logos) *LogosState {
6565
}
6666

6767
if logos.Mark.IsSet() {
68-
logosToAdd.Mark = types.StringValue(*logos.Mark.Get())
68+
logosToAdd.Mark = types.StringPointerValue(logos.Mark.Get())
6969
}
7070

7171
if logos.Alt.IsSet() {
72-
logosToAdd.Alt = types.StringValue(*logos.Alt.Get())
72+
logosToAdd.Alt = types.StringPointerValue(logos.Alt.Get())
7373
}
7474

7575
return &logosToAdd

internal/provider/models/tracking_plan.go

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,12 @@ type TrackingPlanPlan struct {
4545

4646
func (t *TrackingPlanState) Fill(trackingPlan api.TrackingPlan, rules *[]api.RuleV1) error {
4747
t.ID = types.StringValue(trackingPlan.Id)
48-
if trackingPlan.Name != nil {
49-
t.Name = types.StringValue(*trackingPlan.Name)
50-
}
51-
if trackingPlan.Slug != nil {
52-
t.Slug = types.StringValue(*trackingPlan.Slug)
53-
}
54-
if trackingPlan.Description != nil {
55-
t.Description = types.StringValue(*trackingPlan.Description)
56-
}
48+
t.Name = types.StringPointerValue(trackingPlan.Name)
49+
t.Slug = types.StringPointerValue(trackingPlan.Slug)
50+
t.Description = types.StringPointerValue(trackingPlan.Description)
5751
t.Type = types.StringValue(trackingPlan.Type)
58-
if trackingPlan.UpdatedAt != nil {
59-
t.UpdatedAt = types.StringValue(*trackingPlan.UpdatedAt)
60-
}
61-
if trackingPlan.CreatedAt != nil {
62-
t.CreatedAt = types.StringValue(*trackingPlan.CreatedAt)
63-
}
52+
t.UpdatedAt = types.StringPointerValue(trackingPlan.UpdatedAt)
53+
t.CreatedAt = types.StringPointerValue(trackingPlan.CreatedAt)
6454

6555
t.Rules = []RulesState{}
6656
if rules != nil {
@@ -69,7 +59,7 @@ func (t *TrackingPlanState) Fill(trackingPlan api.TrackingPlan, rules *[]api.Rul
6959

7060
r.Type = types.StringValue(rule.Type)
7161
if rule.Key != nil {
72-
r.Key = types.StringValue(*rule.Key)
62+
r.Key = types.StringPointerValue(rule.Key)
7363
}
7464

7565
jsonSchema, err := json.Marshal(rule.JsonSchema)
@@ -89,52 +79,29 @@ func (t *TrackingPlanState) Fill(trackingPlan api.TrackingPlan, rules *[]api.Rul
8979

9080
func (t *TrackingPlanDSState) Fill(trackingPlan api.TrackingPlan, rules *[]api.RuleV1) error {
9181
t.ID = types.StringValue(trackingPlan.Id)
92-
if trackingPlan.Name != nil {
93-
t.Name = types.StringValue(*trackingPlan.Name)
94-
}
95-
if trackingPlan.Slug != nil {
96-
t.Slug = types.StringValue(*trackingPlan.Slug)
97-
}
98-
if trackingPlan.Description != nil {
99-
t.Description = types.StringValue(*trackingPlan.Description)
100-
}
82+
t.Name = types.StringPointerValue(trackingPlan.Name)
83+
t.Slug = types.StringPointerValue(trackingPlan.Slug)
84+
t.Description = types.StringPointerValue(trackingPlan.Description)
10185
t.Type = types.StringValue(trackingPlan.Type)
102-
if trackingPlan.UpdatedAt != nil {
103-
t.UpdatedAt = types.StringValue(*trackingPlan.UpdatedAt)
104-
}
105-
if trackingPlan.CreatedAt != nil {
106-
t.CreatedAt = types.StringValue(*trackingPlan.CreatedAt)
107-
}
86+
t.UpdatedAt = types.StringPointerValue(trackingPlan.UpdatedAt)
87+
t.CreatedAt = types.StringPointerValue(trackingPlan.CreatedAt)
10888

10989
t.Rules = []RulesDSState{}
11090
if rules != nil {
11191
for _, rule := range *rules {
11292
r := RulesDSState{}
11393

11494
r.Type = types.StringValue(rule.Type)
115-
if rule.Key != nil {
116-
r.Key = types.StringValue(*rule.Key)
117-
}
118-
95+
r.Key = types.StringPointerValue(rule.Key)
11996
jsonSchema, err := json.Marshal(rule.JsonSchema)
12097
if err != nil {
12198
return fmt.Errorf("could not marshal json: %w", err)
12299
}
123100
r.JSONSchema = jsontypes.NewNormalizedValue(string(jsonSchema))
124-
125101
r.Version = types.Float64Value(float64(rule.Version))
126-
127-
if rule.CreatedAt != nil {
128-
r.CreatedAt = types.StringValue(*rule.CreatedAt)
129-
}
130-
131-
if rule.UpdatedAt != nil {
132-
r.UpdatedAt = types.StringValue(*rule.UpdatedAt)
133-
}
134-
135-
if rule.DeprecatedAt != nil {
136-
r.DeprecatedAt = types.StringValue(*rule.DeprecatedAt)
137-
}
102+
r.CreatedAt = types.StringPointerValue(rule.CreatedAt)
103+
r.UpdatedAt = types.StringPointerValue(rule.UpdatedAt)
104+
r.DeprecatedAt = types.StringPointerValue(rule.DeprecatedAt)
138105

139106
t.Rules = append(t.Rules, r)
140107
}

0 commit comments

Comments
 (0)