billing.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package billing
  2. import (
  3. "fmt"
  4. "github.com/porter-dev/porter/internal/models"
  5. )
  6. // BillingManager contains methods for managing billing for a project
  7. type BillingManager interface {
  8. // CreateTeam creates the concept of a billing "team". This is currently a one-to-one
  9. // mapping with projects, but this may change in the future (i.e. multiple projects
  10. // per same team)
  11. CreateTeam(user *models.User, proj *models.Project) (teamID string, err error)
  12. // DeleteTeam deletes a billing team.
  13. DeleteTeam(user *models.User, proj *models.Project) (err error)
  14. // ParseProjectUsageFromWebhook parses the project usage from a webhook payload sent
  15. // from a billing agent
  16. ParseProjectUsageFromWebhook(payload []byte) (*models.ProjectUsage, error)
  17. // VerifySignature verifies the signature for a webhook
  18. VerifySignature(signature string, body []byte) bool
  19. }
  20. // NoopBillingManager performs no billing operations
  21. type NoopBillingManager struct{}
  22. func (n *NoopBillingManager) CreateTeam(user *models.User, proj *models.Project) (teamID string, err error) {
  23. return fmt.Sprintf("%d", proj.ID), nil
  24. }
  25. func (n *NoopBillingManager) DeleteTeam(user *models.User, proj *models.Project) (err error) {
  26. return nil
  27. }
  28. func (n *NoopBillingManager) ParseProjectUsageFromWebhook(payload []byte) (*models.ProjectUsage, error) {
  29. return nil, nil
  30. }
  31. func (n *NoopBillingManager) VerifySignature(signature string, body []byte) bool {
  32. return false
  33. }