2
0

integration.go 3.2 KB

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