Skip to content

Commit

Permalink
[TT-8265] Drop satori go.uuid package (TykTechnologies#4849)
Browse files Browse the repository at this point in the history
<!-- Provide a general summary of your changes in the Title above -->

## Description

This PR removes satori/go.uuid in favor of gofrs/uuid.
<!-- Describe your changes in detail -->

## Related Issue

<!-- This project only accepts pull requests related to open issues. -->
<!-- If suggesting a new feature or change, please discuss it in an
issue first. -->
<!-- If fixing a bug, there should be an issue describing it with steps
to reproduce. -->
<!-- OSS: Please link to the issue here. Tyk: please create/link the
JIRA ticket. -->

https://tyktech.atlassian.net/browse/TT-8265

## Motivation and Context

<!-- Why is this change required? What problem does it solve? -->

## How This Has Been Tested

<!-- Please describe in detail how you tested your changes -->
<!-- Include details of your testing environment, and the tests -->
<!-- you ran to see how your change affects other areas of the code,
etc. -->
<!-- This information is helpful for reviewers and QA. -->

## Screenshots (if appropriate)

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test
coverage to functionality)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes
that apply -->
<!-- If there are no documentation updates required, mark the item as
checked. -->
<!-- Raise up any additional concerns not covered by the checklist. -->

- [ ] I ensured that the documentation is up to date
- [ ] I explained why this PR updates go.mod in detail with reasoning
why it's required
- [ ] I would like a code coverage CI quality gate exception and have
explained why

---------

Co-authored-by: Tit Petric <[email protected]>
  • Loading branch information
titpetric and Tit Petric authored Mar 10, 2023
1 parent 52591f5 commit 0e3ab5f
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 80 deletions.
15 changes: 6 additions & 9 deletions apidef/api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"text/template"
"time"

uuid "github.com/satori/go.uuid"

"github.com/TykTechnologies/graphql-go-tools/pkg/engine/datasource/kafka_datasource"
"github.com/TykTechnologies/graphql-go-tools/pkg/execution/datasource"

"github.com/clbanning/mxj"

"github.com/lonelycode/osin"
"gopkg.in/mgo.v2/bson"

"github.com/TykTechnologies/gojsonschema"
"github.com/TykTechnologies/graphql-go-tools/pkg/engine/datasource/kafka_datasource"
"github.com/TykTechnologies/graphql-go-tools/pkg/execution/datasource"

"github.com/TykTechnologies/gojsonschema"
"github.com/TykTechnologies/tyk/regexp"

"github.com/TykTechnologies/tyk/internal/uuid"
)

type AuthProviderCode string
Expand Down Expand Up @@ -1124,7 +1121,7 @@ func (s *StringRegexMap) Init() error {
}

func (a *APIDefinition) GenerateAPIID() {
a.APIID = strings.Replace(uuid.NewV4().String(), "-", "", -1)
a.APIID = uuid.NewHex()
}

func (a *APIDefinition) GetAPIDomain() string {
Expand Down
6 changes: 3 additions & 3 deletions apidef/importer/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strconv"
"strings"

uuid "github.com/satori/go.uuid"

"github.com/TykTechnologies/tyk/apidef"

"github.com/TykTechnologies/tyk/internal/uuid"
)

const ApiaryBluePrint APIImporterSource = "blueprint"
Expand Down Expand Up @@ -164,7 +164,7 @@ func (b *BluePrintAST) ToAPIDefinition(orgID, upstreamURL string, asMock bool) (
Name: b.Name,
Active: true,
UseKeylessAccess: true,
APIID: uuid.NewV4().String(),
APIID: uuid.NewHex(),
OrgID: orgID,
}
ad.VersionDefinition.Key = "version"
Expand Down
6 changes: 3 additions & 3 deletions apidef/importer/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"net/http"
"strings"

uuid "github.com/satori/go.uuid"

"github.com/TykTechnologies/tyk/apidef"

"github.com/TykTechnologies/tyk/internal/uuid"
)

const SwaggerSource APIImporterSource = "swagger"
Expand Down Expand Up @@ -145,7 +145,7 @@ func (s *SwaggerAST) ToAPIDefinition(orgId, upstreamURL string, as_mock bool) (*
Name: s.Info.Title,
Active: true,
UseKeylessAccess: true,
APIID: uuid.NewV4().String(),
APIID: uuid.NewHex(),
OrgID: orgId,
}
ad.VersionDefinition.Key = "version"
Expand Down
6 changes: 3 additions & 3 deletions apidef/importer/wsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"net/http"
"strings"

uuid "github.com/satori/go.uuid"

"github.com/TykTechnologies/tyk/apidef"

"github.com/TykTechnologies/tyk/internal/uuid"
)

const WSDLSource APIImporterSource = "wsdl"
Expand Down Expand Up @@ -279,7 +279,7 @@ func (def *WSDLDef) ToAPIDefinition(orgId, upstreamURL string, as_mock bool) (*a
Active: true,
UseKeylessAccess: true,
OrgID: orgId,
APIID: uuid.NewV4().String(),
APIID: uuid.NewHex(),
}

ad.VersionDefinition.Key = "version"
Expand Down
6 changes: 2 additions & 4 deletions apidef/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"sort"
"strings"

uuid "github.com/satori/go.uuid"

"github.com/TykTechnologies/tyk/internal/reflect"
"github.com/TykTechnologies/tyk/internal/uuid"
)

var (
Expand Down Expand Up @@ -60,8 +59,7 @@ func (a *APIDefinition) MigrateVersioning() (versions []APIDefinition, err error
for vName, vInfo := range a.VersionData.Versions {
newAPI := *a

newID := uuid.NewV4()
apiID := strings.Replace(newID.String(), "-", "", -1)
apiID := uuid.NewHex()

newAPI.APIID = apiID
newAPI.Id = ""
Expand Down
13 changes: 6 additions & 7 deletions gateway/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (

"github.com/TykTechnologies/tyk/config"

uuid "github.com/satori/go.uuid"
"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/apidef/oas"

Expand Down Expand Up @@ -2140,11 +2140,10 @@ func (gw *Gateway) createOauthClient(w http.ResponseWriter, r *http.Request) {
}

// Allow the client ID to be set
cleanSting := newOauthClient.ClientID
clientID := newOauthClient.ClientID

if newOauthClient.ClientID == "" {
u5 := uuid.NewV4()
cleanSting = strings.Replace(u5.String(), "-", "", -1)
clientID = uuid.NewHex()
}

// Allow the secret to be set
Expand All @@ -2154,7 +2153,7 @@ func (gw *Gateway) createOauthClient(w http.ResponseWriter, r *http.Request) {
}

newClient := OAuthClient{
ClientID: cleanSting,
ClientID: clientID,
ClientRedirectURI: newOauthClient.ClientRedirectURI,
ClientSecret: secret,
PolicyID: newOauthClient.PolicyID,
Expand Down Expand Up @@ -3386,8 +3385,8 @@ func ctxGetOperation(r *http.Request) (op *Operation) {
}

var createOauthClientSecret = func() string {
secret := uuid.NewV4()
return base64.StdEncoding.EncodeToString([]byte(secret.String()))
secret := uuid.New()
return base64.StdEncoding.EncodeToString([]byte(secret))
}

// invalidate tokens if we had a new policy
Expand Down
6 changes: 4 additions & 2 deletions gateway/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (

"github.com/getkin/kin-openapi/openapi3"
"github.com/go-redis/redis/v8"
uuid "github.com/satori/go.uuid"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/apidef/oas"
"github.com/TykTechnologies/tyk/certs"
Expand Down Expand Up @@ -1836,7 +1837,8 @@ func TestApiLoaderLongestPathFirst(t *testing.T) {

for hp := range inputs {
apis = append(apis, BuildAPI(func(spec *APISpec) {
spec.APIID = uuid.NewV4().String()
spec.APIID = uuid.New()

spec.Domain = hp.host
spec.Proxy.ListenPath = "/" + hp.path
})[0])
Expand Down
7 changes: 3 additions & 4 deletions gateway/auth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"strings"
"time"

uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"

"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/storage"
"github.com/TykTechnologies/tyk/user"
)
Expand Down Expand Up @@ -219,7 +220,5 @@ func (d DefaultKeyGenerator) GenerateAuthKey(orgID string) string {

// GenerateHMACSecret is a utility function for generating new auth keys. Returns the storage key name and the actual key
func (DefaultKeyGenerator) GenerateHMACSecret() string {
u5 := uuid.NewV4()
cleanSting := strings.Replace(u5.String(), "-", "", -1)
return base64.StdEncoding.EncodeToString([]byte(cleanSting))
return base64.StdEncoding.EncodeToString([]byte(uuid.NewHex()))
}
5 changes: 3 additions & 2 deletions gateway/host_checker_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"sync"
"time"

uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
msgpack "gopkg.in/vmihailenco/msgpack.v2"

"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/storage"
)
Expand Down Expand Up @@ -87,7 +88,7 @@ func (hc *HostCheckerManager) Start(ctx context.Context) {
}

func (hc *HostCheckerManager) GenerateCheckerId() {
hc.Id = uuid.NewV4().String()
hc.Id = uuid.New()
}

// CheckActivePollerLoop manages the state of the HostCheckerManager UptimeTest
Expand Down
7 changes: 0 additions & 7 deletions gateway/host_checker_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"net/http"
"testing"

uuid "github.com/satori/go.uuid"

"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/storage"
"github.com/TykTechnologies/tyk/test"
Expand Down Expand Up @@ -99,11 +97,6 @@ func TestGenerateCheckerId(t *testing.T) {
if hc.Id == "" {
t.Error("HostCheckerManager should generate an Id on GenerateCheckerId")
}

uuid, _ := uuid.FromString(hc.Id)
if uuid.Version() != 4 {
t.Error("HostCheckerManager should generate an uuid.v4 id")
}
}

func TestCheckActivePollerLoop(t *testing.T) {
Expand Down
12 changes: 8 additions & 4 deletions gateway/host_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
"time"

proxyproto "github.com/pires/go-proxyproto"
uuid "github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"

"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/storage"
Expand Down Expand Up @@ -71,7 +72,8 @@ func (w *testEventHandler) HandleEvent(em config.EventMessage) {
// // ToDo check why it blocks
func TestHostChecker(t *testing.T) {
ts := StartTest(func(globalConf *config.Config) {
globalConf.UptimeTests.PollerGroup = uuid.NewV4().String()
globalConf.UptimeTests.PollerGroup = uuid.New()

})
defer ts.Close()

Expand Down Expand Up @@ -178,7 +180,8 @@ func TestHostChecker(t *testing.T) {
func TestReverseProxyAllDown(t *testing.T) {

ts := StartTest(func(globalConf *config.Config) {
globalConf.UptimeTests.PollerGroup = uuid.NewV4().String()
globalConf.UptimeTests.PollerGroup = uuid.New()

})
defer ts.Close()

Expand Down Expand Up @@ -458,7 +461,8 @@ func TestProxyWhenHostIsDown(t *testing.T) {
conf.UptimeTests.Config.FailureTriggerSampleSize = 1
conf.UptimeTests.Config.TimeWait = 5
conf.UptimeTests.Config.EnableUptimeAnalytics = true
conf.UptimeTests.PollerGroup = uuid.NewV4().String()
conf.UptimeTests.PollerGroup = uuid.New()

}
ts := StartTest(conf)
defer ts.Close()
Expand Down
6 changes: 4 additions & 2 deletions gateway/mw_api_rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"time"

"github.com/justinas/alice"
uuid "github.com/satori/go.uuid"

"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/test"
"github.com/TykTechnologies/tyk/user"
Expand Down Expand Up @@ -224,7 +225,8 @@ func TestRLClosed(t *testing.T) {
req := TestReq(t, "GET", "/rl_closed_test/", nil)

session := createRLSession()
customToken := uuid.NewV4().String()
customToken := uuid.New()

// AuthKey sessions are stored by {token}
err := ts.Gw.GlobalSessionManager.UpdateSession(customToken, session, 60, false)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions gateway/mw_context_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strings"

uuid "github.com/satori/go.uuid"
"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/request"
)
Expand Down Expand Up @@ -33,7 +33,7 @@ func (m *MiddlewareContextVars) ProcessRequest(w http.ResponseWriter, r *http.Re
"path_parts": strings.Split(r.URL.Path, "/"), // Path parts
"path": r.URL.Path, // path data
"remote_addr": request.RealIP(r), // IP
"request_id": uuid.NewV4().String(), //Correlation ID
"request_id": uuid.New(), //Correlation ID
}

for hname, vals := range r.Header {
Expand Down
5 changes: 3 additions & 2 deletions gateway/mw_organisation_activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

uuid "github.com/satori/go.uuid"
"github.com/TykTechnologies/tyk/internal/uuid"

"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/test"
Expand All @@ -17,7 +17,8 @@ import (
func (ts *Test) testPrepareProcessRequestQuotaLimit(tb testing.TB, data map[string]interface{}) {

// load API
orgID := "test-org-" + uuid.NewV4().String()
orgID := "test-org-" + uuid.New()

ts.Gw.BuildAndLoadAPI(func(spec *APISpec) {
spec.UseKeylessAccess = true
spec.OrgID = orgID
Expand Down
6 changes: 3 additions & 3 deletions gateway/oauth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
"github.com/TykTechnologies/tyk/request"

"github.com/lonelycode/osin"
uuid "github.com/satori/go.uuid"
"golang.org/x/crypto/bcrypt"

"github.com/TykTechnologies/tyk/internal/uuid"

"strconv"

"github.com/TykTechnologies/tyk/header"
Expand Down Expand Up @@ -1138,8 +1139,7 @@ func (a accessTokenGen) GenerateAccessToken(data *osin.AccessData, generaterefre

accesstoken = a.Gw.keyGen.GenerateAuthKey(newSession.OrgID)
if generaterefresh {
u6 := uuid.NewV4()
refreshtoken = base64.StdEncoding.EncodeToString([]byte(u6.String()))
refreshtoken = base64.StdEncoding.EncodeToString([]byte(uuid.New()))
}
return
}
Expand Down
Loading

0 comments on commit 0e3ab5f

Please sign in to comment.