From cd390b1dfc99f407e866fe13619d31ec9ce41c8f Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Fri, 30 Jan 2026 15:35:32 +0000 Subject: [PATCH] fix: fix publisher is creating wrong urls (#25) ## Description relates to #1234 ## Checklist - [ ] Issue was linked above - [ ] Code format was applied: `make fmt` - [ ] Examples were added / adjusted (see `examples/` directory) - [x] Docs are up-to-date: `make generate-docs` (will be checked by CI) - [ ] Unit tests got implemented or updated - [ ] Acceptance tests got implemented or updated (see e.g. [here](https://github.com/stackitcloud/terraform-provider-stackit/blob/f5f99d170996b208672ae684b6da53420e369563/stackit/internal/services/dns/dns_acc_test.go)) - [x] Unit tests are passing: `make test` (will be checked by CI) - [x] No linter issues: `make lint` (will be checked by CI) Reviewed-on: https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pulls/25 Co-authored-by: Marcel S. Henselin Co-committed-by: Marcel S. Henselin --- cmd/cmd/publish/architecture.go | 64 +++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/cmd/cmd/publish/architecture.go b/cmd/cmd/publish/architecture.go index 76a64aa7..a2e6f6af 100644 --- a/cmd/cmd/publish/architecture.go +++ b/cmd/cmd/publish/architecture.go @@ -4,21 +4,22 @@ import ( "encoding/json" "fmt" "log" + "net/url" "os" "path" "strings" ) type Architecture struct { - Protocols []string `json:"protocols"` - OS string `json:"os"` - Arch string `json:"arch"` - FileName string `json:"filename"` - DownloadUrl string `json:"download_url"` - ShaSumsUrl string `json:"shasums_url"` - ShaSumsSignatureUrl string `json:"shasums_signature_url"` - ShaSum string `json:"shasum"` - SigningKeys []SigningKey `json:"signing_keys"` + Protocols []string `json:"protocols"` + OS string `json:"os"` + Arch string `json:"arch"` + FileName string `json:"filename"` + DownloadUrl string `json:"download_url"` + ShaSumsUrl string `json:"shasums_url"` + ShaSumsSignatureUrl string `json:"shasums_signature_url"` + ShaSum string `json:"shasum"` + SigningKeys SigningKey `json:"signing_keys"` } type SigningKey struct { @@ -46,14 +47,23 @@ func (p *Provider) CreateArchitectureFiles() error { pathPrefix := path.Join("release", prefix) // urlPrefix := fmt.Sprintf("https://%s/%s", domain, prefix) - urlPrefix := path.Join("https://", p.Domain, prefix) + urlPrefix, err := url.JoinPath("https://", p.Domain, prefix) + if err != nil { + return fmt.Errorf("error creating base url: %w", err) + } // download url = https://example.com/v1/providers/namespace/provider/0.0.1/download/terraform-provider_0.0.1_darwin_amd64.zip - downloadUrlPrefix := path.Join(urlPrefix, "download") + downloadUrlPrefix, err := url.JoinPath(urlPrefix, "download") + if err != nil { + return fmt.Errorf("error crearting download url: %w", err) + } downloadPathPrefix := path.Join(pathPrefix, "download") // shasums url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS - shasumsUrl := path.Join(urlPrefix, fmt.Sprintf("%s_%s_SHA256SUMS", p.RepoName, p.Version)) + shasumsUrl, err := url.JoinPath(urlPrefix, fmt.Sprintf("%s_%s_SHA256SUMS", p.RepoName, p.Version)) + if err != nil { + return fmt.Errorf("error creating shasums url: %w", err) + } // shasums_signature_url = https://example.com/v1/providers/namespace/provider/0.0.1/terraform-provider_0.0.1_SHA256SUMS.sig shasumsSigUrl := shasumsUrl + ".sig" @@ -67,7 +77,10 @@ func (p *Provider) CreateArchitectureFiles() error { return err } for _, sum := range shaSums { - downloadUrl := path.Join(downloadUrlPrefix, sum.Path) + downloadUrl, err := url.JoinPath(downloadUrlPrefix, sum.Path) + if err != nil { + return fmt.Errorf("error creating url: %w", err) + } // get os and arch from filename removeFileExtension := strings.Split(sum.Path, ".zip") @@ -89,23 +102,20 @@ func (p *Provider) CreateArchitectureFiles() error { ShaSumsUrl: shasumsUrl, ShaSumsSignatureUrl: shasumsSigUrl, ShaSum: sum.Sum, - SigningKeys: []SigningKey{}, + SigningKeys: SigningKey{}, } - a.SigningKeys = append( - a.SigningKeys, - SigningKey{ - GpgPublicKeys: []GpgPublicKey{ - { - KeyId: p.GpgFingerprint, - AsciiArmor: gpgAsciiPub, - TrustSignature: "", - Source: "", - SourceUrl: "", - }, + a.SigningKeys = SigningKey{ + GpgPublicKeys: []GpgPublicKey{ + { + KeyId: p.GpgFingerprint, + AsciiArmor: gpgAsciiPub, + TrustSignature: "", + Source: "", + SourceUrl: "", }, }, - ) + } // var architectureTemplate = []byte(fmt.Sprintf(` //{ // "protocols": [ @@ -136,7 +146,7 @@ func (p *Provider) CreateArchitectureFiles() error { log.Printf(" - Arch file: %s", archFileName) - err := WriteArchitectureFile(archFileName, a) + err = WriteArchitectureFile(archFileName, a) if err != nil { return err }