Skip to content

Commit

Permalink
fix: built in variables
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Mar 14, 2024
1 parent ce2ed32 commit b496ab1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/fatih/structtag v1.2.0
github.com/gzuidhof/tygo v0.2.14
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/pterm/pterm v0.12.79
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
15 changes: 8 additions & 7 deletions pkg/tagmanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package tagmanager

import (
"context"
"errors"
"log/slog"
"time"

"github.com/pkg/errors"
"google.golang.org/api/option"
"google.golang.org/api/tagmanager/v2"
)
Expand Down Expand Up @@ -212,7 +212,7 @@ func (c *Client) Variable(name string) (*tagmanager.Variable, error) {
return c.variables[name], nil
}

func (c *Client) BuiltInVariable(name string) (*tagmanager.Variable, error) {
func (c *Client) BuiltInVariable(name string) (*tagmanager.BuiltInVariable, error) {
if c.builtInVariables == nil {
c.builtInVariables = map[string]*tagmanager.BuiltInVariable{}

Expand All @@ -227,11 +227,11 @@ func (c *Client) BuiltInVariable(name string) (*tagmanager.Variable, error) {
}
}

if _, ok := c.variables[name]; !ok {
if _, ok := c.builtInVariables[name]; !ok {
return nil, ErrNotFound
}

return c.variables[name], nil
return c.builtInVariables[name], nil
}

func (c *Client) Trigger(name string) (*tagmanager.Trigger, error) {
Expand Down Expand Up @@ -373,7 +373,7 @@ func (c *Client) UpsertVariable(variable *tagmanager.Variable) (*tagmanager.Vari
return c.Variable(variable.Name)
}

func (c *Client) EnableBuiltInVariable(name string) (*tagmanager.Variable, error) {
func (c *Client) EnableBuiltInVariable(name string) (*tagmanager.BuiltInVariable, error) {
l := c.l.With("type", "Built-In Variable", "name", name)

cache, err := c.BuiltInVariable(name)
Expand All @@ -388,10 +388,11 @@ func (c *Client) EnableBuiltInVariable(name string) (*tagmanager.Variable, error
l.Info("creating")
resp, err := c.Service().Accounts.Containers.Workspaces.BuiltInVariables.Create(c.WorkspacePath()).Type(name).Do()
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to create built-in variable")
}
for _, builtInVariable := range resp.BuiltInVariable {
c.builtInVariables[builtInVariable.Name] = builtInVariable
l.Debug(builtInVariable.Type)
c.builtInVariables[builtInVariable.Type] = builtInVariable
}

return c.BuiltInVariable(name)
Expand Down

0 comments on commit b496ab1

Please sign in to comment.