2
0

integration.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package cloudcost
  2. import (
  3. "time"
  4. "github.com/opencost/opencost/pkg/cloud"
  5. "github.com/opencost/opencost/pkg/cloud/alibaba"
  6. "github.com/opencost/opencost/pkg/cloud/aws"
  7. "github.com/opencost/opencost/pkg/cloud/azure"
  8. "github.com/opencost/opencost/pkg/cloud/gcp"
  9. "github.com/opencost/opencost/pkg/kubecost"
  10. )
  11. // CloudCostIntegration is an interface for retrieving daily granularity CloudCost data for a given range
  12. type CloudCostIntegration interface {
  13. GetCloudCost(time.Time, time.Time) (*kubecost.CloudCostSetRange, error)
  14. GetStatus() cloud.ConnectionStatus
  15. }
  16. // GetIntegrationFromConfig coverts any valid KeyedConfig into the appropriate BillingIntegration if possible
  17. func GetIntegrationFromConfig(kc cloud.KeyedConfig) CloudCostIntegration {
  18. switch keyedConfig := kc.(type) {
  19. // AthenaIntegration
  20. case *aws.AthenaConfiguration:
  21. return &aws.AthenaIntegration{
  22. AthenaQuerier: aws.AthenaQuerier{
  23. AthenaConfiguration: *keyedConfig,
  24. },
  25. }
  26. case *aws.AthenaQuerier:
  27. return &aws.AthenaIntegration{
  28. AthenaQuerier: *keyedConfig,
  29. }
  30. case *aws.AthenaIntegration:
  31. return keyedConfig
  32. // BigQueryIntegration
  33. case *gcp.BigQueryConfiguration:
  34. return &gcp.BigQueryIntegration{
  35. BigQueryQuerier: gcp.BigQueryQuerier{
  36. BigQueryConfiguration: *keyedConfig,
  37. },
  38. }
  39. case *gcp.BigQueryQuerier:
  40. return &gcp.BigQueryIntegration{
  41. BigQueryQuerier: *keyedConfig,
  42. }
  43. case *gcp.BigQueryIntegration:
  44. return keyedConfig
  45. // AzureStorageIntegration
  46. case *azure.StorageConfiguration:
  47. return &azure.AzureStorageIntegration{
  48. AzureStorageBillingParser: azure.AzureStorageBillingParser{
  49. StorageConnection: azure.StorageConnection{
  50. StorageConfiguration: *keyedConfig},
  51. },
  52. }
  53. case *azure.StorageConnection:
  54. return &azure.AzureStorageIntegration{
  55. AzureStorageBillingParser: azure.AzureStorageBillingParser{
  56. StorageConnection: *keyedConfig,
  57. },
  58. }
  59. case *azure.AzureStorageBillingParser:
  60. return &azure.AzureStorageIntegration{
  61. AzureStorageBillingParser: *keyedConfig,
  62. }
  63. case *azure.AzureStorageIntegration:
  64. return keyedConfig
  65. // S3SelectIntegration
  66. case *aws.S3Configuration:
  67. return &aws.S3SelectIntegration{
  68. S3SelectQuerier: aws.S3SelectQuerier{
  69. S3Connection: aws.S3Connection{
  70. S3Configuration: *keyedConfig,
  71. },
  72. },
  73. }
  74. case *aws.S3Connection:
  75. return &aws.S3SelectIntegration{
  76. S3SelectQuerier: aws.S3SelectQuerier{
  77. S3Connection: *keyedConfig,
  78. },
  79. }
  80. case *aws.S3SelectQuerier:
  81. return &aws.S3SelectIntegration{
  82. S3SelectQuerier: *keyedConfig,
  83. }
  84. case *aws.S3SelectIntegration:
  85. return keyedConfig
  86. // Alibaba BOA Integration
  87. case *alibaba.BOAConfiguration:
  88. return nil
  89. default:
  90. return nil
  91. }
  92. }