Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

fix: replace fmt.Sprintf for paths with path.Join #27

Merged
merged 1 commit into from
Mar 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ notifications:
# Resend API Token
token: ""
from: ""
subject: ""
replyTo: ""
cloudProvider:
hetzner:
Expand Down
13 changes: 0 additions & 13 deletions env.template

This file was deleted.

5 changes: 3 additions & 2 deletions internal/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
import (
"context"
"fmt"
"path"

"github.com/google/uuid"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
Expand Down Expand Up @@ -103,11 +104,11 @@ func (s *Service) GetCluster(ctx context.Context, ID uuid.UUID) (*models.Cluster
}

func (s *Service) getProviderName(provider *models.Provider) string {
return fmt.Sprintf("%s/%s", s.dirCfg.TemplatesDir(), provider.Name)
return path.Join(s.dirCfg.TemplatesDir(), provider.Name)
}

func (s *Service) getCustomerDir(customer *models.Customer) string {
return fmt.Sprintf("%s/%s", s.dirCfg.ClientsDir(), customer.ID)
return path.Join(s.dirCfg.ClientsDir(), customer.ID.String())
}

func (s *Service) BuildCluster(ctx context.Context, customer *models.Customer, providerID uuid.UUID) (*models.Cluster, error) {
Expand Down
5 changes: 3 additions & 2 deletions internal/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path"

helmclient "github.com/mittwald/go-helm-client"
"helm.sh/helm/v3/pkg/repo"
Expand Down Expand Up @@ -35,14 +36,14 @@ func (c *Cluster) InstallCharts() error {
}

// rook-ceph operator values
rookCephOperatorValues := fmt.Sprintf("%s/%s", c.chartsDir, rookCephOperatorChartValues)
rookCephOperatorValues := path.Join(c.chartsDir, rookCephOperatorChartValues)
valuesRookOperatorYaml, err := os.ReadFile(rookCephOperatorValues)
if err != nil {
return fmt.Errorf("could not load values.yaml for rook-operator: %w", err)
}

// rook-ceph cluster values
rookCephClusterValues := fmt.Sprintf("%s/%s", c.chartsDir, rookCephClusterChartValues)
rookCephClusterValues := path.Join(c.chartsDir, rookCephClusterChartValues)
valuesRookClusterYaml, err := os.ReadFile(rookCephClusterValues)
if err != nil {
return fmt.Errorf("could not load values.yaml for rook-cluster: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions internal/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log/slog"
"path"

"github.com/google/uuid"
"github.com/koor-tech/genesis/pkg/database"
Expand Down Expand Up @@ -41,8 +42,8 @@ func (s *Service) BuildAndRunSSH(ctx context.Context, clusterID uuid.UUID, dirPa
return nil, err
}

privateKeyFile := fmt.Sprintf("%s/%s", dirPath, fileKeyName)
publicKeyFile := fmt.Sprintf("%s/%s.pub", dirPath, fileKeyName)
privateKeyFile := path.Join(dirPath, fileKeyName)
publicKeyFile := path.Join(dirPath, fmt.Sprintf("%s.pub", fileKeyName))

sshModel.PrivateFilePath = privateKeyFile
sshModel.PublicFilePath = publicKeyFile
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type EmailNotifications struct {
Token string `yaml:"token"`

From string `yaml:"from"`
Subject string `yaml:"subject"`
ReplyTo string `yaml:"replyTo"`
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/kubeone/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log/slog"
"os"
"os/exec"
"path"
"strings"

"github.com/hashicorp/terraform-exec/tfexec"
Expand Down Expand Up @@ -52,7 +53,7 @@ func (b *Builder) WriteTFVars() error {
tfConfigFile = append(tfConfigFile, configLine)
}

tfVars := fmt.Sprintf("%s/%s", b.dst, "terraform.tfvars")
tfVars := path.Join(b.dst, "terraform.tfvars")
err = utils.SaveInFile(tfVars, strings.Join(tfConfigFile, "\n"), 0600)
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions pkg/notification/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
"github.com/resend/resend-go/v2"
)

const emailText = `Your managed Koor Ceph Cluster is ready to use!`
const (
emailSubject = `Your managed Koor Ceph Cluster is ready to use!`
emailText = `Your managed Koor Ceph Cluster is ready to use!`
)

type Email struct {
Notifier
Expand All @@ -25,6 +28,8 @@ type Email struct {
func NewEmail(logger *slog.Logger, cfg config.EmailNotifications) (Notifier, error) {
client := resend.NewClient(cfg.Token)

// TODO either we use a a separate template "collection" for the notification in general or
// a "central" templates object
tpl, err := template.New("email").Parse(emailText)
if err != nil {
return nil, err
Expand All @@ -44,8 +49,8 @@ func (n *Email) Send(customer models.Customer) error {
params := &resend.SendEmailRequest{
To: []string{customer.Email},
From: n.cfg.From,
Subject: n.cfg.Subject,
ReplyTo: n.cfg.ReplyTo,
Subject: emailSubject,
Text: emailText,
}

Expand Down