2
0

integration.go 3.3 KB

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