Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,32 @@ poweradmin groups zone-add --group-id 1 --zone-id 78
poweradmin groups zone-remove --group-id 1 --zone-id 78
```

### Permission Templates

```bash
# List all permission templates
poweradmin permission-templates list
poweradmin permission-templates list -o json

# Get a template by name or ID (shows full permission list)
poweradmin permission-templates get --name Administrator
poweradmin permission-templates get --id 1 -o json

# Create a template
poweradmin permission-templates create --name "Zone Editors" --description "Can edit zone records"
poweradmin permission-templates create --name "Zone Editors" --type group --permissions 1,2,3

# Create and capture the ID
PT_ID=$(poweradmin permission-templates create --name "Zone Editors" -q)

# Update a template
poweradmin permission-templates update --name "Zone Editors" --new-name "DNS Editors"
poweradmin permission-templates update --name "Zone Editors" --permissions 1,2,3,4

# Delete a template
poweradmin permission-templates delete --name "Zone Editors" --yes
```

### Version

```bash
Expand Down
2 changes: 2 additions & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

"github.com/contentways/poweradmin-cli/internal/cmd/groups"
"github.com/contentways/poweradmin-cli/internal/cmd/permission_templates"
"github.com/contentways/poweradmin-cli/internal/cmd/records"
"github.com/contentways/poweradmin-cli/internal/cmd/users"
cmdversion "github.com/contentways/poweradmin-cli/internal/cmd/version"
Expand Down Expand Up @@ -70,6 +71,7 @@ func NewRootCommand(s *state.State) *cobra.Command {
root.AddCommand(users.NewUsersCommand(s))
root.AddCommand(groups.NewGroupsCommand(s))
root.AddCommand(cmdversion.NewVersionCmd())
root.AddCommand(permission_templates.NewPermissionTemplatesCommand(s))

return root
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNewRootCommand(t *testing.T) {
t.Fatalf("Use = %q", cmd.Use)
}

if len(cmd.Commands()) != 5 {
t.Fatalf("got %d commands, want 5", len(cmd.Commands()))
if len(cmd.Commands()) != 6 {
t.Fatalf("got %d commands, want 6", len(cmd.Commands()))
}
}
8 changes: 4 additions & 4 deletions internal/cmd/groups/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGroupsCreate(t *testing.T) {
return 42, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewCreateCmd(), []string{"--name", "TestGroup"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -36,7 +36,7 @@ func TestGroupsCreateJSON(t *testing.T) {
return 42, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewCreateCmd(), []string{"--name", "TestGroup", "-o", "json"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -48,7 +48,7 @@ func TestGroupsCreateJSON(t *testing.T) {
}

func TestGroupsCreateMissingName(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewCreateCmd(), []string{})
if err == nil {
t.Fatal("expected error when name is missing")
Expand All @@ -61,7 +61,7 @@ func TestGroupsCreateError(t *testing.T) {
return 0, nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewCreateCmd(), []string{"--name", "TestGroup"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/groups/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestGroupsDelete(t *testing.T) {
return nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewDeleteCmd(nil), []string{"--name", "TestGroup", "--yes"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -42,7 +42,7 @@ func TestGroupsDeleteJSON(t *testing.T) {
return nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewDeleteCmd(nil), []string{"--name", "TestGroup", "--yes", "-o", "json"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -54,7 +54,7 @@ func TestGroupsDeleteJSON(t *testing.T) {
}

func TestGroupsDeleteMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewDeleteCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -70,7 +70,7 @@ func TestGroupsDeleteError(t *testing.T) {
return nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewDeleteCmd(nil), []string{"--name", "TestGroup", "--yes"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/groups/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGroupsGetByName(t *testing.T) {
return &poweradmin.Group{ID: 1, Name: name, Description: "Full access"}, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewGetCmd(nil), []string{"--name", "Administrators"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -36,7 +36,7 @@ func TestGroupsGetJSON(t *testing.T) {
return &poweradmin.Group{ID: 1, Name: name}, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewGetCmd(nil), []string{"--name", "Administrators", "-o", "json"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -48,7 +48,7 @@ func TestGroupsGetJSON(t *testing.T) {
}

func TestGroupsGetMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewGetCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -61,7 +61,7 @@ func TestGroupsGetError(t *testing.T) {
return nil, nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewGetCmd(nil), []string{"--name", "Administrators"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/groups/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestGroupsList(t *testing.T) {
}, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewListCmd(nil), []string{})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -41,7 +41,7 @@ func TestGroupsListJSON(t *testing.T) {
}, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewListCmd(nil), []string{"-o", "json"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -58,7 +58,7 @@ func TestGroupsListError(t *testing.T) {
return nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewListCmd(nil), []string{})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/groups/member_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGroupsMemberAdd(t *testing.T) {
return nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewMemberAddCmd(nil), []string{"--group-id", "1", "--user-id", "2"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -31,7 +31,7 @@ func TestGroupsMemberAdd(t *testing.T) {
}

func TestGroupsMemberAddMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewMemberAddCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -44,7 +44,7 @@ func TestGroupsMemberAddError(t *testing.T) {
return nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewMemberAddCmd(nil), []string{"--group-id", "1", "--user-id", "2"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/groups/member_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGroupsMemberRemove(t *testing.T) {
return nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewMemberRemoveCmd(nil), []string{"--group-id", "1", "--user-id", "2"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -31,7 +31,7 @@ func TestGroupsMemberRemove(t *testing.T) {
}

func TestGroupsMemberRemoveMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewMemberRemoveCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -44,7 +44,7 @@ func TestGroupsMemberRemoveError(t *testing.T) {
return nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewMemberRemoveCmd(nil), []string{"--group-id", "1", "--user-id", "2"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/groups/members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestGroupsMembers(t *testing.T) {
}, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewMembersCmd(nil), []string{"--name", "Administrators"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -36,7 +36,7 @@ func TestGroupsMembers(t *testing.T) {
}

func TestGroupsMembersMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewMembersCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -52,7 +52,7 @@ func TestGroupsMembersError(t *testing.T) {
return nil, nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewMembersCmd(nil), []string{"--name", "Administrators"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/groups/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestGroupsUpdate(t *testing.T) {
return &poweradmin.Group{ID: 42, Name: "NewName"}, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewUpdateCmd(nil), []string{"--name", "TestGroup", "--new-name", "NewName"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -42,7 +42,7 @@ func TestGroupsUpdateJSON(t *testing.T) {
return &poweradmin.Group{ID: 42, Name: "NewName"}, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewUpdateCmd(nil), []string{"--name", "TestGroup", "--new-name", "NewName", "-o", "json"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -54,7 +54,7 @@ func TestGroupsUpdateJSON(t *testing.T) {
}

func TestGroupsUpdateMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewUpdateCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -70,7 +70,7 @@ func TestGroupsUpdateError(t *testing.T) {
return nil, nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewUpdateCmd(nil), []string{"--name", "TestGroup", "--new-name", "NewName"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/groups/zone_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGroupsZoneAdd(t *testing.T) {
return nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewZoneAddCmd(nil), []string{"--group-id", "1", "--zone-id", "78"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -31,7 +31,7 @@ func TestGroupsZoneAdd(t *testing.T) {
}

func TestGroupsZoneAddMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewZoneAddCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -44,7 +44,7 @@ func TestGroupsZoneAddError(t *testing.T) {
return nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewZoneAddCmd(nil), []string{"--group-id", "1", "--zone-id", "78"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/groups/zone_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGroupsZoneRemove(t *testing.T) {
return nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewZoneRemoveCmd(nil), []string{"--group-id", "1", "--zone-id", "78"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -31,7 +31,7 @@ func TestGroupsZoneRemove(t *testing.T) {
}

func TestGroupsZoneRemoveMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewZoneRemoveCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -44,7 +44,7 @@ func TestGroupsZoneRemoveError(t *testing.T) {
return nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewZoneRemoveCmd(nil), []string{"--group-id", "1", "--zone-id", "78"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/groups/zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestGroupsZones(t *testing.T) {
}, nil, nil
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewZonesCmd(nil), []string{"--name", "Administrators"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand All @@ -36,7 +36,7 @@ func TestGroupsZones(t *testing.T) {
}

func TestGroupsZonesMissingFlags(t *testing.T) {
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{})
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, &testutil.MockGroupClient{}, nil)
err := fx.Run(groups.NewZonesCmd(nil), []string{})
if err == nil {
t.Fatal("expected error when no flags provided")
Expand All @@ -52,7 +52,7 @@ func TestGroupsZonesError(t *testing.T) {
return nil, nil, fmt.Errorf("api error")
},
}
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup)
fx := testutil.NewFixtureWithAllMocks(t, nil, nil, nil, mockGroup, nil)
err := fx.Run(groups.NewZonesCmd(nil), []string{"--name", "Administrators"})
if err == nil {
t.Fatal("expected error, got nil")
Expand Down
Loading
Loading