integration.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package cloudcost
  2. import (
  3. "time"
  4. "github.com/opencost/opencost/core/pkg/opencost"
  5. "github.com/opencost/opencost/pkg/cloud"
  6. "github.com/opencost/opencost/pkg/cloud/alibaba"
  7. "github.com/opencost/opencost/pkg/cloud/aws"
  8. "github.com/opencost/opencost/pkg/cloud/azure"
  9. "github.com/opencost/opencost/pkg/cloud/gcp"
  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) (*opencost.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: azure.StorageConnection{
  57. StorageConfiguration: keyedConfig.StorageConfiguration},
  58. },
  59. }
  60. case *azure.AzureStorageBillingParser:
  61. return &azure.AzureStorageIntegration{
  62. AzureStorageBillingParser: azure.AzureStorageBillingParser{
  63. StorageConnection: azure.StorageConnection{
  64. StorageConfiguration: keyedConfig.StorageConfiguration},
  65. },
  66. }
  67. case *azure.AzureStorageIntegration:
  68. return &azure.AzureStorageIntegration{
  69. AzureStorageBillingParser: azure.AzureStorageBillingParser{
  70. StorageConnection: azure.StorageConnection{
  71. StorageConfiguration: keyedConfig.StorageConfiguration},
  72. },
  73. }
  74. // S3SelectIntegration
  75. case *aws.S3Configuration:
  76. return &aws.S3SelectIntegration{
  77. S3SelectQuerier: aws.S3SelectQuerier{
  78. S3Connection: aws.S3Connection{
  79. S3Configuration: *keyedConfig,
  80. },
  81. },
  82. }
  83. case *aws.S3Connection:
  84. return &aws.S3SelectIntegration{
  85. S3SelectQuerier: aws.S3SelectQuerier{
  86. S3Connection: *keyedConfig,
  87. },
  88. }
  89. case *aws.S3SelectQuerier:
  90. return &aws.S3SelectIntegration{
  91. S3SelectQuerier: *keyedConfig,
  92. }
  93. case *aws.S3SelectIntegration:
  94. return keyedConfig
  95. // Alibaba BOA Integration
  96. case *alibaba.BOAConfiguration:
  97. return nil
  98. default:
  99. return nil
  100. }
  101. }