-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed func tableOvhCloudStorage() to func tableOvhCloudSwiftStorage…
…() and added func tableOvhCloudS3Storage() that are two different OVH API path
- Loading branch information
Showing
6 changed files
with
225 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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' | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 similar to S3. | ||
|
||
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 storage containers of a cloud project | ||
|
||
```sql | ||
select | ||
id, | ||
name | ||
from | ||
ovh_cloud_swift_storage | ||
where | ||
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8' | ||
``` | ||
|
||
## List empty storage containers | ||
|
||
```sql | ||
select | ||
id, | ||
name | ||
from | ||
ovh_cloud_swift_storage | ||
where | ||
project_id='27c5a6d3dfez87893jfd88fdsfmvnqb8' | ||
and stored_objects is null | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
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.", | ||
Transform: transform.FromField("OwnerId"), | ||
}, | ||
{ | ||
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.", | ||
Transform: transform.FromField("Created_Date"), | ||
}, | ||
{ | ||
Name: "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"` | ||
Created_Date 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 | ||
} | ||
//container.ID = id | ||
return container, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters