Skip to content

Commit

Permalink
fix: check for register platform v2 mutation (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-hontarau authored Dec 9, 2024
1 parent cb4c9b1 commit 3270b0f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
35 changes: 34 additions & 1 deletion internal/cmd/provider/create_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"slices"

"github.com/pkg/errors"
"github.com/shurcooL/graphql"
Expand All @@ -19,7 +20,12 @@ func createVersion() cli.ActionFunc {
dir := cliCtx.String(flagGoReleaserDir.Name)

providerType := cliCtx.String(flagProviderType.Name)
useRegisterPlatformV2 := cliCtx.Bool(flagUseRegisterPlatformV2.Name)
var useRegisterPlatformV2 bool
if types, err := mutationTypes(cliCtx.Context); err == nil {
useRegisterPlatformV2 = types.hasTerraformProviderVersionRegisterPlatformV2Mutation()
} else {
fmt.Println("Failed to check for presence of terraformProviderVersionRegisterPlatformV2Mutation ", err.Error())
}

fmt.Println("Retrieving release data from ", dir)
versionData, err := internal.BuildGoReleaserVersionData(dir)
Expand Down Expand Up @@ -163,6 +169,33 @@ func registerPlatform(ctx context.Context, dir string, versionID string, artifac
return nil
}

type mutationTypesQuery struct {
Schema struct {
MutationType struct {
Fields []mutationTypeField
}
} `graphql:"__schema"`
}

type mutationTypeField struct {
Name string
}

func (q mutationTypesQuery) hasTerraformProviderVersionRegisterPlatformV2Mutation() bool {
return slices.ContainsFunc(q.Schema.MutationType.Fields, func(field mutationTypeField) bool {
return field.Name == "terraformProviderVersionRegisterPlatformV2"
})
}

func mutationTypes(ctx context.Context) (mutationTypesQuery, error) {
query := mutationTypesQuery{}
err := authenticated.Client.Query(ctx, &query, nil)
if err != nil {
return mutationTypesQuery{}, err
}
return query, nil
}

func registerPlatformV2(ctx context.Context, dir string, versionID string, artifact *internal.GoReleaserArtifact) error {
var mutation struct {
RegisterTerraformProviderVersionPlatform struct {
Expand Down
5 changes: 0 additions & 5 deletions internal/cmd/provider/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ var flagProviderType = &cli.StringFlag{
Required: true,
}

var flagUseRegisterPlatformV2 = &cli.BoolFlag{
Name: "use-register-platform-v2",
Usage: "Use register platform v2 mutation",
}

var flagProviderVersionProtocols = &cli.StringSliceFlag{
Name: "protocols",
Usage: "Terraform plugin protocols supported by the provider",
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func Command() *cli.Command {
flagProviderVersionProtocols,
flagGoReleaserDir,
flagGPGKeyID,
flagUseRegisterPlatformV2,
},
Action: createVersion(),
Before: authenticated.Ensure,
Expand Down

0 comments on commit 3270b0f

Please sign in to comment.