Skip to content

Commit

Permalink
Merge branch 'jdenoy-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Apr 27, 2024
2 parents 44780c4 + 76b4008 commit 5e41659
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 62 deletions.
38 changes: 38 additions & 0 deletions docs/tables/ovh_cloud_s3_storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Table: ovh_cloud_s3_storage

An S3 storage is an S3 object storage.

The `ovh_cloud_s3_storage` table can be used to query information about storage containers and **you must specify which cloud project AND region** in the where clause (`where project_id=xxxx and region=xxxx`).

## Examples

### List S3 storage containers of a cloud project

```sql
select
name,
owner_id,
objects_count,
objects_size
from
ovh_cloud_s3_storage
where
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8'
and region='GRA'
```

## List specific storage container

```sql
select
name,
owner_id,
objects_count,
objects_size
from
ovh_cloud_s3_storage
where
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8'
and region='GRA'
and name='databucket'
```
32 changes: 0 additions & 32 deletions docs/tables/ovh_cloud_storage.md

This file was deleted.

32 changes: 32 additions & 0 deletions docs/tables/ovh_cloud_swift_storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Table: ovh_cloud_swift_storage

A Swift storage is an object storage.

The `ovh_cloud_swift_storage` table can be used to query information about storage containers and **you must specify which cloud project** in the where or join clause (`where project_id=`, `join ovh_cloud_project on id=`).

## Examples

### List swift storage containers of a cloud project

```sql
select
id,
name
from
ovh_cloud_swift_storage
where
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8'
```

## List empty swift storage containers

```sql
select
id,
name
from
ovh_cloud_swift_storage
where
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8'
and stored_objects is null
```
33 changes: 17 additions & 16 deletions ovh/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ func Plugin(ctx context.Context) *plugin.Plugin {
Schema: ConfigSchema,
},
TableMap: map[string]*plugin.Table{
"ovh_bill": tableOvhBill(),
"ovh_bill_detail": tableOvhBillDetails(),
"ovh_cloud_ai_app": tableOvhCloudAIApp(),
"ovh_cloud_ai_job": tableOvhCloudAIJob(),
"ovh_cloud_ai_notebook": tableOvhCloudAINotebook(),
"ovh_cloud_data_job": tableOvhCloudDataJob(),
"ovh_cloud_database": tableOvhCloudDatabase(),
"ovh_cloud_flavor": tableOvhCloudFlavor(),
"ovh_cloud_image": tableOvhCloudImage(),
"ovh_cloud_instance": tableOvhCloudInstance(),
"ovh_cloud_postgres": tableOvhCloudPostgres(),
"ovh_cloud_project": tableOvhCloudProject(),
"ovh_cloud_ssh_key": tableOvhCloudSshKey(),
"ovh_cloud_storage": tableOvhCloudStorage(),
"ovh_cloud_volume": tableOvhCloudVolume(),
"ovh_cloud_volume_snapshot": tableOvhCloudVolumeSnapshot(),
"ovh_bill": tableOvhBill(),
"ovh_bill_detail": tableOvhBillDetails(),
"ovh_cloud_ai_app": tableOvhCloudAIApp(),
"ovh_cloud_ai_job": tableOvhCloudAIJob(),
"ovh_cloud_ai_notebook": tableOvhCloudAINotebook(),
"ovh_cloud_data_job": tableOvhCloudDataJob(),
"ovh_cloud_database": tableOvhCloudDatabase(),
"ovh_cloud_flavor": tableOvhCloudFlavor(),
"ovh_cloud_image": tableOvhCloudImage(),
"ovh_cloud_instance": tableOvhCloudInstance(),
"ovh_cloud_postgres": tableOvhCloudPostgres(),
"ovh_cloud_project": tableOvhCloudProject(),
"ovh_cloud_s3_storage": tableOvhCloudS3Storage(),
"ovh_cloud_ssh_key": tableOvhCloudSshKey(),
"ovh_cloud_swift_storage": tableOvhCloudSwiftStorage(),
"ovh_cloud_volume": tableOvhCloudVolume(),
"ovh_cloud_volume_snapshot": tableOvhCloudVolumeSnapshot(),
},
}
return p
Expand Down
128 changes: 128 additions & 0 deletions ovh/table_ovh_cloud_s3_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package ovh

import (
"context"
"fmt"
"time"

"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func tableOvhCloudS3Storage() *plugin.Table {
return &plugin.Table{
Name: "ovh_cloud_s3_storage",
Description: "A S3 storage is an object storage.",
List: &plugin.ListConfig{
KeyColumns: plugin.AllColumns([]string{"project_id", "region"}),
Hydrate: listS3StorageContainer,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"project_id", "region", "name"}),
Hydrate: getS3StorageContainer,
},
Columns: []*plugin.Column{
{
Name: "project_id",
Type: proto.ColumnType_STRING,
Transform: transform.FromQual("project_id"),
Description: "Project ID.",
},
{
Name: "name",
Type: proto.ColumnType_STRING,
Description: "Container name.",
},
{
Name: "virtual_host",
Type: proto.ColumnType_STRING,
Description: "Container virtual host.",
},
{
Name: "owner_id",
Type: proto.ColumnType_INT,
Description: "Container owner userID.",
},
{
Name: "objects_count",
Type: proto.ColumnType_INT,
Description: "Container total objects count.",
},
{
Name: "objects_size",
Type: proto.ColumnType_INT,
Description: "Container total objects size (bytes).",
},
{
Name: "region",
Type: proto.ColumnType_STRING,
Description: "Region of the container.",
},
{
Name: "created_at",
Type: proto.ColumnType_TIMESTAMP,
Description: "The date and timestamp when the resource was created.",
},
{
Name: "encryption_sse_algorithm",
Type: proto.ColumnType_STRING,
Description: "Encryption configuration.",
Transform: transform.FromField("Encryption.SSEAlgorithm"),
},
},
}
}

type S3StorageContainer struct {
Name string `json:"name"`
VirtualHost string `json:"virtualHost"`
OwnerID int `json:"ownerId"`
ObjectsCount int `json:"objectsCount"`
ObjectsSize int `json:"objectsSize"`
Region string `json:"region"`
CreatedAt time.Time `json:"createdAt"`
Encryption S3StorageContainerEncryption `json:"encryption"`
}
type S3StorageContainerEncryption struct {
SSEAlgorithm string `json:"sseAlgorithm"`
}

func listS3StorageContainer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_s3_storage.listS3StorageContainer", "connection_error", err)
return nil, err
}
projectId := d.EqualsQuals["project_id"].GetStringValue()
region := d.EqualsQuals["region"].GetStringValue()

var containers []S3StorageContainer
err = client.Get(fmt.Sprintf("/cloud/project/%s/region/%s/storage", projectId, region), &containers)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_s3_storage.listS3StorageContainer", err)
return nil, err
}
for _, container := range containers {
d.StreamListItem(ctx, container)
}
return nil, nil
}

func getS3StorageContainer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_s3_storage.getS3StorageContainer", "connection_error", err)
return nil, err
}
projectId := d.EqualsQuals["project_id"].GetStringValue()
region := d.EqualsQuals["region"].GetStringValue()
name := d.EqualsQuals["name"].GetStringValue()
var container S3StorageContainer
err = client.Get(fmt.Sprintf("/cloud/project/%s/region/%s/storage/%s", projectId, region, name), &container)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_s3_storage.getS3StorageContainer", err)
return nil, err
}
return container, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func tableOvhCloudStorage() *plugin.Table {
func tableOvhCloudSwiftStorage() *plugin.Table {
return &plugin.Table{
Name: "ovh_cloud_storage",
Description: "A storage is an object storage similar to S3.",
Name: "ovh_cloud_swift_storage",
Description: "A Swift storage is an object storage similar to S3.",
List: &plugin.ListConfig{
KeyColumns: plugin.SingleColumn("project_id"),
Hydrate: listStorageContainer,
Hydrate: listSwiftStorageContainer,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"project_id", "id"}),
Hydrate: getStorageContainer,
Hydrate: getSwiftStorageContainer,
},
Columns: []*plugin.Column{
{
Expand Down Expand Up @@ -57,25 +57,25 @@ func tableOvhCloudStorage() *plugin.Table {
}
}

type StorageContainer struct {
type SwiftStorageContainer struct {
ID string `json:"id"`
Name string `json:"name"`
StoredObjects int `json:"storedObjects"`
StoredBytes int `json:"storedBytes"`
Region string `json:"region"`
}

func listStorageContainer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
func listSwiftStorageContainer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_storage.listStorageContainer", "connection_error", err)
plugin.Logger(ctx).Error("ovh_cloud_swift_storage.listSwiftStorageContainer", "connection_error", err)
return nil, err
}
projectId := d.EqualsQuals["project_id"].GetStringValue()
var containers []StorageContainer
var containers []SwiftStorageContainer
err = client.Get(fmt.Sprintf("/cloud/project/%s/storage", projectId), &containers)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_storage.listStorageContainer", err)
plugin.Logger(ctx).Error("ovh_cloud_swift_storage.listSwiftStorageContainer", err)
return nil, err
}
for _, container := range containers {
Expand All @@ -84,18 +84,18 @@ func listStorageContainer(ctx context.Context, d *plugin.QueryData, _ *plugin.Hy
return nil, nil
}

func getStorageContainer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
func getSwiftStorageContainer(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_storage.getStorageContainer", "connection_error", err)
plugin.Logger(ctx).Error("ovh_cloud_swift_storage.getSwiftStorageContainer", "connection_error", err)
return nil, err
}
projectId := d.EqualsQuals["project_id"].GetStringValue()
id := d.EqualsQuals["id"].GetStringValue()
var container StorageContainer
var container SwiftStorageContainer
err = client.Get(fmt.Sprintf("/cloud/project/%s/storage/%s", projectId, id), &container)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_storage.getStorageContainer", err)
plugin.Logger(ctx).Error("ovh_cloud_swift_storage.getSwiftStorageContainer", err)
return nil, err
}
container.ID = id
Expand Down

0 comments on commit 5e41659

Please sign in to comment.