Skip to content

Commit

Permalink
fix: [CDS-77684]: Handle null point exception if created by field is …
Browse files Browse the repository at this point in the history
…nil (#665)

* [fix]: [CDS-77684]: Handle null point exception if created by field is not set

* fix: [CDS-77684]: Add nil check to file_store

* fix: [CDS-77684]: Update func name

* fix: [CDS-77684]: Update change.log

* Update 665.txt

---------

Co-authored-by: Yogesh Chauhan <yogesh.chauhan@harness.io>
  • Loading branch information
sarthakkasat and yogesh-chauhan committed Aug 25, 2023
1 parent c63338d commit 3e41bdb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/665.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Fixed harness_platform_file_store_folder create resource plugin crash, when service account token was used to create
```
13 changes: 12 additions & 1 deletion internal/service/platform/file_store/file_store_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,16 @@ func getOptionalString(str interface{}) optional.String {
return optional.NewString(v)
}

func getEmail(user *nextgen.EmbeddedUserDetailsDto) string {
if user != nil {
return user.Email
}
return ""
}


func getName(user *nextgen.EmbeddedUserDetailsDto) string {
if user != nil {
return user.Name
}
return ""
}
8 changes: 4 additions & 4 deletions internal/service/platform/file_store/resource_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ func readFileNode(d *schema.ResourceData, file *nextgen.File, fileContentOpt opt
d.Set(tags, FlattenTags(file.Tags))
d.Set(createdBy, []interface{}{
map[string]interface{}{
"email": file.CreatedBy.Email,
"name": file.CreatedBy.Name,
"email": getEmail(file.CreatedBy),
"name": getName(file.CreatedBy),
},
})
d.Set(lastModifiedBy, []interface{}{
map[string]interface{}{
"email": file.LastModifiedBy.Email,
"name": file.LastModifiedBy.Name,
"email": getEmail(file.LastModifiedBy),
"name": getName(file.LastModifiedBy),
},
})
d.Set(lastModifiedAt, file.LastModifiedAt)
Expand Down
8 changes: 4 additions & 4 deletions internal/service/platform/file_store/resource_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ func readFolderNode(d *schema.ResourceData, file *nextgen.File, fileContentOpt o
d.Set(path, file.Path)
d.Set(createdBy, []interface{}{
map[string]interface{}{
"email": file.CreatedBy.Email,
"name": file.CreatedBy.Name,
"email": getEmail(file.CreatedBy),
"name": getName(file.CreatedBy),
},
})
d.Set(lastModifiedBy, []interface{}{
map[string]interface{}{
"email": file.LastModifiedBy.Email,
"name": file.LastModifiedBy.Name,
"email": getEmail(file.LastModifiedBy),
"name": getName(file.LastModifiedBy),
},
})
d.Set(lastModifiedAt, file.LastModifiedAt)
Expand Down

0 comments on commit 3e41bdb

Please sign in to comment.