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

refactor:context cancel in create yaml #1618

Merged
merged 1 commit into from
Feb 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions cli/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"context"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -35,9 +36,9 @@ func ExtractInstallationId(isNewConfigPath bool) (string, error) {
return installationId, nil
}

func GenerateTelemetryConfigFile(logger *zap.Logger, id string) error {
func GenerateTelemetryConfigFile(ctx context.Context, logger *zap.Logger, id string) error {
path := utils.FetchHomeDirectory(true)
yaml.CreateYamlFile(path, "installation-id", logger)
yaml.CreateYamlFile(ctx, logger, path, "installation-id")

data := []byte{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/yaml/reportDb/reportDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (fe *TestReport) InsertReport(ctx context.Context, testRunId string, testSe
testReport.Name = fmt.Sprintf("report-%v", lastIndex)
}

_, err := yaml.CreateYamlFile(fe.Path, testReport.Name, fe.Logger)
_, err := yaml.CreateYamlFile(ctx, fe.Logger, fe.Path, testReport.Name)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/platform/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (nd *NetworkTrafficDoc) GetKind() string {
func Write(ctx context.Context, logger *zap.Logger, path, fileName string, docRead platform.KindSpecifier) error {
//
doc, _ := docRead.(*NetworkTrafficDoc)
isFileEmpty, err := CreateYamlFile(path, fileName, logger)
isFileEmpty, err := CreateYamlFile(ctx, logger, path, fileName)
if err != nil {
return err
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func GetNextID() int64 {
}

// createYamlFile is used to create the yaml file along with the path directory (if does not exists)
func CreateYamlFile(path string, fileName string, Logger *zap.Logger) (bool, error) {
func CreateYamlFile(ctx context.Context, Logger *zap.Logger, path string, fileName string) (bool, error) {
// checks id the yaml exists
yamlPath, err := ValidatePath(filepath.Join(path, fileName+".yaml"))
if err != nil {
Expand Down Expand Up @@ -129,8 +129,7 @@ func CreateYamlFile(path string, fileName string, Logger *zap.Logger) (bool, err
keployPath = filepath.Join(strings.TrimSuffix(path, filepath.Base(path)))
}
Logger.Debug("the path to the generated keploy directory", zap.Any("path", keployPath))
//TODO: use CommandContext
cmd := exec.Command("sudo", "chmod", "-R", "777", keployPath)
cmd := exec.CommandContext(ctx, "sudo", "chmod", "-R", "777", keployPath)
err = cmd.Run()
if err != nil {
Logger.Error("failed to set the permission of keploy directory", zap.Error(err))
Expand Down