diff --git a/docs/tables/ovh_cloud_s3_storage.md b/docs/tables/ovh_cloud_s3_storage.md new file mode 100644 index 0000000..cdf1094 --- /dev/null +++ b/docs/tables/ovh_cloud_s3_storage.md @@ -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' +``` diff --git a/docs/tables/ovh_cloud_storage.md b/docs/tables/ovh_cloud_storage.md deleted file mode 100644 index 394edd4..0000000 --- a/docs/tables/ovh_cloud_storage.md +++ /dev/null @@ -1,32 +0,0 @@ -# Table: ovh_cloud_storage - -A storage is an object storage similar to S3. - -The `ovh_cloud_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 storage containers of a cloud project - -```sql -select - id, - name -from - ovh_cloud_storage -where - project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8' -``` - -## List empty storage containers - -```sql -select - id, - name -from - ovh_cloud_storage -where - project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8' - and stored_objects is null -``` diff --git a/docs/tables/ovh_cloud_swift_storage.md b/docs/tables/ovh_cloud_swift_storage.md new file mode 100644 index 0000000..34d935f --- /dev/null +++ b/docs/tables/ovh_cloud_swift_storage.md @@ -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 +``` diff --git a/ovh/plugin.go b/ovh/plugin.go index e7f18f2..523e1ca 100644 --- a/ovh/plugin.go +++ b/ovh/plugin.go @@ -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 diff --git a/ovh/table_ovh_cloud_s3_storage.go b/ovh/table_ovh_cloud_s3_storage.go new file mode 100644 index 0000000..848ea78 --- /dev/null +++ b/ovh/table_ovh_cloud_s3_storage.go @@ -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 +} diff --git a/ovh/table_ovh_cloud_storage.go b/ovh/table_ovh_cloud_swift_storage.go similarity index 68% rename from ovh/table_ovh_cloud_storage.go rename to ovh/table_ovh_cloud_swift_storage.go index cbf59b6..d07e6dd 100644 --- a/ovh/table_ovh_cloud_storage.go +++ b/ovh/table_ovh_cloud_swift_storage.go @@ -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{ { @@ -57,7 +57,7 @@ func tableOvhCloudStorage() *plugin.Table { } } -type StorageContainer struct { +type SwiftStorageContainer struct { ID string `json:"id"` Name string `json:"name"` StoredObjects int `json:"storedObjects"` @@ -65,17 +65,17 @@ type StorageContainer struct { 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 { @@ -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