Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gailazar300 committed Apr 3, 2024
1 parent 38badc2 commit 3003542
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
- [Delete Violations Report](#delete-violations-report)
- [Get Artifact Summary](#get-artifact-summary)
- [Get Entitlement info](#get-entitlement-info)
- [XSC API](#xsc-apis)
- [XSC APIs](#xsc-apis)
- [Creating XSC Service Manager](#creating-xray-service-manager)
- [Creating XSC Details](#creating-xsc-details)
- [Creating XSC Service Config](#creating-xsc-service-config)
Expand Down
18 changes: 3 additions & 15 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,27 +605,15 @@ func Pointer[K any](val K) *K {

func SetEnvWithResetCallback(key, value string) (func() error, error) {
oldValue, exist := os.LookupEnv(key)
errMsg := "failed %s %s as environment variable. Cause: %s"

if err := os.Setenv(key, value); err != nil {
log.Debug(fmt.Sprintf(errMsg, "setting", key, err.Error()))
return func() error { return nil }, err
return func() error { return nil }, errorutils.CheckError(err)
}

if exist {
return func() error {
err := os.Setenv(key, oldValue)
if err != nil {
log.Debug(fmt.Sprintf(errMsg, "setting", key, err.Error()))
}
return err
return errorutils.CheckError(os.Setenv(key, oldValue))
}, nil
}
return func() error {
err := os.Unsetenv(key)
if err != nil {
log.Debug(fmt.Sprintf(errMsg, "unsetting", key, err.Error()))
}
return err
return errorutils.CheckError(os.Unsetenv(key))
}, nil
}

0 comments on commit 3003542

Please sign in to comment.