Skip to content

Commit 0306ed2

Browse files
STAC-22844: Drop support for setting up a scope on a subject
1 parent 218df2f commit 0306ed2

File tree

150 files changed

+18760
-1352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+18760
-1352
lines changed

cmd/rbac/flags.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ const (
44
Subject = "subject"
55
Permission = "permission"
66
Resource = "resource"
7-
Scope = "scope"
87

98
SubjectUsage = "The handle of the subject of the permissions. If you're using LDAP, please use the usernameKey configured in StackState"
109
PermissionRevokeUsage = "The permission to revoke"
1110
PermissionGrantUsage = "The permission to grant"
1211
PermissionDescribeUsage = "Filter the permissions by permission name"
13-
ResourceDescribeUsage = "Filter the permissions by a resource identifier (e.g. system or a view name)"
14-
ResourceGrantUsage = "The resource to grant the permission to (e.g. \"system\" or a view name)"
15-
ResourceRevokeUsage = "The resource to revoke the permission to (e.g. \"system\" or a view name)"
16-
ScopeUsage = "The query in STQL that will be prepended to every topology element retrieved in StackState. " +
17-
"For example, if your scope is \"label = 'A'\", then all STQL executed in StackState" +
18-
" (e.g. Retrieving topology) will only return elements that have the label A"
12+
ResourceDescribeUsage = "Filter the permissions by a resource identifier (e.g. system, a resource name or tag)"
13+
ResourceGrantUsage = "The resource to grant the permission to (e.g. \"system\" or a resource name or tag)"
14+
ResourceRevokeUsage = "The resource to revoke the permission to (e.g. \"system\" or a resource name or tag)"
1915

20-
DefaultResource = "system"
21-
DefaultScope = "id = '-1'"
22-
DefaultSTQLVersion = "0.0.1"
16+
DefaultResource = "system"
2317
)

cmd/rbac/rbac_create_subject.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
type CreateSubjectArgs struct {
1111
Subject string
12-
Scope string
1312
}
1413

1514
func CreateSubjectCommand(deps *di.Deps) *cobra.Command {
@@ -24,8 +23,6 @@ func CreateSubjectCommand(deps *di.Deps) *cobra.Command {
2423
cmd.Flags().StringVar(&args.Subject, Subject, "", SubjectUsage)
2524
cmd.MarkFlagRequired(Subject) //nolint:errcheck
2625

27-
cmd.Flags().StringVar(&args.Scope, Scope, DefaultScope, ScopeUsage)
28-
2926
return cmd
3027
}
3128

@@ -36,9 +33,7 @@ func RunCreateSubjectCommand(args *CreateSubjectArgs) di.CmdWithApiFn {
3633
api *stackstate_api.APIClient,
3734
serverInfo *stackstate_api.ServerInfo,
3835
) common.CLIError {
39-
subject := stackstate_api.NewCreateSubject(args.Scope, DefaultSTQLVersion)
4036
resp, err := api.SubjectApi.CreateSubject(cli.Context, args.Subject).
41-
CreateSubject(*subject).
4237
Execute()
4338

4439
if err != nil {

cmd/rbac/rbac_create_subject_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
87
"github.com/stackvista/stackstate-cli/internal/di"
98
"github.com/stretchr/testify/assert"
109
)
@@ -24,10 +23,6 @@ func TestCreateSubjectJson(t *testing.T) {
2423
assert.Len(t, calls, 1)
2524
assert.Equal(t, SomeSubject, calls[0].Psubject)
2625

27-
expectedSubject := stackstate_api.NewCreateSubject(DefaultScope, DefaultSTQLVersion)
28-
29-
assert.Equal(t, expectedSubject, calls[0].PcreateSubject)
30-
3126
expectedJson := []map[string]interface{}{
3227
{
3328
"created-subject": SomeSubject,
@@ -41,16 +36,12 @@ func TestCreateSubject(t *testing.T) {
4136
cli := di.NewMockDeps(t)
4237
cmd := CreateSubjectCommand(&cli.Deps)
4338

44-
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--subject", SomeOtherSubject, "--scope", SomeScope)
39+
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--subject", SomeOtherSubject)
4540

4641
calls := *cli.MockClient.ApiMocks.SubjectApi.CreateSubjectCalls
4742
assert.Len(t, calls, 1)
4843
assert.Equal(t, SomeOtherSubject, calls[0].Psubject)
4944

50-
otherExpectedSubject := stackstate_api.NewCreateSubject(SomeScope, DefaultSTQLVersion)
51-
52-
assert.Equal(t, otherExpectedSubject, calls[0].PcreateSubject)
53-
5445
expectedStrings := []string{
5546
fmt.Sprintf("Created subject '%s'", SomeOtherSubject),
5647
}

cmd/rbac/rbac_describe_subjects.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ func RunDescribeSubjectsCommand(args *DescribeSubjectsArgs) di.CmdWithApiFn {
4242

4343
if cli.IsJson() {
4444
cli.Printer.PrintJson(map[string]interface{}{
45-
"handle": subject.Handle,
46-
"scopeQuery": safeDeref(subject.ScopeQuery),
45+
"handle": subject.Handle,
4746
})
4847
} else {
4948
cli.Printer.Table(printer.TableData{
50-
Header: []string{"Subject", "Scope Query"},
49+
Header: []string{"Subject"},
5150
Data: [][]interface{}{
5251
{
5352
subject.Handle,
54-
safeDeref(subject.ScopeQuery),
5553
},
5654
},
5755
MissingTableDataMsg: printer.NotFoundMsg{Types: "matching subjects"},
@@ -72,11 +70,11 @@ func RunDescribeSubjectsCommand(args *DescribeSubjectsArgs) di.CmdWithApiFn {
7270
data := make([][]interface{}, 0)
7371

7472
for _, subject := range subjects {
75-
data = append(data, []interface{}{subject.Handle, safeDeref(subject.ScopeQuery)})
73+
data = append(data, []interface{}{subject.Handle})
7674
}
7775

7876
cli.Printer.Table(printer.TableData{
79-
Header: []string{"Subject", "Scope Query"},
77+
Header: []string{"Subject"},
8078
Data: data,
8179
MissingTableDataMsg: printer.NotFoundMsg{Types: "subjects"},
8280
})
@@ -85,10 +83,3 @@ func RunDescribeSubjectsCommand(args *DescribeSubjectsArgs) di.CmdWithApiFn {
8583
return nil
8684
}
8785
}
88-
89-
func safeDeref(text *string) string {
90-
if text == nil {
91-
return ""
92-
}
93-
return *text
94-
}

cmd/rbac/rbac_describe_subjects_test.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,17 @@ import (
1212
var (
1313
SomeScopeVar = SomeScope
1414
SubjectConfig1 = stackstate_api.SubjectConfig{
15-
Handle: SomeSubject,
16-
ScopeQuery: &SomeScopeVar,
15+
Handle: SomeSubject,
1716
}
1817

1918
SomeOtherSubject = "handle"
20-
SomeOtherScope = "meaningOfLife = 23"
2119

2220
SubjectConfig2 = stackstate_api.SubjectConfig{
23-
Handle: SomeOtherSubject,
24-
ScopeQuery: &SomeOtherScope,
21+
Handle: SomeOtherSubject,
2522
}
2623

2724
SubjectConfig3 = stackstate_api.SubjectConfig{
28-
Handle: SubjectHandle,
29-
ScopeQuery: nil,
25+
Handle: SubjectHandle,
3026
}
3127
)
3228

@@ -47,11 +43,11 @@ func TestDescribeSubjectsTable(t *testing.T) {
4743

4844
expected := []printer.TableData{
4945
{
50-
Header: []string{"Subject", "Scope Query"},
46+
Header: []string{"Subject"},
5147
Data: [][]interface{}{
52-
{SubjectConfig1.Handle, *SubjectConfig1.ScopeQuery},
53-
{SubjectConfig2.Handle, *SubjectConfig2.ScopeQuery},
54-
{SubjectConfig3.Handle, ""},
48+
{SubjectConfig1.Handle},
49+
{SubjectConfig2.Handle},
50+
{SubjectConfig3.Handle},
5551
},
5652
MissingTableDataMsg: printer.NotFoundMsg{Types: "subjects"},
5753
},
@@ -100,9 +96,9 @@ func TestDescribeSubjectsTableWithFilter(t *testing.T) {
10096

10197
expected := []printer.TableData{
10298
{
103-
Header: []string{"Subject", "Scope Query"},
99+
Header: []string{"Subject"},
104100
Data: [][]interface{}{
105-
{SubjectConfig1.Handle, *SubjectConfig1.ScopeQuery},
101+
{SubjectConfig1.Handle},
106102
},
107103
MissingTableDataMsg: printer.NotFoundMsg{Types: "matching subjects"},
108104
},
@@ -130,12 +126,10 @@ func TestDescribeSubjectsJsonWithFilter(t *testing.T) {
130126

131127
expectedJson := []map[string]interface{}{
132128
{
133-
"handle": SubjectConfig1.Handle,
134-
"scopeQuery": *SubjectConfig1.ScopeQuery,
129+
"handle": SubjectConfig1.Handle,
135130
},
136131
{
137-
"handle": SubjectConfig3.Handle,
138-
"scopeQuery": "",
132+
"handle": SubjectConfig3.Handle,
139133
},
140134
}
141135

0 commit comments

Comments
 (0)