-
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.
Add ovh_refund and ovh_refund_detail tables
- Loading branch information
1 parent
0959ff8
commit 3f58663
Showing
5 changed files
with
369 additions
and
0 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,33 @@ | ||
# Table: ovh_refund | ||
|
||
List of all the refunds of your account. | ||
|
||
The `ovh_refund` table can be used to query information about your refund information. | ||
|
||
## Examples | ||
|
||
### List refunds | ||
|
||
```sql | ||
select | ||
id, | ||
date, | ||
original_bill_id, | ||
price_with_tax | ||
from | ||
ovh_refund; | ||
``` | ||
|
||
### Get a refund | ||
|
||
```sql | ||
select | ||
id, | ||
date, | ||
original_bill_id, | ||
price_with_tax | ||
from | ||
ovh_refund | ||
where | ||
id = 'AFRxxxxxxx'; | ||
``` |
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,30 @@ | ||
# Table: ovh_refund_detail | ||
|
||
Details of the refund of your account. | ||
|
||
The `ovh_refund_detail` table can be used to query information about your refund information. | ||
|
||
## Examples | ||
|
||
### List details of one refund | ||
|
||
```sql | ||
select | ||
* | ||
from | ||
ovh_refund_detail | ||
where | ||
refund_id = 'AFRxxxxxxx'; | ||
``` | ||
|
||
### Get detail of one refund | ||
|
||
```sql | ||
select | ||
* | ||
from | ||
ovh_refund_detail | ||
where | ||
refund_id = 'AFRxxxxxxxx' | ||
and id = 'AFRxxxxxxxx'; | ||
``` |
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,159 @@ | ||
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" | ||
) | ||
|
||
type Refund struct { | ||
ID string `json:"refundId"` | ||
Date time.Time `json:"date"` | ||
Url string `json:"url"` | ||
PdfUrl string `json:"pdfUrl"` | ||
OrderId int `json:"orderId"` | ||
OriginalBillId string `json:"originalBillId"` | ||
Password string `json:"password"` | ||
PriceWithTax Price `json:"priceWithTax"` | ||
PriceWithoutTax Price `json:"priceWithoutTax"` | ||
Tax Price `json:"tax"` | ||
} | ||
|
||
func tableOvhRefund() *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "ovh_refund", | ||
Description: "Refunds of your account.", | ||
List: &plugin.ListConfig{ | ||
Hydrate: listRefund, | ||
}, | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.AllColumns([]string{"id"}), | ||
Hydrate: getRefund, | ||
}, | ||
HydrateConfig: []plugin.HydrateConfig{ | ||
{Func: getRefundInfo}, | ||
}, | ||
Columns: []*plugin.Column{ | ||
{ | ||
Name: "id", | ||
Type: proto.ColumnType_STRING, | ||
Description: "ID of the refund.", | ||
}, | ||
{ | ||
Name: "date", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_TIMESTAMP, | ||
Description: "Date of the refund.", | ||
}, | ||
{ | ||
Name: "url", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("Url"), | ||
Description: "URL to download the refund document.", | ||
}, | ||
{ | ||
Name: "pdf_url", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("PdfUrl"), | ||
Description: "URL to download the refund document in PDF format (maybe same as url field).", | ||
}, | ||
{ | ||
Name: "order_id", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_INT, | ||
Transform: transform.FromField("OrderId"), | ||
Description: "Order id.", | ||
}, | ||
{ | ||
Name: "original_bill_id", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("OriginalBillId"), | ||
Description: "Original Bill id.", | ||
}, | ||
{ | ||
Name: "password", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_STRING, | ||
Description: "Password to download the refund document.", | ||
}, | ||
{ | ||
Name: "price_with_tax", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_DOUBLE, | ||
Transform: transform.FromField("PriceWithTax.Value"), | ||
Description: "Price with tax.", | ||
}, | ||
{ | ||
Name: "price_without_tax", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_DOUBLE, | ||
Transform: transform.FromField("PriceWithoutTax.Value"), | ||
Description: "Price without tax.", | ||
}, | ||
{ | ||
Name: "tax", | ||
Hydrate: getRefundInfo, | ||
Type: proto.ColumnType_DOUBLE, | ||
Transform: transform.FromField("Tax.Value"), | ||
Description: "Amount of the tax.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func getRefundInfo(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
refund := h.Item.(Refund) | ||
|
||
client, err := connect(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_refund.getRefundInfo", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
err = client.Get(fmt.Sprintf("/me/refund/%s", refund.ID), &refund) | ||
|
||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_bill.getRefundInfo", err) | ||
return nil, err | ||
} | ||
|
||
return refund, nil | ||
} | ||
|
||
func listRefund(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
client, err := connect(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_refund.listRefund", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
var refundsId []string | ||
err = client.Get("/me/refund", &refundsId) | ||
|
||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_refund.listRefund", err) | ||
return nil, err | ||
} | ||
|
||
for _, refundId := range refundsId { | ||
var refund Refund | ||
refund.ID = refundId | ||
d.StreamListItem(ctx, refund) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func getRefund(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
id := d.Quals.ToEqualsQualValueMap()["id"].GetStringValue() | ||
var refund Refund | ||
refund.ID = id | ||
return refund, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package ovh | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"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" | ||
) | ||
|
||
type RefundPrice struct { | ||
Value float64 `json:"value"` | ||
CurrencyCode string `json:"currencyCode"` | ||
} | ||
type RefundDetail struct { | ||
ID string `json:"refundDetailId"` | ||
RefundID string `json:"refundId"` | ||
Description string `json:"description"` | ||
Domain string `json:"domain"` | ||
Quantity string `json:"quantity"` | ||
TotalPrice RefundPrice `json:"totalPrice"` | ||
UnitPrice RefundPrice `json:"unitPrice"` | ||
} | ||
|
||
func tableOvhRefundDetails() *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "ovh_refund_detail", | ||
Description: "Detail of a refund.", | ||
List: &plugin.ListConfig{ | ||
KeyColumns: plugin.AllColumns([]string{"refund_id"}), | ||
Hydrate: listRefundDetails, | ||
}, | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.AllColumns([]string{"refund_id", "id"}), | ||
Hydrate: getRefundDetail, | ||
}, | ||
Columns: []*plugin.Column{ | ||
{ | ||
Name: "id", | ||
Type: proto.ColumnType_STRING, | ||
Description: "ID of detail's refund.", | ||
}, | ||
{ | ||
Name: "refund_id", | ||
Transform: transform.FromQual("refund_id"), | ||
Type: proto.ColumnType_STRING, | ||
Description: "ID of refund detail.", | ||
}, | ||
{ | ||
Name: "description", | ||
Hydrate: getGetRefundDetailInfo, | ||
Type: proto.ColumnType_STRING, | ||
Description: "Description of detail.", | ||
}, | ||
{ | ||
Name: "domain", | ||
Hydrate: getGetRefundDetailInfo, | ||
Type: proto.ColumnType_STRING, | ||
Description: "Domain.", | ||
}, | ||
{ | ||
Name: "quantity", | ||
Hydrate: getGetRefundDetailInfo, | ||
Type: proto.ColumnType_STRING, | ||
Description: "Quantity of detail.", | ||
}, | ||
{ | ||
Name: "total_price", | ||
Hydrate: getGetRefundDetailInfo, | ||
Type: proto.ColumnType_DOUBLE, | ||
Transform: transform.FromField("TotalPrice.Value"), | ||
Description: "Total price of this detail.", | ||
}, | ||
{ | ||
Name: "unit_price", | ||
Hydrate: getGetRefundDetailInfo, | ||
Type: proto.ColumnType_DOUBLE, | ||
Transform: transform.FromField("UnitPrice.Value"), | ||
Description: "Unit price of this detail.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// This function populate data of refund detail | ||
func getGetRefundDetailInfo(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
refundDetail := h.Item.(RefundDetail) | ||
|
||
client, err := connect(ctx, d) | ||
|
||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_refund_detail.getGetBillDetailInfo", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
err = client.Get(fmt.Sprintf("/me/refund/%s/details/%s", refundDetail.RefundID, refundDetail.ID), &refundDetail) | ||
|
||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_refund_detail.getGetBillDetailInfo", err) | ||
return nil, err | ||
} | ||
|
||
return refundDetail, nil | ||
} | ||
|
||
func listRefundDetails(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
client, err := connect(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_refund_detail.listRefundDetails", "connection_error", err) | ||
return nil, err | ||
} | ||
|
||
refundId := d.EqualsQuals["refund_id"].GetStringValue() | ||
|
||
// First, we get IDs of refund | ||
var refundDetailsId []string | ||
err = client.Get(fmt.Sprintf("/me/refund/%s/details", refundId), &refundDetailsId) | ||
|
||
if err != nil { | ||
plugin.Logger(ctx).Error("ovh_refund_detail.listRefundDetails", err) | ||
return nil, err | ||
} | ||
|
||
for _, id := range refundDetailsId { | ||
d.StreamListItem(ctx, RefundDetail{ | ||
ID: id, | ||
RefundID: refundId, | ||
}) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func getRefundDetail(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
refundId := d.EqualsQuals["refund_id"].GetStringValue() | ||
id := d.EqualsQuals["id"].GetStringValue() | ||
|
||
h.Item = RefundDetail{ | ||
ID: id, | ||
RefundID: refundId, | ||
} | ||
|
||
return getGetRefundDetailInfo(ctx, d, h) | ||
} |