Skip to content

Commit

Permalink
Add permission table
Browse files Browse the repository at this point in the history
  • Loading branch information
emeric-martineau committed Jul 26, 2023
1 parent 9fb1f09 commit ed9429d
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 71 deletions.
25 changes: 25 additions & 0 deletions docs/tables/metabase_permission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Table: metabase_permission

List all permissions of Metabase.

## Examples

### List all permissions

```sql
select
*
from
metabase_permission;
```

### Get permission of one group

```sql
select
*
from
metabase_permission_group
where
group_id=15;
```
14 changes: 14 additions & 0 deletions docs/tables/metabase_permission_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Table: metabase_permission_data

List data permission of Metabase.

## Examples

### List all permissions

```sql
select
*
from
metabase_permission_data;
```
14 changes: 14 additions & 0 deletions docs/tables/metabase_permission_download.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Table: metabase_permission_download

List download permission of Metabase.

## Examples

### List all permissions

```sql
select
*
from
metabase_permission_download;
```
11 changes: 7 additions & 4 deletions metabase/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ func Plugin(ctx context.Context) *plugin.Plugin {
Schema: ConfigSchema,
},
TableMap: map[string]*plugin.Table{
"metabase_db": tableMetabaseDb(),
"metabase_db_feature": tableMetabaseDbFeature(),
"metabase_db_table": tableMetabaseDbTable(),
"metabase_permission_group": tableMetabaseGroup(),
"metabase_db": tableMetabaseDb(),
"metabase_db_feature": tableMetabaseDbFeature(),
"metabase_db_table": tableMetabaseDbTable(),
"metabase_permission_group": tableMetabaseGroup(),
"metabase_permission": tableMetabasePermission(),
"metabase_permission_data": tableMetabasePermissionData(),
"metabase_permission_download": tableMetabasePermissionDownload(),
},
}
return p
Expand Down
19 changes: 6 additions & 13 deletions metabase/table_metabase_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metabase

import (
"context"
"fmt"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
Expand Down Expand Up @@ -41,7 +40,7 @@ func tableMetabaseDb() *plugin.Table {
}

func listDatabase(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
client, err := connect(d)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.listDatabases", "connection_error", err)
Expand All @@ -52,12 +51,9 @@ func listDatabase(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateDat

dbList, resp, err := client.DatabaseApi.ListDatabasesExecute(request)

err = manageError("metabase_db.listDatabases", ctx, resp, err)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.listDatabases", err)
return nil, err
} else if resp.StatusCode >= 300 {
err = fmt.Errorf("HTTP code = %d", resp.StatusCode)
plugin.Logger(ctx).Error("metabase_db.listDatabases", err)
return nil, err
}

Expand All @@ -69,7 +65,7 @@ func listDatabase(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateDat
}

func getDatabase(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
client, err := connect(d)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getDatabase", "connection_error", err)
Expand All @@ -83,12 +79,9 @@ func getDatabase(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData

db, resp, err := client.DatabaseApi.GetDatabaseExecute(request)

err = manageError("metabase_db.getDatabase", ctx, resp, err)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getDatabase", err)
return nil, err
} else if resp.StatusCode >= 300 {
err = fmt.Errorf("HTTP code = %d", resp.StatusCode)
plugin.Logger(ctx).Error("metabase_db.getDatabase", err)
return nil, err
}

Expand Down
16 changes: 6 additions & 10 deletions metabase/table_metabase_db_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metabase

import (
"context"
"fmt"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
Expand All @@ -20,7 +19,7 @@ func tableMetabaseDbFeature() *plugin.Table {
Description: "Features of one database.",
List: &plugin.ListConfig{
KeyColumns: plugin.AllColumns([]string{"db_id"}),
Hydrate: listDatabaseFeatures,
Hydrate: listDatabaseFeature,
},

Columns: []*plugin.Column{
Expand All @@ -30,11 +29,11 @@ func tableMetabaseDbFeature() *plugin.Table {
}
}

func listDatabaseFeatures(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
func listDatabaseFeature(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
client, err := connect(d)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getDatabaseFeatures", "connection_error", err)
plugin.Logger(ctx).Error("metabase_db_feature.listDatabaseFeature", "connection_error", err)
return nil, err
}

Expand All @@ -45,12 +44,9 @@ func listDatabaseFeatures(ctx context.Context, d *plugin.QueryData, h *plugin.Hy

db, resp, err := client.DatabaseApi.GetDatabaseExecute(request)

err = manageError("metabase_db_feature.listDatabaseFeature", ctx, resp, err)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getDatabaseFeatures", err)
return nil, err
} else if resp.StatusCode >= 300 {
err = fmt.Errorf("HTTP code = %d", resp.StatusCode)
plugin.Logger(ctx).Error("metabase_db.getDatabaseFeatures", err)
return nil, err
}

Expand Down
26 changes: 8 additions & 18 deletions metabase/table_metabase_db_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metabase

import (
"context"
"fmt"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
Expand Down Expand Up @@ -41,10 +40,10 @@ func tableMetabaseDbTable() *plugin.Table {
}

func listDatabaseTable(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
client, err := connect(d)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.listDatabaseTable", "connection_error", err)
plugin.Logger(ctx).Error("metabase_db_table.listDatabaseTable", "connection_error", err)
return nil, err
}

Expand All @@ -56,15 +55,9 @@ func listDatabaseTable(ctx context.Context, d *plugin.QueryData, _ *plugin.Hydra

db, resp, err := client.DatabaseApi.GetDatabaseExecute(request)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.listDatabaseTable", err)

return nil, err
} else if resp.StatusCode >= 300 {
err = fmt.Errorf("HTTP code = %d", resp.StatusCode)
plugin.Logger(ctx).Debug("metabase_db.listDatabaseTable", "http-response", resp)
plugin.Logger(ctx).Error("metabase_db.listDatabaseTable", err)
err = manageError("metabase_db_table.listDatabaseTable", ctx, resp, err)

if err != nil {
return nil, err
}

Expand All @@ -76,10 +69,10 @@ func listDatabaseTable(ctx context.Context, d *plugin.QueryData, _ *plugin.Hydra
}

func getDatabaseTable(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
client, err := connect(d)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getDatabaseTable", "connection_error", err)
plugin.Logger(ctx).Error("metabase_db_table.getDatabaseTable", "connection_error", err)
return nil, err
}

Expand All @@ -92,12 +85,9 @@ func getDatabaseTable(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrat

db, resp, err := client.DatabaseApi.GetDatabaseExecute(request)

err = manageError("metabase_db_table.getDatabaseTable", ctx, resp, err)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getDatabaseTable", err)
return nil, err
} else if resp.StatusCode >= 300 {
err = fmt.Errorf("HTTP code = %d", resp.StatusCode)
plugin.Logger(ctx).Error("metabase_db.getDatabaseTable", err)
return nil, err
}

Expand Down
28 changes: 9 additions & 19 deletions metabase/table_metabase_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metabase

import (
"context"
"fmt"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
Expand All @@ -22,34 +21,28 @@ func tableMetabaseGroup() *plugin.Table {
},
Columns: []*plugin.Column{
// Key column cannot be a pointer. Transform helps us to manage them
{Name: "id", Type: proto.ColumnType_INT, Transform: transform.FromField("Id"), Description: "ID of groud."},
{Name: "id", Type: proto.ColumnType_INT, Transform: transform.FromField("Id"), Description: "ID of group."},
{Name: "name", Type: proto.ColumnType_STRING, Description: "Name of group"},
{Name: "member_count", Type: proto.ColumnType_STRING, Description: "Number of member."},
},
}
}

func listPermissionGroup(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
client, err := connect(d)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.listPermissionGroup", "connection_error", err)
plugin.Logger(ctx).Error("metabase_permission_group.listPermissionGroup", "connection_error", err)
return nil, err
}

request := client.PermissionsApi.GetPermissionsGroup(context.Background())

permissions, resp, err := client.PermissionsApi.GetPermissionsGroupExecute(request)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.listPermissionGroup", err)

return nil, err
} else if resp.StatusCode >= 300 {
err = fmt.Errorf("HTTP code = %d", resp.StatusCode)
plugin.Logger(ctx).Debug("metabase_db.listPermissionGroup", "http-response", resp)
plugin.Logger(ctx).Error("metabase_db.listPermissionGroup", err)
err = manageError("metabase_permission_group.listPermissionGroup", ctx, resp, err)

if err != nil {
return nil, err
}

Expand All @@ -61,10 +54,10 @@ func listPermissionGroup(ctx context.Context, d *plugin.QueryData, _ *plugin.Hyd
}

func getPermissionGroup(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
client, err := connect(d)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getPermissionGroup", "connection_error", err)
plugin.Logger(ctx).Error("metabase_permission_group.getPermissionGroup", "connection_error", err)
return nil, err
}

Expand All @@ -75,12 +68,9 @@ func getPermissionGroup(ctx context.Context, d *plugin.QueryData, h *plugin.Hydr

permissions, resp, err := client.PermissionsApi.GetPermissionsGroupExecute(request)

err = manageError("metabase_permission_group.getPermissionGroup", ctx, resp, err)

if err != nil {
plugin.Logger(ctx).Error("metabase_db.getPermissionGroup", err)
return nil, err
} else if resp.StatusCode >= 300 {
err = fmt.Errorf("HTTP code = %d", resp.StatusCode)
plugin.Logger(ctx).Error("metabase_db.getPermissionGroup", err)
return nil, err
}

Expand Down
Loading

0 comments on commit ed9429d

Please sign in to comment.