mirror of
https://github.com/foomo/sesamy-cli.git
synced 2025-10-16 12:35:36 +00:00
fix: use workspace loader
This commit is contained in:
parent
3880d503f1
commit
f1fe8c2c72
@ -82,6 +82,8 @@ googleTagManager:
|
||||
containerId: '175355532'
|
||||
# (Optional) The workspace id that should be used by the api
|
||||
workspaceId: '23'
|
||||
# (Optional) The workspace name that should be used by the api
|
||||
workspace: 'Default Workspace'
|
||||
# Server container settings
|
||||
serverContainer:
|
||||
# The container tag id
|
||||
@ -90,6 +92,8 @@ googleTagManager:
|
||||
containerId: '175348980'
|
||||
# (Optional) The workspace id that should be used by the api
|
||||
workspaceId: '10'
|
||||
# (Optional) The workspace name that should be used by the api
|
||||
workspace: 'Default Workspace'
|
||||
# Web container variables
|
||||
webContainerVariables:
|
||||
dataLayer:
|
||||
|
||||
@ -37,6 +37,8 @@ func list(ctx context.Context, l *slog.Logger, tm *tagmanager.TagManager, resour
|
||||
switch resource {
|
||||
case "environments":
|
||||
return dump(tm.Service().Accounts.Containers.Environments.List(tm.ContainerPath()).Context(ctx).Do())
|
||||
case "workspaces":
|
||||
return dump(tm.Service().Accounts.Containers.Workspaces.List(tm.ContainerPath()).Context(ctx).Do())
|
||||
case "status":
|
||||
return dump(tm.Service().Accounts.Containers.Workspaces.GetStatus(tm.WorkspacePath()).Context(ctx).Do())
|
||||
case "clients":
|
||||
|
||||
@ -25,6 +25,7 @@ func NewServer(root *cobra.Command) {
|
||||
"transformations",
|
||||
"triggers",
|
||||
"variables",
|
||||
"workspaces",
|
||||
"zones",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@ -24,6 +24,7 @@ func NewWeb(root *cobra.Command) {
|
||||
"transformations",
|
||||
"triggers",
|
||||
"variables",
|
||||
"workspaces",
|
||||
"zones",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
@ -18,6 +18,7 @@ func init() {
|
||||
NewList(root)
|
||||
NewProvision(root)
|
||||
NewTypeScript(root)
|
||||
|
||||
cobra.OnInitialize(pkgcmd.InitConfig)
|
||||
}
|
||||
|
||||
|
||||
@ -7,4 +7,6 @@ type GoogleTagManagerContainer struct {
|
||||
ContainerID string `json:"containerId" yaml:"containerId"`
|
||||
// (Optional) The workspace id that should be used by the api
|
||||
WorkspaceID string `json:"workspaceId" yaml:"workspaceId"`
|
||||
// (Optional) The workspace name that should be used by the api
|
||||
Workspace string `json:"workspace" yaml:"workspace"`
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ type (
|
||||
folders *AccessedMap[*tagmanager.Folder]
|
||||
variables *AccessedMap[*tagmanager.Variable]
|
||||
environments *AccessedMap[*tagmanager.Environment]
|
||||
workspaces *AccessedMap[*tagmanager.Workspace]
|
||||
builtInVariables *AccessedMap[*tagmanager.BuiltInVariable]
|
||||
triggers *AccessedMap[*tagmanager.Trigger]
|
||||
tags *AccessedMap[*tagmanager.Tag]
|
||||
@ -236,11 +237,15 @@ func (t *TagManager) Notes(v any) string {
|
||||
|
||||
func (t *TagManager) EnsureWorkspaceID(ctx context.Context) error {
|
||||
if t.WorkspaceID() == "" {
|
||||
environment, err := t.GetEnvironment(ctx, "workspace")
|
||||
if err != nil {
|
||||
return err
|
||||
name := t.container.Workspace
|
||||
if name == "" {
|
||||
name = "Default Workspace"
|
||||
}
|
||||
t.container.WorkspaceID = environment.WorkspaceId
|
||||
workspace, err := t.GetWorkspace(ctx, name)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get default workspace")
|
||||
}
|
||||
t.container.WorkspaceID = workspace.WorkspaceId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -350,6 +355,19 @@ func (t *TagManager) GetEnvironment(ctx context.Context, typeName string) (*tagm
|
||||
return elems.Get(typeName), nil
|
||||
}
|
||||
|
||||
func (t *TagManager) GetWorkspace(ctx context.Context, name string) (*tagmanager.Workspace, error) {
|
||||
elems, err := t.LoadWorkspaces(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !elems.Has(name) {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return elems.Get(name), nil
|
||||
}
|
||||
|
||||
func (t *TagManager) GetBuiltInVariable(ctx context.Context, typeName string) (*tagmanager.BuiltInVariable, error) {
|
||||
elems, err := t.LoadBuiltInVariables(ctx)
|
||||
if err != nil {
|
||||
@ -363,8 +381,26 @@ func (t *TagManager) GetBuiltInVariable(ctx context.Context, typeName string) (*
|
||||
return elems.Get(typeName), nil
|
||||
}
|
||||
|
||||
func (t *TagManager) LoadWorkspaces(ctx context.Context) (*AccessedMap[*tagmanager.Workspace], error) {
|
||||
if t.workspaces == nil {
|
||||
t.l.Info("└ ⬇︎ Loading list", "type", "Workspaces")
|
||||
r, err := t.Service().Accounts.Containers.Workspaces.List(t.ContainerPath()).Context(ctx).Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := map[string]*tagmanager.Workspace{}
|
||||
for _, value := range r.Workspace {
|
||||
res[value.Name] = value
|
||||
}
|
||||
t.workspaces = NewAccessedMap(res)
|
||||
}
|
||||
|
||||
return t.workspaces, nil
|
||||
}
|
||||
|
||||
func (t *TagManager) LoadEnvironments(ctx context.Context) (*AccessedMap[*tagmanager.Environment], error) {
|
||||
if t.builtInVariables == nil {
|
||||
if t.environments == nil {
|
||||
t.l.Info("└ ⬇︎ Loading list", "type", "Environments")
|
||||
r, err := t.Service().Accounts.Containers.Environments.List(t.ContainerPath()).Context(ctx).Do()
|
||||
if err != nil {
|
||||
|
||||
@ -534,6 +534,10 @@
|
||||
"workspaceId": {
|
||||
"type": "string",
|
||||
"description": "(Optional) The workspace id that should be used by the api"
|
||||
},
|
||||
"workspace": {
|
||||
"type": "string",
|
||||
"description": "(Optional) The workspace name that should be used by the api"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
|
||||
@ -28,6 +28,8 @@ googleTagManager:
|
||||
containerId: '175355532'
|
||||
# (Optional) The workspace id that should be used by the api
|
||||
workspaceId: '23'
|
||||
# (Optional) The workspace name that should be used by the api
|
||||
workspace: 'Default Workspace'
|
||||
# Server container settings
|
||||
serverContainer:
|
||||
# The container tag id
|
||||
@ -36,6 +38,8 @@ googleTagManager:
|
||||
containerId: '175348980'
|
||||
# (Optional) The workspace id that should be used by the api
|
||||
workspaceId: '10'
|
||||
# (Optional) The workspace name that should be used by the api
|
||||
workspace: 'Default Workspace'
|
||||
# Web container variables
|
||||
webContainerVariables:
|
||||
dataLayer:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user