Skip to content

Commit

Permalink
Deprecated pricer API v3 removed
Browse files Browse the repository at this point in the history
  • Loading branch information
tzununbekov committed Feb 29, 2024
1 parent a56b68e commit 37f947f
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 1,342 deletions.
9 changes: 1 addition & 8 deletions cmd/pricer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
_ "github.com/mysteriumnetwork/discovery/docs"
"github.com/mysteriumnetwork/discovery/middleware"
"github.com/mysteriumnetwork/discovery/price"
"github.com/mysteriumnetwork/discovery/price/pricing"
"github.com/mysteriumnetwork/discovery/price/pricingbyservice"
"github.com/mysteriumnetwork/go-rest/apierror"
mlog "github.com/mysteriumnetwork/logger"
Expand Down Expand Up @@ -58,10 +57,9 @@ func main() {
log.Fatal().Err(err).Msg("could not reach redis")
}

v3 := r.Group("/api/v3")
v4 := r.Group("/api/v4")

cfger := pricing.NewConfigProviderDB(rdb)
cfger := pricingbyservice.NewConfigProviderDB(rdb)

_, err = cfger.Get()
if err != nil {
Expand All @@ -74,17 +72,12 @@ func main() {
log.Fatal().Err(err).Msg("Failed to load cfg by service")
}

getter, err := pricing.NewPriceGetter(rdb)
if err != nil {
log.Fatal().Err(err).Msg("failed to initialize price getter")
}
getterByService, err := pricingbyservice.NewPriceGetter(rdb)
if err != nil {
log.Fatal().Err(err).Msg("failed to initialize price getter by service")
}

ac := middleware.NewJWTChecker(cfg.SentinelURL, cfg.UniverseJWTSecret)
price.NewAPI(getter, cfger, ac).RegisterRoutes(v3)
price.NewAPIByService(rdb, getterByService, cfgerByService, ac).RegisterRoutes(v4)

if err := r.Run(); err != nil {
Expand Down
Binary file removed docs/architecture.png
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ var doc = `{
},
"/proposals": {
"get": {
"description": "List proposals",
"description": "List all proposals for internal use",
"consumes": [
"application/json"
],
"tags": [
"proposals"
],
"summary": "List proposals",
"summary": "List all proposals for internal use",
"parameters": [
{
"type": "string",
Expand Down
Binary file removed docs/service_blocks.png
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@
},
"/proposals": {
"get": {
"description": "List proposals",
"description": "List all proposals for internal use",
"consumes": [
"application/json"
],
"tags": [
"proposals"
],
"summary": "List proposals",
"summary": "List all proposals for internal use",
"parameters": [
{
"type": "string",
Expand Down
4 changes: 2 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ paths:
get:
consumes:
- application/json
description: List proposals
description: List all proposals for internal use
parameters:
- description: Consumer country
in: query
Expand Down Expand Up @@ -236,7 +236,7 @@ paths:
items:
$ref: '#/definitions/v3.Proposal'
type: array
summary: List proposals
summary: List all proposals for internal use
tags:
- proposals
/proposals-metadata:
Expand Down
14 changes: 7 additions & 7 deletions e2e/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/dghubble/sling"

"github.com/mysteriumnetwork/discovery/health"
"github.com/mysteriumnetwork/discovery/price/pricing"
"github.com/mysteriumnetwork/discovery/price/pricingbyservice"
v3 "github.com/mysteriumnetwork/discovery/proposal/v3"
)

Expand Down Expand Up @@ -62,21 +62,21 @@ type pricerAPI struct {
basePath string
}

func (a *pricerAPI) LatestPrices() (latestPrices pricing.LatestPrices, err error) {
_, err = sling.New().Base(a.basePath).Get("/api/v3/prices").Receive(&latestPrices, nil)
func (a *pricerAPI) LatestPrices() (latestPrices pricingbyservice.LatestPrices, err error) {
_, err = sling.New().Base(a.basePath).Get("/api/v4/prices").Receive(&latestPrices, nil)
return latestPrices, err
}

func (a *pricerAPI) GetPriceConfig(token string) (config pricing.Config, err error) {
resp, err := sling.New().Base(a.basePath).Add("Authorization", "Bearer "+token).Get("/api/v3/prices/config").Receive(&config, nil)
func (a *pricerAPI) GetPriceConfig(token string) (config pricingbyservice.Config, err error) {
resp, err := sling.New().Base(a.basePath).Add("Authorization", "Bearer "+token).Get("/api/v4/prices/config").Receive(&config, nil)
if resp.StatusCode == 401 {
return config, errors.New(fmt.Sprint(resp.StatusCode))
}
return config, err
}

func (a *pricerAPI) UpdatePriceConfig(token string, cfg pricing.Config) (err error) {
resp, err := sling.New().Base(a.basePath).Add("Authorization", "Bearer "+token).BodyJSON(&cfg).Post("/api/v3/prices/config").Receive(nil, nil)
func (a *pricerAPI) UpdatePriceConfig(token string, cfg pricingbyservice.Config) (err error) {
resp, err := sling.New().Base(a.basePath).Add("Authorization", "Bearer "+token).BodyJSON(&cfg).Post("/api/v4/prices/config").Receive(nil, nil)
if resp.StatusCode == 401 || resp.StatusCode == 400 {
return errors.New(fmt.Sprint(resp.StatusCode))
}
Expand Down
51 changes: 38 additions & 13 deletions e2e/price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/mysteriumnetwork/discovery/price/pricing"
"github.com/mysteriumnetwork/discovery/price/pricingbyservice"
"github.com/stretchr/testify/assert"
)

Expand All @@ -31,14 +31,39 @@ func TestMain(m *testing.M) {
func Test_LatestPrices(t *testing.T) {
prices, err := PricerAPI.LatestPrices()
assert.NoError(t, err)
assert.NotNil(t, prices.Defaults.Current.Residential.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Residential.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Other.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Other.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Residential.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Residential.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Other.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Other.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Residential.DVPN.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Residential.DVPN.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Residential.Scraping.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Residential.Scraping.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Residential.Wireguard.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Residential.Wireguard.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Residential.DataTransfer.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Residential.DataTransfer.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Other.DVPN.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Other.DVPN.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Other.Scraping.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Other.Scraping.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Other.Wireguard.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Other.Wireguard.PricePerHour)
assert.NotNil(t, prices.Defaults.Current.Other.DataTransfer.PricePerGiB)
assert.NotNil(t, prices.Defaults.Current.Other.DataTransfer.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Residential.DVPN.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Residential.DVPN.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Residential.Scraping.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Residential.Scraping.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Residential.Wireguard.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Residential.Wireguard.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Residential.DataTransfer.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Residential.DataTransfer.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Other.DVPN.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Other.DVPN.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Other.Scraping.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Other.Scraping.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Other.Wireguard.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Other.Wireguard.PricePerHour)
assert.NotNil(t, prices.Defaults.Previous.Other.DataTransfer.PricePerGiB)
assert.NotNil(t, prices.Defaults.Previous.Other.DataTransfer.PricePerHour)

assert.Greater(t, prices.CurrentValidUntil.UnixNano(), time.Unix(0, 0).UnixNano())
assert.Greater(t, prices.PreviousValidUntil.UnixNano(), time.Unix(0, 0).UnixNano())
assert.Greater(t, prices.CurrentServerTime.UnixNano(), time.Unix(0, 0).UnixNano())
Expand All @@ -64,22 +89,22 @@ func Test_GetConfig(t *testing.T) {

func Test_PostConfig(t *testing.T) {
t.Run("rejected with bad token", func(t *testing.T) {
err := PricerAPI.UpdatePriceConfig("tkn", pricing.Config{})
err := PricerAPI.UpdatePriceConfig("tkn", pricingbyservice.Config{})
assert.Error(t, err)
assert.Equal(t, "401", err.Error())
})

t.Run("rejected with invalid config", func(t *testing.T) {
err := PricerAPI.UpdatePriceConfig(validToken, pricing.Config{})
err := PricerAPI.UpdatePriceConfig(validToken, pricingbyservice.Config{})
assert.Error(t, err)
assert.Equal(t, "400", err.Error())
})

t.Run("accepts with valid config", func(t *testing.T) {
toSend := pricing.Config{}
toSend := pricingbyservice.Config{}
err := json.Unmarshal([]byte(expectedPricingConfig), &toSend)
assert.NoError(t, err)
toSend.BasePrices.Other.PricePerGiB = 11
toSend.BasePrices.Other.Wireguard.PricePerGiB = 11

err = PricerAPI.UpdatePriceConfig(validToken, toSend)
assert.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion location/country.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"strings"
)

//https://dev.maxmind.com/geoip/legacy/codes/iso3166/
// https://dev.maxmind.com/geoip/legacy/codes/iso3166/
//
//go:embed countries.csv
var countryCSV string

Expand Down
94 changes: 0 additions & 94 deletions price/api.go

This file was deleted.

9 changes: 9 additions & 0 deletions price/api_by_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import (
"github.com/mysteriumnetwork/go-rest/apierror"
)

const (
errCodeParsingJson = "err_parsing_config"

errCodeNoConfig = "err_no_config"
errCodeUpdateConfig = "err_update_config"

errRedisPingFailed = "failed_redis_ping"
)

type APIByService struct {
pricer *pricingbyservice.PriceGetter
cfger pricingbyservice.ConfigProvider
Expand Down
Loading

0 comments on commit 37f947f

Please sign in to comment.