Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zeroize Support #12

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions pkg/zhmcclient/fakes/lpar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions pkg/zhmcclient/fakes/zhmc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 39 additions & 2 deletions pkg/zhmcclient/lpar.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ type LparAPI interface {
DetachStorageGroupToPartition(storageGroupURI string, request *StorageGroupPayload) (int, *HmcError)
MountIsoImage(lparURI string, isoFile string, insFile string) (int, *HmcError)
UnmountIsoImage(lparURI string) (int, *HmcError)

ListNics(lparURI string) ([]string, int, *HmcError)
FetchAsciiConsoleURI(lparURI string, request *AsciiConsoleURIPayload) (*AsciiConsoleURIResponse, int, *HmcError)

ZeroizeCryptoDomain(lparURI string, adapterDetails *CryptoAdapterDetails) (int, *HmcError)
GetEnergyDetailsforLPAR(lparURI string, props *EnergyRequestPayload) (uint64, int, *HmcError)

AttachCryptoToPartition(lparURI string, request *CryptoConfig) (int, *HmcError)
Expand Down Expand Up @@ -660,6 +659,44 @@ func (m *LparManager) GetEnergyDetailsforLPAR(lparURI string, props *EnergyReque
return 0, status, errorResponseBody
}

/**
* POST /api/partitions/{partition-id}/operations/zeroize-crypto-domain
*
* Return: 204 (No Content) is returned and no response body
* or: 400, 404, 409, 500, 503
*/

func (m *LparManager) ZeroizeCryptoDomain(lparURI string, adapterDetails *CryptoAdapterDetails) (int, *HmcError) {
requestUrl := m.client.CloneEndpointURL()
requestUrl.Path = path.Join(requestUrl.Path, lparURI)
logger.Info("Request URL:" + string(requestUrl.Path) + " Method:" + http.MethodPost + " adapterDetails" + fmt.Sprint(adapterDetails))
status, responseBody, err := m.client.ExecuteRequest(http.MethodPost, requestUrl, adapterDetails, "")
if err != nil {
logger.Error("error on getting lpar's energy",
zap.String("request url", fmt.Sprint(requestUrl)),
zap.String("method", http.MethodGet),
zap.String("status", fmt.Sprint(status)),
zap.Error(fmt.Errorf("%v", err)))
return status, err
}

logger.Info("Response : " + string(responseBody))

if status == http.StatusNoContent {
logger.Info(fmt.Sprintf("Response: zeroize partition crypto domains successfull, request url: %v, method: %v, status: %v", lparURI, http.MethodPost, status))
return status, nil
}
errorResponseBody := GenerateErrorFromResponse(responseBody)
return status, errorResponseBody
}

/**
* POST /api/partitions/{partition-id}/operations/increase-crypto-configuration
*
* Return: 204 (No Content) is returned and no response body
* or: 400, 404, 409, 500, 503
*/

func (m *LparManager) AttachCryptoToPartition(lparURI string, request *CryptoConfig) (int, *HmcError) {
requestUrl := m.client.CloneEndpointURL()
requestUrl.Path = path.Join(requestUrl.Path, lparURI, "/operations/increase-crypto-configuration")
Expand Down
46 changes: 46 additions & 0 deletions pkg/zhmcclient/lpar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,52 @@ var _ = Describe("LPAR", func() {
})
})

Describe("Zeroize Crypto Domain", func() {
var (
payload *CryptoAdapterDetails
bytesResponse []byte
)

BeforeEach(func() {
payload = &CryptoAdapterDetails{
CryptoAdapterUri: "/api/adapters/196a234",
DomainIdx: 0,
}

bytesResponse, _ = json.Marshal(payload)
})

Context("When ZeroizeCryptoDomain and returns correctly", func() {
It("check the results succeed", func() {
fakeClient.CloneEndpointURLReturns(url)
fakeClient.ExecuteRequestReturns(http.StatusNoContent, bytesResponse, nil)
_, err := manager.ZeroizeCryptoDomain(lparid, payload)

Expect(err).To(BeNil())
})
})

Context("When ZeroizeCryptoDomain returns error due to unmarshalErr", func() {
It("check the error happened", func() {
fakeClient.CloneEndpointURLReturns(url)
fakeClient.ExecuteRequestReturns(http.StatusBadRequest, []byte("incorrect json bytes"), hmcErr)
_, err := manager.ZeroizeCryptoDomain(lparid, payload)

Expect(err.Error()).ToNot(BeNil())
})
})

Context("When ZeroizeCryptoDomain returns error due to hmcErr", func() {
It("check the error happened", func() {
fakeClient.CloneEndpointURLReturns(url)
fakeClient.ExecuteRequestReturns(http.StatusBadRequest, bytesResponse, hmcErr)
_, err := manager.ZeroizeCryptoDomain(lparid, payload)

Expect(*err).To(Equal(*hmcErr))
})
})
})

Describe("UpdateLparProperties", func() {
var (
payload *LparProperties
Expand Down
5 changes: 5 additions & 0 deletions pkg/zhmcclient/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@ type CryptoConfig struct {
CryptoDomainConfigurations []DomainInfo `json:"crypto-domain-configurations,omitempty"`
}

type CryptoAdapterDetails struct {
CryptoAdapterUri string `json:"crypto-adapter-uri,omitempty"`
DomainIdx int `json:"domain-index,omitempty"`
}

type EnergyRequestPayload struct {
Timescale string `json:"timescale,omitempty"`
Type string `json:"type,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/zhmcclient/zhmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func (m *ZhmcManager) UnmountIsoImage(lparURI string) (int, *HmcError) {
func (m *ZhmcManager) ListNics(lparURI string) ([]string, int, *HmcError) {
return m.lparManager.ListNics(lparURI)
}
func (m *ZhmcManager) ZeroizeCryptoDomain(lparURI string, adapterDetails *CryptoAdapterDetails) (int, *HmcError) {
return m.lparManager.ZeroizeCryptoDomain(lparURI, adapterDetails)
}

func (m *ZhmcManager) AttachStorageGroupToPartition(lparURI string, request *StorageGroupPayload) (int, *HmcError) {
return m.lparManager.AttachStorageGroupToPartition(lparURI, request)
Expand Down
Loading