Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Invoices table #122

Merged
merged 1 commit into from
Nov 25, 2024
Merged

add Invoices table #122

merged 1 commit into from
Nov 25, 2024

Conversation

tdannenmuller
Copy link
Contributor

I've added support for a new table named invoices. This table recover the data form : https://www.scaleway.com/en/developers/api/billing/#path-invoices-list-invoices using scaleway-sdk-go/api/billing

I'm not a go developer, so I've intensively used AI to generate the table code. I've tried my best to conform to coding convention and styling of the project.

The table have been extensively tested, and the documentation reflects that.

I humbly hope this contribution is decent enough to be integrated.

@misraved misraved self-requested a review November 4, 2024 11:51
@misraved misraved assigned misraved and tdannenmuller and unassigned misraved Nov 6, 2024
@tdannenmuller
Copy link
Contributor Author

@misraved why did you assigned me the PR ?

Maybe you have "forgot" the corresponding comment ?

Copy link
Contributor

@ParthaI ParthaI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tdannenmuller, I’ve shared some initial review comments—please take a look. Thank you!

Additionally, here are a few key points to address:

  • Update the table name to scaleway_billing_invoice and make corresponding updates to the function name and file name.
  • Remove any unnecessary log statements.(Typically, we avoid including Debug or Warn statements unless they are absolutely necessary.)

}
}

func extractAmount(ctx context.Context, d *transform.TransformData) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please rearrange the functions in the following order?

  • List Function
  • Get Function
  • Other hydrate Function
  • Transform Function
  • Utility Function

For reference: https://github.com/turbot/steampipe-plugin-aws/blob/main/aws/table_aws_acm_certificate.go

}

func extractAmount(ctx context.Context, d *transform.TransformData) (interface{}, error) {
plugin.Logger(ctx).Debug("extractAmount", "field", d.ColumnName, "raw_value", d.Value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
plugin.Logger(ctx).Debug("extractAmount", "field", d.ColumnName, "raw_value", d.Value)

plugin.Logger(ctx).Debug("extractAmount", "field", d.ColumnName, "raw_value", d.Value)

if d.Value == nil {
plugin.Logger(ctx).Warn("extractAmount: nil value", "field", d.ColumnName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
plugin.Logger(ctx).Warn("extractAmount: nil value", "field", d.ColumnName)

}

for _, invoices := range resp.Invoices {
plugin.Logger(ctx).Debug("raw invoices data", "invoices", fmt.Sprintf("%+v", invoices))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
plugin.Logger(ctx).Debug("raw invoices data", "invoices", fmt.Sprintf("%+v", invoices))

}

// Make the API request to list invoices
resp, err := billingAPI.ListInvoices(req)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add support for API pagination for this API?

According to the API documentation, the ListInvoices API supports pagination. For implementing this feature, you may refer to the implementation in the scaleway_account_project table.

Name: "seller_name",
Type: proto.ColumnType_STRING,
Description: "The name of the seller.",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please include the Scaleway standard columns and Steampipe standard columns in this table to maintain consistency across all tables?

organizationID = *scalewayConfig.OrganizationID
}

// Check if organization_id is specified in the query
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check if organization_id is specified in the query
// Check if organization_id is specified in the query parameter


// Log a warning if organization_id is not provided by either config or query
if organizationID == "" {
plugin.Logger(ctx).Warn("scaleway_invoices.listScalewayInvoices", "warning", "No organization_id provided in config or query")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more appropriate to return an error instead of just a warning message in this scenario.

Could you please clarify how the API behaves when the Organization ID is not provided?
Does it default to returning results for the current Organization associated with the provided access key and secret key?

If the API does not return an error in such cases, I kindly suggest removing this block of code for simplicity and consistency with the API behavior.

KeyColumns: []*plugin.KeyColumn{
{Name: "organization_id", Require: plugin.Optional},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly include the Get Config as well, allowing users to retrieve details for a single invoice. This addition could help optimize query performance and improve efficiency.

}
}

type invoicesItem struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to define this structure explicitly?

@ParthaI ParthaI changed the base branch from main to add-table-invoice November 25, 2024 10:56
@ParthaI ParthaI merged commit fd92492 into turbot:add-table-invoice Nov 25, 2024
1 check passed
@tdannenmuller
Copy link
Contributor Author

Hello, I'm a bit confused. I thought you were waiting for the changes to merge.

For the record, I've started to implement you're comments, but i've not finished yet. I have several questions / remarks concerning them, but it is still a work in progress. I'll try to take some time soon to do so.

How should we proceed in order to bring those future changes to the main repo ?

Thx.

@ParthaI
Copy link
Contributor

ParthaI commented Nov 25, 2024

Apologies for any confusion, @tdannenmuller. Since we hadn’t heard from you in a while and the overall changes in the PR looked great, we went ahead and merged it into a branch. I’ve also made some cleanup changes and raised a follow-up PR (#123) with main as the base branch. You can review the updated changes there.

Please feel free to continue adding your updates to the add-table-invoice branch within the new PR. Let me know if you have any questions or if there’s anything else I can assist with!

Thanks!

misraved added a commit that referenced this pull request Nov 25, 2024

Co-authored-by: tdannenmuller <114987187+tdannenmuller@users.noreply.github.com>
Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants