Skip to content

Commit

Permalink
[feature] add monitor execution & execute tasks privileges (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
haley-roberts authored Jun 18, 2020
1 parent 5609aec commit 73e443e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/resources/account_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var validAccountPrivileges = newPrivilegeSet(
privilegeCreateIntegration,
privilegeManageGrants,
privilegeMonitorUsage,
privilegeMonitorExecution,
privilegeExecuteTask,
)

var accountGrantSchema = map[string]*schema.Schema{
Expand Down
34 changes: 34 additions & 0 deletions pkg/resources/account_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,40 @@ func TestAccountGrantRead(t *testing.T) {
})
}

func TestMonitorExecution(t *testing.T) {
r := require.New(t)

d := accountGrant(t, "ACCOUNT|||MONITOR EXECUTION", map[string]interface{}{
"privilege": "MONITOR EXECUTION",
"roles": []interface{}{"test-role-1", "test-role-2"},
})

r.NotNil(d)

WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
expectReadAccountGrant(mock)
err := resources.ReadAccountGrant(d, db)
r.NoError(err)
})
}

func TestExecuteTask(t *testing.T) {
r := require.New(t)

d := accountGrant(t, "ACCOUNT|||EXECUTE TASK", map[string]interface{}{
"privilege": "EXECUTE TASK",
"roles": []interface{}{"test-role-1", "test-role-2"},
})

r.NotNil(d)

WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
expectReadAccountGrant(mock)
err := resources.ReadAccountGrant(d, db)
r.NoError(err)
})
}

func expectReadAccountGrant(mock sqlmock.Sqlmock) {
rows := sqlmock.NewRows([]string{
"created_on", "privilege", "granted_on", "name", "granted_to", "grantee_name", "grant_option", "granted_by",
Expand Down
2 changes: 2 additions & 0 deletions pkg/resources/privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const (
privilegeCreateIntegration privilege = "CREATE INTEGRATION"
privilegeManageGrants privilege = "MANAGE GRANTS"
privilegeMonitorUsage privilege = "MONITOR USAGE"
privilegeMonitorExecution privilege = "MONITOR EXECUTION"
privilegeExecuteTask privilege = "EXECUTE TASK"
)

type privilegeSet map[privilege]struct{}
Expand Down

0 comments on commit 73e443e

Please sign in to comment.