Skip to content

Commit

Permalink
refactor: checks the return value of the amt response (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavilosetty-intel authored Feb 12, 2024
1 parent 8d7e56a commit 88138ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/wsman/amt/setupandconfiguration/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"encoding/xml"
"errors"
"fmt"
"strconv"

"github.com/google/uuid"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/internal/message"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/amt/methods"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/client"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/common"
)

// DecodeUUID formats the returned AMT base64 encoded UUID into a human readable UUID
Expand Down Expand Up @@ -169,6 +171,7 @@ func (s Service) CommitChanges() (response Response, err error) {
if err != nil {
return
}
err = checkReturnValue(response.Body.SetMEBxPassword_OUTPUT.ReturnValue, "Commit Changes")
return
}

Expand Down Expand Up @@ -239,6 +242,7 @@ func (s Service) SetMEBXPassword(password string) (response Response, err error)
if err != nil {
return
}
err = checkReturnValue(response.Body.SetMEBxPassword_OUTPUT.ReturnValue, "MEBx Password")
return
}

Expand Down Expand Up @@ -282,3 +286,16 @@ func (s Service) Unprovision(provisioningMode ProvisioningModeValue) (response R

return
}

func checkReturnValue(rc int, item string) (err error) {
if rc != common.PT_STATUS_SUCCESS {
if rc == common.PT_STATUS_DUPLICATE {
return errors.New(item + " already exists and must be removed before continuing")
} else if rc == common.PT_STATUS_INVALID_CERT {
return errors.New(item + " is invalid")
} else {
return errors.New(item + " non-zero return code: " + strconv.Itoa(rc))
}
}
return nil
}

0 comments on commit 88138ad

Please sign in to comment.