From 126f501e6c8b31c1eafa5ead4b887bd1350f3849 Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Tue, 25 Jun 2024 19:32:56 +0300 Subject: [PATCH] refactor: move progress to a separate file Signed-off-by: Boris Glimcher --- sztp-agent/pkg/secureagent/agent.go | 109 ---------------------- sztp-agent/pkg/secureagent/progress.go | 119 +++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 109 deletions(-) create mode 100644 sztp-agent/pkg/secureagent/progress.go diff --git a/sztp-agent/pkg/secureagent/agent.go b/sztp-agent/pkg/secureagent/agent.go index 4a2e2934..774a96a0 100644 --- a/sztp-agent/pkg/secureagent/agent.go +++ b/sztp-agent/pkg/secureagent/agent.go @@ -16,115 +16,6 @@ const ( ARTIFACTS_PATH = "/tmp/" ) -type ProgressType int64 - -const ( - ProgressTypeBootstrapInitiated ProgressType = iota - ProgressTypeParsingInitiated - ProgressTypeParsingWarning - ProgressTypeParsingError - ProgressTypeParsingComplete - ProgressTypeBootImageInitiated - ProgressTypeBootImageWarning - ProgressTypeBootImageError - ProgressTypeBootImageMismatch - ProgressTypeBootImageInstalledRebooting - ProgressTypeBootImageComplete - ProgressTypePreScriptInitiated - ProgressTypePreScriptWarning - ProgressTypePreScriptError - ProgressTypePreScriptComplete - ProgressTypeConfigInitiated - ProgressTypeConfigWarning - ProgressTypeConfigError - ProgressTypeConfigComplete - ProgressTypePostScriptInitiated - ProgressTypePostScriptWarning - ProgressTypePostScriptError - ProgressTypePostScriptComplete - ProgressTypeBootstrapWarning - ProgressTypeBootstrapError - ProgressTypeBootstrapComplete - ProgressTypeInformational -) - -//nolint:funlen -func (s ProgressType) String() string { - switch s { - case ProgressTypeBootstrapInitiated: - return "bootstrap-initiated" - case ProgressTypeParsingInitiated: - return "parsing-initiated" - case ProgressTypeParsingWarning: - return "parsing-warning" - case ProgressTypeParsingError: - return "parsing-error" - case ProgressTypeParsingComplete: - return "parsing-complete" - case ProgressTypeBootImageInitiated: - return "boot-image-initiated" - case ProgressTypeBootImageWarning: - return "boot-image-warning" - case ProgressTypeBootImageError: - return "boot-image-error" - case ProgressTypeBootImageMismatch: - return "boot-image-mismatch" - case ProgressTypeBootImageInstalledRebooting: - return "boot-image-installed-rebooting" - case ProgressTypeBootImageComplete: - return "boot-image-complete" - case ProgressTypePreScriptInitiated: - return "pre-script-initiated" - case ProgressTypePreScriptWarning: - return "pre-script-warning" - case ProgressTypePreScriptError: - return "pre-script-error" - case ProgressTypePreScriptComplete: - return "pre-script-complete" - case ProgressTypeConfigInitiated: - return "config-initiated" - case ProgressTypeConfigWarning: - return "config-warning" - case ProgressTypeConfigError: - return "config-error" - case ProgressTypeConfigComplete: - return "config-complete" - case ProgressTypePostScriptInitiated: - return "post-script-initiated" - case ProgressTypePostScriptWarning: - return "post-script-warning" - case ProgressTypePostScriptError: - return "post-script-error" - case ProgressTypePostScriptComplete: - return "post-script-complete" - case ProgressTypeBootstrapWarning: - return "bootstrap-warning" - case ProgressTypeBootstrapError: - return "bootstrap-error" - case ProgressTypeBootstrapComplete: - return "bootstrap-complete" - case ProgressTypeInformational: - return "informational" - } - return "unknown" -} - -type ProgressJSON struct { - IetfSztpBootstrapServerInput struct { - ProgressType string `json:"progress-type"` - Message string `json:"message"` - SSHHostKeys struct { - SSHHostKey []struct { - Algorithm string `json:"algorithm"` - KeyData string `json:"key-data"` - } `json:"ssh-host-key,omitempty"` - } `json:"ssh-host-keys,omitempty"` - TrustAnchorCerts struct { - TrustAnchorCert []string `json:"trust-anchor-cert,omitempty"` - } `json:"trust-anchor-certs,omitempty"` - } `json:"ietf-sztp-bootstrap-server:input"` -} - type InputJSON struct { IetfSztpBootstrapServerInput struct { HwModel string `json:"hw-model"` diff --git a/sztp-agent/pkg/secureagent/progress.go b/sztp-agent/pkg/secureagent/progress.go new file mode 100644 index 00000000..7b7c869e --- /dev/null +++ b/sztp-agent/pkg/secureagent/progress.go @@ -0,0 +1,119 @@ +/* +SPDX-License-Identifier: Apache-2.0 +Copyright (C) 2022-2023 Intel Corporation +Copyright (c) 2022 Dell Inc, or its subsidiaries. +Copyright (C) 2022 Red Hat. +*/ + +// nolint +// Package secureagent implements the secure agent +package secureagent + +type ProgressType int64 + +const ( + ProgressTypeBootstrapInitiated ProgressType = iota + ProgressTypeParsingInitiated + ProgressTypeParsingWarning + ProgressTypeParsingError + ProgressTypeParsingComplete + ProgressTypeBootImageInitiated + ProgressTypeBootImageWarning + ProgressTypeBootImageError + ProgressTypeBootImageMismatch + ProgressTypeBootImageInstalledRebooting + ProgressTypeBootImageComplete + ProgressTypePreScriptInitiated + ProgressTypePreScriptWarning + ProgressTypePreScriptError + ProgressTypePreScriptComplete + ProgressTypeConfigInitiated + ProgressTypeConfigWarning + ProgressTypeConfigError + ProgressTypeConfigComplete + ProgressTypePostScriptInitiated + ProgressTypePostScriptWarning + ProgressTypePostScriptError + ProgressTypePostScriptComplete + ProgressTypeBootstrapWarning + ProgressTypeBootstrapError + ProgressTypeBootstrapComplete + ProgressTypeInformational +) + +//nolint:funlen +func (s ProgressType) String() string { + switch s { + case ProgressTypeBootstrapInitiated: + return "bootstrap-initiated" + case ProgressTypeParsingInitiated: + return "parsing-initiated" + case ProgressTypeParsingWarning: + return "parsing-warning" + case ProgressTypeParsingError: + return "parsing-error" + case ProgressTypeParsingComplete: + return "parsing-complete" + case ProgressTypeBootImageInitiated: + return "boot-image-initiated" + case ProgressTypeBootImageWarning: + return "boot-image-warning" + case ProgressTypeBootImageError: + return "boot-image-error" + case ProgressTypeBootImageMismatch: + return "boot-image-mismatch" + case ProgressTypeBootImageInstalledRebooting: + return "boot-image-installed-rebooting" + case ProgressTypeBootImageComplete: + return "boot-image-complete" + case ProgressTypePreScriptInitiated: + return "pre-script-initiated" + case ProgressTypePreScriptWarning: + return "pre-script-warning" + case ProgressTypePreScriptError: + return "pre-script-error" + case ProgressTypePreScriptComplete: + return "pre-script-complete" + case ProgressTypeConfigInitiated: + return "config-initiated" + case ProgressTypeConfigWarning: + return "config-warning" + case ProgressTypeConfigError: + return "config-error" + case ProgressTypeConfigComplete: + return "config-complete" + case ProgressTypePostScriptInitiated: + return "post-script-initiated" + case ProgressTypePostScriptWarning: + return "post-script-warning" + case ProgressTypePostScriptError: + return "post-script-error" + case ProgressTypePostScriptComplete: + return "post-script-complete" + case ProgressTypeBootstrapWarning: + return "bootstrap-warning" + case ProgressTypeBootstrapError: + return "bootstrap-error" + case ProgressTypeBootstrapComplete: + return "bootstrap-complete" + case ProgressTypeInformational: + return "informational" + } + return "unknown" +} + +type ProgressJSON struct { + IetfSztpBootstrapServerInput struct { + ProgressType string `json:"progress-type"` + Message string `json:"message"` + SSHHostKeys struct { + SSHHostKey []struct { + Algorithm string `json:"algorithm"` + KeyData string `json:"key-data"` + } `json:"ssh-host-key,omitempty"` + } `json:"ssh-host-keys,omitempty"` + TrustAnchorCerts struct { + TrustAnchorCert []string `json:"trust-anchor-cert,omitempty"` + } `json:"trust-anchor-certs,omitempty"` + } `json:"ietf-sztp-bootstrap-server:input"` +}