@@ -21,6 +21,7 @@ package tofuretriever
2121import (
2222 "context"
2323 "errors"
24+ "fmt"
2425 "net/url"
2526 "runtime"
2627 "strings"
@@ -52,9 +53,9 @@ const (
5253
5354 defaultTofuURLTemplate = "https://github.com/opentofu/opentofu/releases/download/v{{ .Version }}/{{ .Artifact }}"
5455
55- baseIdentity = "https://github.com/opentofu/opentofu/.github/workflows/release.yml@refs/heads/v"
56- issuer = "https://token.actions.githubusercontent.com"
57- unstableIdentity = "https://github.com/opentofu/opentofu/.github/workflows/release.yml@refs/heads/main"
56+ baseIdentity = "https://github.com/opentofu/opentofu/.github/workflows/release.yml@refs/heads/v"
57+ issuer = "https://token.actions.githubusercontent.com"
58+ mainIdentity = "https://github.com/opentofu/opentofu/.github/workflows/release.yml@refs/heads/main"
5859
5960 baseFileName = "tofu_"
6061)
@@ -211,7 +212,7 @@ func (r TofuRetriever) checkSumAndSig(ctx context.Context, version *version.Vers
211212 return err
212213 }
213214
214- identity := buildIdentity (version , stable )
215+ identity := buildIdentity (version )
215216 err = cosigncheck .Check (ctx , dataSums , dataSumsSig , dataSumsCert , identity , issuer , r .conf .Displayer )
216217 if err == nil || ! errors .Is (err , cosigncheck .ErrNotInstalled ) {
217218 return err
@@ -257,15 +258,19 @@ func buildAssetNames(version string, arch string, stable bool) []string {
257258 return []string {nameBuilder .String (), sumsAssetName , sumsAssetName + ".pem" , sumsAssetName + ".sig" }
258259}
259260
260- func buildIdentity (v * version.Version , stable bool ) string {
261- if ! stable {
262- return unstableIdentity
261+ func buildIdentity (v * version.Version ) string {
262+ segments := v .Segments ()
263+ if len (segments ) < 3 {
264+ return baseIdentity + v .String ()
265+ }
266+
267+ // According to https://opentofu.org/docs/intro/install/standalone/,
268+ // alpha and beta versions have a specific identity.
269+ if strings .Contains (v .Prerelease (), "alpha" ) || strings .Contains (v .Prerelease (), "beta" ) {
270+ return mainIdentity
263271 }
264272
265- cleanedVersion := v .String ()
266- indexDot := strings .LastIndexByte (cleanedVersion , '.' )
267- // cleaned, so indexDot can not be -1
268- shortVersion := cleanedVersion [:indexDot ]
273+ shortVersion := fmt .Sprintf ("%d.%d" , segments [0 ], segments [1 ])
269274
270275 return baseIdentity + shortVersion
271276}
0 commit comments