Просмотр исходного кода

Remove opencost dependency

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb 17 часов назад
Родитель
Сommit
a3f4eca025

+ 1 - 1
modules/pricing/public/aws/pricelistapi.go

@@ -8,7 +8,7 @@ import (
 
 
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/log"
 	"github.com/opencost/opencost/core/pkg/util/json"
 	"github.com/opencost/opencost/core/pkg/util/json"
-	"github.com/opencost/opencost/pkg/env"
+	"github.com/opencost/opencost/modules/pricing/public/env"
 )
 )
 
 
 const (
 const (

+ 5 - 5
modules/pricing/public/aws/pricelistapi_test.go

@@ -3,12 +3,12 @@ package aws
 import (
 import (
 	"testing"
 	"testing"
 
 
-	"github.com/opencost/opencost/pkg/env"
+	"github.com/opencost/opencost/modules/pricing/public/env"
 )
 )
 
 
 func TestGetListPriceURL(t *testing.T) {
 func TestGetListPriceURL(t *testing.T) {
 	t.Run("uses override when configured", func(t *testing.T) {
 	t.Run("uses override when configured", func(t *testing.T) {
-		t.Setenv(env.AWSPricingURL, "https://example.com/custom.json")
+		t.Setenv(env.AWSPricingURLEnvVar, "https://example.com/custom.json")
 
 
 		got := getListPriceURL("AmazonEC2", "us-east-1")
 		got := getListPriceURL("AmazonEC2", "us-east-1")
 
 
@@ -18,7 +18,7 @@ func TestGetListPriceURL(t *testing.T) {
 	})
 	})
 
 
 	t.Run("builds standard regional URL", func(t *testing.T) {
 	t.Run("builds standard regional URL", func(t *testing.T) {
-		t.Setenv(env.AWSPricingURL, "")
+		t.Setenv(env.AWSPricingURLEnvVar, "")
 
 
 		got := getListPriceURL("AmazonEC2", "us-west-2")
 		got := getListPriceURL("AmazonEC2", "us-west-2")
 		want := "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/us-west-2/index.json"
 		want := "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/us-west-2/index.json"
@@ -29,7 +29,7 @@ func TestGetListPriceURL(t *testing.T) {
 	})
 	})
 
 
 	t.Run("builds standard global URL when region empty", func(t *testing.T) {
 	t.Run("builds standard global URL when region empty", func(t *testing.T) {
-		t.Setenv(env.AWSPricingURL, "")
+		t.Setenv(env.AWSPricingURLEnvVar, "")
 
 
 		got := getListPriceURL("AmazonEC2", "")
 		got := getListPriceURL("AmazonEC2", "")
 		want := "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json"
 		want := "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json"
@@ -40,7 +40,7 @@ func TestGetListPriceURL(t *testing.T) {
 	})
 	})
 
 
 	t.Run("uses china endpoint for china regions", func(t *testing.T) {
 	t.Run("uses china endpoint for china regions", func(t *testing.T) {
-		t.Setenv(env.AWSPricingURL, "")
+		t.Setenv(env.AWSPricingURLEnvVar, "")
 
 
 		got := getListPriceURL("AmazonEC2", "cn-north-1")
 		got := getListPriceURL("AmazonEC2", "cn-north-1")
 		want := "https://pricing.cn-north-1.amazonaws.com.cn/offers/v1.0/cn/AmazonEC2/current/cn-north-1/index.json"
 		want := "https://pricing.cn-north-1.amazonaws.com.cn/offers/v1.0/cn/AmazonEC2/current/cn-north-1/index.json"

+ 14 - 0
modules/pricing/public/env/env.go

@@ -0,0 +1,14 @@
+package env
+
+import (
+	"github.com/opencost/opencost/core/pkg/env"
+)
+
+const (
+	AWSPricingURLEnvVar = "AWS_PRICING_URL"
+)
+
+// GetAWSPricingURL returns an optional alternative URL to fetch AWS pricing data from; for use in airgapped environments
+func GetAWSPricingURL() string {
+	return env.Get(AWSPricingURLEnvVar, "")
+}

+ 0 - 1
modules/pricing/public/go.mod

@@ -5,7 +5,6 @@ replace github.com/opencost/opencost/core => ../../../core
 require github.com/opencost/opencost/core v0.0.0 // return to v1.120.2-0.20260514205745-aa41c03dc67a
 require github.com/opencost/opencost/core v0.0.0 // return to v1.120.2-0.20260514205745-aa41c03dc67a
 
 
 require (
 require (
-	github.com/opencost/opencost v1.120.3
 	github.com/spf13/cobra v1.10.2
 	github.com/spf13/cobra v1.10.2
 )
 )