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

fix(progress): remove redundant function argument #343

Merged
merged 1 commit into from
Jun 10, 2024
Merged
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
fix(progress): remove redundant function argument
Signed-off-by: Boris Glimcher <[email protected]>
glimchb committed Jun 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8ebab4d7cfe9dedaa6c91a90fbff79ae9b1fd55a
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -413,7 +413,7 @@ docker-compose up --build web
## Test HTTP server from agent

```text
docker-compose run --rm -T agent curl --fail --key /private_key.pem --cert /my_cert.pem --cacert /opi.pem https://web:443/var/lib/
docker-compose run --rm -T agent curl --fail --key /private_key.pem --cert /my_cert.pem --cacert /opi.pem https://web:443/
```

OR
20 changes: 10 additions & 10 deletions sztp-agent/pkg/secureagent/daemon.go
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@
if err != nil {
return err
}
_ = a.doReportProgress(ProgressTypeBootstrapComplete, true)
_ = a.doReportProgress(ProgressTypeBootstrapComplete)
return nil
}

@@ -92,7 +92,7 @@
return nil
}

func (a *Agent) doReportProgress(s ProgressType, needssh bool) error {
func (a *Agent) doReportProgress(s ProgressType) error {
log.Println("[INFO] Starting the Report Progress request.")
url := strings.ReplaceAll(a.GetBootstrapURL(), "get-bootstrapping-data", "report-progress")
p := ProgressJSON{
@@ -110,7 +110,7 @@
Message: "message sent via JSON",
},
}
if needssh {
if s == ProgressTypeBootstrapComplete {
// TODO: generate real key here
encodedKey := base64.StdEncoding.EncodeToString([]byte("mysshpass"))
p.IetfSztpBootstrapServerInput.SSHHostKeys = struct {
@@ -175,7 +175,7 @@
return err
}
log.Println("[INFO] Response retrieved successfully")
_ = a.doReportProgress(ProgressTypeBootstrapInitiated, false)
_ = a.doReportProgress(ProgressTypeBootstrapInitiated)
crypto := res.IetfSztpBootstrapServerOutput.ConveyedInformation
newVal, err := base64.StdEncoding.DecodeString(crypto)
if err != nil {
@@ -215,7 +215,7 @@
//nolint:funlen
func (a *Agent) downloadAndValidateImage() error {
log.Printf("[INFO] Starting the Download Image: %v", a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.BootImage.DownloadURI)
_ = a.doReportProgress(ProgressTypeBootImageInitiated, false)
_ = a.doReportProgress(ProgressTypeBootImageInitiated)
// Download the image from DownloadURI and save it to a file
a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference = fmt.Sprintf("%8d", time.Now().Unix())
for i, item := range a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.BootImage.DownloadURI {
@@ -239,7 +239,7 @@
},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{ //nolint:gosec
InsecureSkipVerify: true, // TODO: remove skip verify

Check failure on line 242 in sztp-agent/pkg/secureagent/daemon.go

GitHub Actions / golangci

G402: TLS InsecureSkipVerify set true. (gosec)
RootCAs: caCertPool,
Certificates: []tls.Certificate{cert},
},
@@ -300,7 +300,7 @@
return errors.New("Checksum mismatch")
}
log.Println("[INFO] Checksum verified successfully")
_ = a.doReportProgress(ProgressTypeBootImageComplete, false)
_ = a.doReportProgress(ProgressTypeBootImageComplete)
return nil
default:
return errors.New("Unsupported hash algorithm")
@@ -311,7 +311,7 @@

func (a *Agent) copyConfigurationFile() error {
log.Println("[INFO] Starting the Copy Configuration.")
_ = a.doReportProgress(ProgressTypeConfigInitiated, false)
_ = a.doReportProgress(ProgressTypeConfigInitiated)
// Copy the configuration file to the device
file, err := os.Create(ARTIFACTS_PATH + a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference + "-config")
if err != nil {
@@ -330,13 +330,13 @@
log.Println("[ERROR] writing the configuration file", err.Error())
return err
}
err = os.Chmod(ARTIFACTS_PATH+a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference+"-config", 0744)

Check failure on line 333 in sztp-agent/pkg/secureagent/daemon.go

GitHub Actions / golangci

G302: Expect file permissions to be 0600 or less (gosec)
if err != nil {
log.Println("[ERROR] changing the configuration file permission", err.Error())
return err
}
log.Println("[INFO] Configuration file copied successfully")
_ = a.doReportProgress(ProgressTypeConfigComplete, false)
_ = a.doReportProgress(ProgressTypeConfigComplete)
return nil
}

@@ -356,8 +356,8 @@
reportEnd = ProgressTypePreScriptComplete
}
log.Println("[INFO] Starting the " + scriptName + "-configuration.")
_ = a.doReportProgress(reportStart, false)
_ = a.doReportProgress(reportStart)
file, err := os.Create(ARTIFACTS_PATH + a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference + scriptName + "configuration.sh")

Check failure on line 360 in sztp-agent/pkg/secureagent/daemon.go

GitHub Actions / golangci

G304: Potential file inclusion via variable (gosec)
if err != nil {
log.Println("[ERROR] creating the "+scriptName+"-configuration script", err.Error())
return err
@@ -374,7 +374,7 @@
log.Println("[ERROR] writing the "+scriptName+"-configuration script", err.Error())
return err
}
err = os.Chmod(ARTIFACTS_PATH+a.BootstrapServerOnboardingInfo.IetfSztpConveyedInfoOnboardingInformation.InfoTimestampReference+scriptName+"configuration.sh", 0755)

Check failure on line 377 in sztp-agent/pkg/secureagent/daemon.go

GitHub Actions / golangci

G302: Expect file permissions to be 0600 or less (gosec)
if err != nil {
log.Println("[ERROR] changing the "+scriptName+"-configuration script permission", err.Error())
return err
@@ -387,7 +387,7 @@
return err
}
log.Println(string(out)) // remove it
_ = a.doReportProgress(reportEnd, false)
_ = a.doReportProgress(reportEnd)
log.Println("[INFO] " + scriptName + "-Configuration script executed successfully")
return nil
}
2 changes: 1 addition & 1 deletion sztp-agent/pkg/secureagent/daemon_test.go
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@
}

func createTempTestFile(file string, ok bool) {
f, err := os.Create(file)

Check failure on line 91 in sztp-agent/pkg/secureagent/daemon_test.go

GitHub Actions / golangci

G304: Potential file inclusion via variable (gosec)
if err != nil {
log.Fatal(err)
}
@@ -412,7 +412,7 @@
DhcpLeaseFile: tt.fields.DhcpLeaseFile,
ProgressJSON: tt.fields.ProgressJSON,
}
if err := a.doReportProgress(ProgressTypeBootstrapInitiated, false); (err != nil) != tt.wantErr {
if err := a.doReportProgress(ProgressTypeBootstrapInitiated); (err != nil) != tt.wantErr {
t.Errorf("doReportProgress() error = %v, wantErr %v", err, tt.wantErr)
}
})

Unchanged files with check annotations Beta

// Auxiliar function to get lines from file matching with the substr
func linesInFileContains(file string, substr string) string {
f, _ := os.Open(file)

Check failure on line 31 in sztp-agent/pkg/secureagent/utils.go

GitHub Actions / golangci

G304: Potential file inclusion via variable (gosec)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
cmd := &cobra.Command{
Use: "enable",
Short: "Run the enable command",
RunE: func(cmd *cobra.Command, args []string) error {

Check failure on line 31 in sztp-agent/cmd/enable.go

GitHub Actions / golangci

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
a := secureagent.NewAgent(bootstrapURL, serialNumber, dhcpLeaseFile, devicePassword, devicePrivateKey, deviceEndEntityCert, bootstrapTrustAnchorCert)
return a.RunCommandEnable()
},
cmd := &cobra.Command{
Use: "run",
Short: "Exec the run command",
RunE: func(cmd *cobra.Command, args []string) error {

Check failure on line 31 in sztp-agent/cmd/run.go

GitHub Actions / golangci

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
a := secureagent.NewAgent(bootstrapURL, serialNumber, dhcpLeaseFile, devicePassword, devicePrivateKey, deviceEndEntityCert, bootstrapTrustAnchorCert)
return a.RunCommand()
},
cmd := &cobra.Command{
Use: "status",
Short: "Run the status command",
RunE: func(cmd *cobra.Command, args []string) error {

Check failure on line 31 in sztp-agent/cmd/status.go

GitHub Actions / golangci

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
a := secureagent.NewAgent(bootstrapURL, serialNumber, dhcpLeaseFile, devicePassword, devicePrivateKey, deviceEndEntityCert, bootstrapTrustAnchorCert)
return a.RunCommandStatus()
},
want: &cobra.Command{
Use: "run",
Short: "Exec the run command",
RunE: func(cmd *cobra.Command, args []string) error {

Check failure on line 24 in sztp-agent/cmd/run_test.go

GitHub Actions / golangci

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
return nil
},
},