Skip to content

Commit

Permalink
chore: add roles for bq, metabase and grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
Chief-Rishab committed Dec 3, 2023
1 parent 6a5836b commit 5980afb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
23 changes: 23 additions & 0 deletions plugins/providers/bigquery/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,33 @@ import (
)

const (
// legacy roles
DatasetRoleReader = "READER"
DatasetRoleWriter = "WRITER"
DatasetRoleOwner = "OWNER"

// new roles
BigQueryRoleAdmin = "roles/bigquery.admin"
BigQueryRoleUser = "roles/bigquery.user"

BigQueryConnectionAdmin = "roles/bigquery.connectionAdmin"
BigQueryConnectionUser = "roles/bigquery.connectionUser"

BigQueryRoleDataEditor = "roles/bigquery.dataEditor"
BigQueryRoleDataOwner = "roles/bigquery.dataOwner"
BigQueryRoleDataViewer = "roles/bigquery.dataViewer"

BigQueryFilteredDataViewer = "roles/bigquery.filteredDataViewer"
BigQueryRoleJobUser = "roles/bigquery.jobUser"
BigQueryRoleMetaViewer = "roles/bigquery.metadataViewer"

BigQueryReadSessionUser = "roles/bigquery.readSessionUser"
BigQueryResourceAdmin = "roles/bigquery.resourceAdmin"
BigQueryResourceEditor = "roles/bigquery.resourceEditor"
BigQueryResourceViewer = "roles/bigquery.resourceViewer"

BigQueryMaskedReader = "roles/bigquerydatapolicy.maskedReader"

AccountTypeUser = "user"
AccountTypeServiceAccount = "serviceAccount"
)
Expand Down
15 changes: 15 additions & 0 deletions plugins/providers/bigquery/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ func (p *Provider) GetDefaultRoles(ctx context.Context, name string, resourceTyp
DatasetRoleOwner,
DatasetRoleWriter,
DatasetRoleReader,
BigQueryRoleAdmin,
BigQueryRoleUser,
BigQueryRoleDataOwner,
BigQueryRoleDataEditor,
BigQueryRoleDataViewer,
BigQueryConnectionAdmin,
BigQueryConnectionUser,
BigQueryFilteredDataViewer,
BigQueryRoleJobUser,
BigQueryRoleMetaViewer,
BigQueryReadSessionUser,
BigQueryResourceAdmin,
BigQueryResourceEditor,
BigQueryResourceViewer,
BigQueryMaskedReader,
}, nil
}

Expand Down
10 changes: 9 additions & 1 deletion plugins/providers/grafana/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ func (p *provider) GetType() string {

// GetDefaultRoles returns a list of roles supported by the provider
func (p *provider) GetDefaultRoles(ctx context.Context, name string, resourceType string) ([]string, error) {
return []string{}, nil
if resourceType == ResourceTypeDashboard || resourceType == "" {
return []string{
DashboardRoleAdmin,
DashboardRoleEditor,
DashboardRoleViewer,
}, nil
}

return nil, ErrInvalidResourceType
}

func (p *provider) CreateConfig(pc *domain.ProviderConfig) error {
Expand Down
27 changes: 26 additions & 1 deletion plugins/providers/metabase/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,32 @@ func (p *provider) GetType() string {

// GetDefaultRoles returns a list of roles supported by the provider
func (p *provider) GetDefaultRoles(ctx context.Context, name string, resourceType string) ([]string, error) {
return []string{}, nil
databaseRoles := []string{
DatabaseRoleViewer,
DatabaseRoleEditor,
}
collectionRoles := []string{
CollectionRoleViewer,
CollectionRoleCurate,
}
tableRoles := []string{
TableRoleViewer,
}
allRoles := append(databaseRoles, collectionRoles...)
allRoles = append(allRoles, tableRoles...)

switch resourceType {
case ResourceTypeDatabase:
return databaseRoles, nil
case ResourceTypeCollection:
return collectionRoles, nil
case ResourceTypeTable:
return tableRoles, nil
case "":
return allRoles, nil
default:
return nil, ErrInvalidResourceType
}
}

func (p *provider) CreateConfig(pc *domain.ProviderConfig) error {
Expand Down

0 comments on commit 5980afb

Please sign in to comment.