integration.go 3.6 KB

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