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'
|
containerId: '175355532'
|
||||||
# (Optional) The workspace id that should be used by the api
|
# (Optional) The workspace id that should be used by the api
|
||||||
workspaceId: '23'
|
workspaceId: '23'
|
||||||
|
# (Optional) The workspace name that should be used by the api
|
||||||
|
workspace: 'Default Workspace'
|
||||||
# Server container settings
|
# Server container settings
|
||||||
serverContainer:
|
serverContainer:
|
||||||
# The container tag id
|
# The container tag id
|
||||||
@ -90,6 +92,8 @@ googleTagManager:
|
|||||||
containerId: '175348980'
|
containerId: '175348980'
|
||||||
# (Optional) The workspace id that should be used by the api
|
# (Optional) The workspace id that should be used by the api
|
||||||
workspaceId: '10'
|
workspaceId: '10'
|
||||||
|
# (Optional) The workspace name that should be used by the api
|
||||||
|
workspace: 'Default Workspace'
|
||||||
# Web container variables
|
# Web container variables
|
||||||
webContainerVariables:
|
webContainerVariables:
|
||||||
dataLayer:
|
dataLayer:
|
||||||
|
|||||||
@ -37,6 +37,8 @@ func list(ctx context.Context, l *slog.Logger, tm *tagmanager.TagManager, resour
|
|||||||
switch resource {
|
switch resource {
|
||||||
case "environments":
|
case "environments":
|
||||||
return dump(tm.Service().Accounts.Containers.Environments.List(tm.ContainerPath()).Context(ctx).Do())
|
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":
|
case "status":
|
||||||
return dump(tm.Service().Accounts.Containers.Workspaces.GetStatus(tm.WorkspacePath()).Context(ctx).Do())
|
return dump(tm.Service().Accounts.Containers.Workspaces.GetStatus(tm.WorkspacePath()).Context(ctx).Do())
|
||||||
case "clients":
|
case "clients":
|
||||||
|
|||||||
@ -25,6 +25,7 @@ func NewServer(root *cobra.Command) {
|
|||||||
"transformations",
|
"transformations",
|
||||||
"triggers",
|
"triggers",
|
||||||
"variables",
|
"variables",
|
||||||
|
"workspaces",
|
||||||
"zones",
|
"zones",
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|||||||
@ -24,6 +24,7 @@ func NewWeb(root *cobra.Command) {
|
|||||||
"transformations",
|
"transformations",
|
||||||
"triggers",
|
"triggers",
|
||||||
"variables",
|
"variables",
|
||||||
|
"workspaces",
|
||||||
"zones",
|
"zones",
|
||||||
},
|
},
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|||||||
@ -18,6 +18,7 @@ func init() {
|
|||||||
NewList(root)
|
NewList(root)
|
||||||
NewProvision(root)
|
NewProvision(root)
|
||||||
NewTypeScript(root)
|
NewTypeScript(root)
|
||||||
|
|
||||||
cobra.OnInitialize(pkgcmd.InitConfig)
|
cobra.OnInitialize(pkgcmd.InitConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,4 +7,6 @@ type GoogleTagManagerContainer struct {
|
|||||||
ContainerID string `json:"containerId" yaml:"containerId"`
|
ContainerID string `json:"containerId" yaml:"containerId"`
|
||||||
// (Optional) The workspace id that should be used by the api
|
// (Optional) The workspace id that should be used by the api
|
||||||
WorkspaceID string `json:"workspaceId" yaml:"workspaceId"`
|
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]
|
folders *AccessedMap[*tagmanager.Folder]
|
||||||
variables *AccessedMap[*tagmanager.Variable]
|
variables *AccessedMap[*tagmanager.Variable]
|
||||||
environments *AccessedMap[*tagmanager.Environment]
|
environments *AccessedMap[*tagmanager.Environment]
|
||||||
|
workspaces *AccessedMap[*tagmanager.Workspace]
|
||||||
builtInVariables *AccessedMap[*tagmanager.BuiltInVariable]
|
builtInVariables *AccessedMap[*tagmanager.BuiltInVariable]
|
||||||
triggers *AccessedMap[*tagmanager.Trigger]
|
triggers *AccessedMap[*tagmanager.Trigger]
|
||||||
tags *AccessedMap[*tagmanager.Tag]
|
tags *AccessedMap[*tagmanager.Tag]
|
||||||
@ -236,11 +237,15 @@ func (t *TagManager) Notes(v any) string {
|
|||||||
|
|
||||||
func (t *TagManager) EnsureWorkspaceID(ctx context.Context) error {
|
func (t *TagManager) EnsureWorkspaceID(ctx context.Context) error {
|
||||||
if t.WorkspaceID() == "" {
|
if t.WorkspaceID() == "" {
|
||||||
environment, err := t.GetEnvironment(ctx, "workspace")
|
name := t.container.Workspace
|
||||||
if err != nil {
|
if name == "" {
|
||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
@ -350,6 +355,19 @@ func (t *TagManager) GetEnvironment(ctx context.Context, typeName string) (*tagm
|
|||||||
return elems.Get(typeName), nil
|
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) {
|
func (t *TagManager) GetBuiltInVariable(ctx context.Context, typeName string) (*tagmanager.BuiltInVariable, error) {
|
||||||
elems, err := t.LoadBuiltInVariables(ctx)
|
elems, err := t.LoadBuiltInVariables(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -363,8 +381,26 @@ func (t *TagManager) GetBuiltInVariable(ctx context.Context, typeName string) (*
|
|||||||
return elems.Get(typeName), nil
|
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) {
|
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")
|
t.l.Info("└ ⬇︎ Loading list", "type", "Environments")
|
||||||
r, err := t.Service().Accounts.Containers.Environments.List(t.ContainerPath()).Context(ctx).Do()
|
r, err := t.Service().Accounts.Containers.Environments.List(t.ContainerPath()).Context(ctx).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -534,6 +534,10 @@
|
|||||||
"workspaceId": {
|
"workspaceId": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "(Optional) The workspace id that should be used by the api"
|
"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,
|
"additionalProperties": false,
|
||||||
|
|||||||
@ -28,6 +28,8 @@ googleTagManager:
|
|||||||
containerId: '175355532'
|
containerId: '175355532'
|
||||||
# (Optional) The workspace id that should be used by the api
|
# (Optional) The workspace id that should be used by the api
|
||||||
workspaceId: '23'
|
workspaceId: '23'
|
||||||
|
# (Optional) The workspace name that should be used by the api
|
||||||
|
workspace: 'Default Workspace'
|
||||||
# Server container settings
|
# Server container settings
|
||||||
serverContainer:
|
serverContainer:
|
||||||
# The container tag id
|
# The container tag id
|
||||||
@ -36,6 +38,8 @@ googleTagManager:
|
|||||||
containerId: '175348980'
|
containerId: '175348980'
|
||||||
# (Optional) The workspace id that should be used by the api
|
# (Optional) The workspace id that should be used by the api
|
||||||
workspaceId: '10'
|
workspaceId: '10'
|
||||||
|
# (Optional) The workspace name that should be used by the api
|
||||||
|
workspace: 'Default Workspace'
|
||||||
# Web container variables
|
# Web container variables
|
||||||
webContainerVariables:
|
webContainerVariables:
|
||||||
dataLayer:
|
dataLayer:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user