This commit is contained in:
Amber Brown 2022-07-22 12:18:15 +10:00
Родитель 75f2c4f53d
Коммит d9f33a0dc6
34 изменённых файлов: 83 добавлений и 98 удалений

Просмотреть файл

@ -11,7 +11,6 @@ import (
"os"
"strings"
"github.com/gofrs/uuid"
"github.com/sirupsen/logrus"
"github.com/Azure/ARO-RP/pkg/database"
@ -23,6 +22,7 @@ import (
"github.com/Azure/ARO-RP/pkg/util/encryption"
"github.com/Azure/ARO-RP/pkg/util/keyvault"
"github.com/Azure/ARO-RP/pkg/util/oidc"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
func portal(ctx context.Context, log *logrus.Entry, audit *logrus.Entry) error {

Просмотреть файл

@ -159,8 +159,6 @@ func validateImports(path string, fset *token.FileSet, f *ast.File) []error {
"pkg/operator/clientset",
"pkg/operator/mocks/",
"pkg/util/mocks/",
"pkg/util/uuid/",
"test/util/deterministicuuid/",
} {
if strings.HasPrefix(path, prefix) {
return nil

Просмотреть файл

@ -10,9 +10,8 @@ import (
"testing"
"time"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/test/validate"
)
@ -322,7 +321,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
}
},
modify: func(oc *OpenShiftCluster) {
oc.Properties.ServicePrincipalProfile.ClientID = uuid.Must(uuid.NewV4()).String()
oc.Properties.ServicePrincipalProfile.ClientID = uuid.DefaultGenerator.Generate()
},
wantErr: "400: PropertyChangeNotAllowed: properties.servicePrincipalProfile.clientId: Changing property 'properties.servicePrincipalProfile.clientId' is not allowed.",
},
@ -338,7 +337,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
}
},
modify: func(oc *OpenShiftCluster) {
oc.Properties.ServicePrincipalProfile.SPObjectID = uuid.Must(uuid.NewV4()).String()
oc.Properties.ServicePrincipalProfile.SPObjectID = uuid.DefaultGenerator.Generate()
},
wantErr: "400: PropertyChangeNotAllowed: properties.servicePrincipalProfile.spObjectId: Changing property 'properties.servicePrincipalProfile.spObjectId' is not allowed.",
},

Просмотреть файл

@ -11,13 +11,13 @@ import (
"strings"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/api/validate"
"github.com/Azure/ARO-RP/pkg/util/immutable"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
"github.com/Azure/ARO-RP/pkg/util/subnet"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -173,8 +173,8 @@ func (sv *openShiftClusterStaticValidator) validateConsoleProfile(path string, c
}
func (sv *openShiftClusterStaticValidator) validateServicePrincipalProfile(path string, spp *ServicePrincipalProfile) error {
_, err := uuid.FromString(spp.ClientID)
if err != nil {
valid := uuid.IsValid(spp.ClientID)
if !valid {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".clientId", "The provided client ID '%s' is invalid.", spp.ClientID)
}
if spp.ClientSecret == "" {

Просмотреть файл

@ -10,9 +10,9 @@ import (
"testing"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
"github.com/Azure/ARO-RP/test/validate"
)
@ -762,7 +762,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
{
name: "clientId change",
modify: func(oc *OpenShiftCluster) {
oc.Properties.ServicePrincipalProfile.ClientID = uuid.Must(uuid.NewV4()).String()
oc.Properties.ServicePrincipalProfile.ClientID = uuid.DefaultGenerator.Generate()
},
},
{

Просмотреть файл

@ -11,13 +11,13 @@ import (
"strings"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/api/validate"
"github.com/Azure/ARO-RP/pkg/util/immutable"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
"github.com/Azure/ARO-RP/pkg/util/subnet"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -175,8 +175,8 @@ func (sv *openShiftClusterStaticValidator) validateConsoleProfile(path string, c
}
func (sv *openShiftClusterStaticValidator) validateServicePrincipalProfile(path string, spp *ServicePrincipalProfile) error {
_, err := uuid.FromString(spp.ClientID)
if err != nil {
valid := uuid.IsValid(spp.ClientID)
if !valid {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".clientId", "The provided client ID '%s' is invalid.", spp.ClientID)
}
if spp.ClientSecret == "" {

Просмотреть файл

@ -10,9 +10,9 @@ import (
"testing"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
"github.com/Azure/ARO-RP/test/validate"
)
@ -759,7 +759,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
{
name: "clientId change",
modify: func(oc *OpenShiftCluster) {
oc.Properties.ServicePrincipalProfile.ClientID = uuid.Must(uuid.NewV4()).String()
oc.Properties.ServicePrincipalProfile.ClientID = uuid.DefaultGenerator.Generate()
},
},
{

Просмотреть файл

@ -11,13 +11,13 @@ import (
"strings"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/api/validate"
"github.com/Azure/ARO-RP/pkg/util/immutable"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
"github.com/Azure/ARO-RP/pkg/util/subnet"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -175,8 +175,8 @@ func (sv *openShiftClusterStaticValidator) validateConsoleProfile(path string, c
}
func (sv *openShiftClusterStaticValidator) validateServicePrincipalProfile(path string, spp *ServicePrincipalProfile) error {
_, err := uuid.FromString(spp.ClientID)
if err != nil {
valid := uuid.IsValid(spp.ClientID)
if !valid {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".clientId", "The provided client ID '%s' is invalid.", spp.ClientID)
}
if spp.ClientSecret == "" {

Просмотреть файл

@ -11,9 +11,9 @@ import (
"time"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
"github.com/Azure/ARO-RP/test/validate"
)
@ -863,7 +863,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
{
name: "clientId change",
modify: func(oc *OpenShiftCluster) {
oc.Properties.ServicePrincipalProfile.ClientID = uuid.Must(uuid.NewV4()).String()
oc.Properties.ServicePrincipalProfile.ClientID = uuid.DefaultGenerator.Generate()
},
},
{

Просмотреть файл

@ -11,13 +11,13 @@ import (
"strings"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/api/validate"
"github.com/Azure/ARO-RP/pkg/util/immutable"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
"github.com/Azure/ARO-RP/pkg/util/subnet"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -181,8 +181,8 @@ func (sv *openShiftClusterStaticValidator) validateConsoleProfile(path string, c
}
func (sv *openShiftClusterStaticValidator) validateServicePrincipalProfile(path string, spp *ServicePrincipalProfile) error {
_, err := uuid.FromString(spp.ClientID)
if err != nil {
valid := uuid.IsValid(spp.ClientID)
if !valid {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".clientId", "The provided client ID '%s' is invalid.", spp.ClientID)
}
if spp.ClientSecret == "" {

Просмотреть файл

@ -11,9 +11,9 @@ import (
"time"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
"github.com/Azure/ARO-RP/test/validate"
)
@ -853,7 +853,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
{
name: "clientId change",
modify: func(oc *OpenShiftCluster) {
oc.Properties.ServicePrincipalProfile.ClientID = uuid.Must(uuid.NewV4()).String()
oc.Properties.ServicePrincipalProfile.ClientID = uuid.DefaultGenerator.Generate()
},
},
{

Просмотреть файл

@ -11,13 +11,13 @@ import (
"strings"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/api/validate"
"github.com/Azure/ARO-RP/pkg/util/immutable"
"github.com/Azure/ARO-RP/pkg/util/pullsecret"
"github.com/Azure/ARO-RP/pkg/util/subnet"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
)
@ -181,8 +181,8 @@ func (sv *openShiftClusterStaticValidator) validateConsoleProfile(path string, c
}
func (sv *openShiftClusterStaticValidator) validateServicePrincipalProfile(path string, spp *ServicePrincipalProfile) error {
_, err := uuid.FromString(spp.ClientID)
if err != nil {
valid := uuid.IsValid(spp.ClientID)
if !valid {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".clientId", "The provided client ID '%s' is invalid.", spp.ClientID)
}
if spp.ClientSecret == "" {

Просмотреть файл

@ -12,9 +12,9 @@ import (
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/util/uuid"
"github.com/Azure/ARO-RP/pkg/util/version"
"github.com/Azure/ARO-RP/test/validate"
)
@ -892,7 +892,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
{
name: "clientId change",
modify: func(oc *OpenShiftCluster) {
oc.Properties.ServicePrincipalProfile.ClientID = uuid.Must(uuid.NewV4()).String()
oc.Properties.ServicePrincipalProfile.ClientID = uuid.DefaultGenerator.Generate()
},
},
{

Просмотреть файл

@ -9,10 +9,9 @@ import (
"net/http"
"strings"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type asyncOperations struct {
@ -48,7 +47,7 @@ func NewAsyncOperationsWithProvidedClient(client cosmosdb.AsyncOperationDocument
}
func (c *asyncOperations) NextUUID() string {
return uuid.Must(c.uuidGenerator.NewV4()).String()
return c.uuidGenerator.Generate()
}
func (c *asyncOperations) Create(ctx context.Context, doc *api.AsyncOperationDocument) (*api.AsyncOperationDocument, error) {

Просмотреть файл

@ -8,10 +8,9 @@ import (
"fmt"
"strings"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type gateway struct {
@ -48,7 +47,7 @@ func NewGatewayWithProvidedClient(client cosmosdb.GatewayDocumentClient, uuidGen
}
func (c *gateway) NextUUID() string {
return uuid.Must(c.uuidGenerator.NewV4()).String()
return c.uuidGenerator.Generate()
}
func (c *gateway) ChangeFeed() cosmosdb.GatewayDocumentIterator {

Просмотреть файл

@ -9,10 +9,9 @@ import (
"net/http"
"strings"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type monitors struct {
@ -64,7 +63,7 @@ func NewMonitors(ctx context.Context, isLocalDevelopmentMode bool, dbc cosmosdb.
return &monitors{
c: cosmosdb.NewMonitorDocumentClient(collc, collMonitors),
uuid: uuid.Must(uuid.NewV4()).String(),
uuid: uuid.DefaultGenerator.Generate(),
}, nil
}

Просмотреть файл

@ -10,10 +10,10 @@ import (
"strings"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
const (
@ -88,7 +88,7 @@ func NewOpenShiftClusters(ctx context.Context, isLocalDevelopmentMode bool, dbc
}
documentClient := cosmosdb.NewOpenShiftClusterDocumentClient(collc, collOpenShiftClusters)
return NewOpenShiftClustersWithProvidedClient(documentClient, collc, uuid.Must(uuid.NewV4()).String(), uuid.DefaultGenerator), nil
return NewOpenShiftClustersWithProvidedClient(documentClient, collc, uuid.DefaultGenerator.Generate(), uuid.DefaultGenerator), nil
}
func NewOpenShiftClustersWithProvidedClient(client cosmosdb.OpenShiftClusterDocumentClient, collectionClient cosmosdb.CollectionClient, uuid string, uuidGenerator uuid.Generator) OpenShiftClusters {
@ -101,7 +101,7 @@ func NewOpenShiftClustersWithProvidedClient(client cosmosdb.OpenShiftClusterDocu
}
func (c *openShiftClusters) NextUUID() string {
return uuid.Must(c.uuidGenerator.NewV4()).String()
return c.uuidGenerator.Generate()
}
func (c *openShiftClusters) Create(ctx context.Context, doc *api.OpenShiftClusterDocument) (*api.OpenShiftClusterDocument, error) {

Просмотреть файл

@ -9,10 +9,9 @@ import (
"net/http"
"strings"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type portals struct {
@ -49,7 +48,7 @@ func NewPortalWithProvidedClient(client cosmosdb.PortalDocumentClient, uuidGener
}
func (c *portals) NextUUID() string {
return uuid.Must(c.uuidGenerator.NewV4()).String()
return c.uuidGenerator.Generate()
}
func (c *portals) Create(ctx context.Context, doc *api.PortalDocument) (*api.PortalDocument, error) {

Просмотреть файл

@ -9,10 +9,9 @@ import (
"net/http"
"strings"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
const SubscriptionsDequeueQuery string = `SELECT * FROM Subscriptions doc WHERE (doc.deleting ?? false) AND (doc.leaseExpires ?? 0) < GetCurrentTimestamp() / 1000`
@ -78,7 +77,7 @@ func NewSubscriptions(ctx context.Context, isLocalDevelopmentMode bool, dbc cosm
}
documentClient := cosmosdb.NewSubscriptionDocumentClient(collc, collSubscriptions)
return NewSubscriptionsWithProvidedClient(documentClient, uuid.Must(uuid.NewV4()).String()), nil
return NewSubscriptionsWithProvidedClient(documentClient, uuid.DefaultGenerator.Generate()), nil
}
func NewSubscriptionsWithProvidedClient(client cosmosdb.SubscriptionDocumentClient, uuid string) Subscriptions {

Просмотреть файл

@ -16,7 +16,6 @@ import (
"strings"
"time"
"github.com/gofrs/uuid"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
@ -26,6 +25,7 @@ import (
"github.com/Azure/ARO-RP/pkg/portal/middleware"
"github.com/Azure/ARO-RP/pkg/util/heartbeat"
"github.com/Azure/ARO-RP/pkg/util/oidc"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
var rxValidPermission = regexp.MustCompile("^[a-z]{1,20}$")
@ -146,7 +146,7 @@ func (s *server) authenticate(h http.Handler) http.Handler {
return
}
if _, err := uuid.FromString(token.Subject()); err != nil {
if valid := uuid.IsValid(token.Subject()); !valid {
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return
}

Просмотреть файл

@ -8,9 +8,8 @@ import (
"encoding/json"
"regexp"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/util/arm"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
const (
@ -23,7 +22,7 @@ const (
)
var (
tenantUUIDHack = uuid.Must(uuid.FromString(tenantIDHack))
tenantUUIDHack = uuid.MustFromString(tenantIDHack)
)
func max(is ...int) int {

4
pkg/env/armhelper.go поставляемый
Просмотреть файл

@ -13,13 +13,13 @@ import (
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/go-autorest/autorest/to"
"github.com/gofrs/uuid"
"github.com/sirupsen/logrus"
"github.com/Azure/ARO-RP/pkg/util/azureclient/graphrbac"
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/authorization"
"github.com/Azure/ARO-RP/pkg/util/rbac"
"github.com/Azure/ARO-RP/pkg/util/refreshable"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
// In INT or PROD, when the ARO RP is running behind ARM, ARM follows the RP's
@ -131,7 +131,7 @@ func (ah *armHelper) EnsureARMResourceGroupRoleAssignment(ctx context.Context, f
return err
}
_, err = ah.roleassignments.Create(ctx, "/subscriptions/"+ah.env.SubscriptionID()+"/resourceGroups/"+resourceGroup, uuid.Must(uuid.NewV4()).String(), mgmtauthorization.RoleAssignmentCreateParameters{
_, err = ah.roleassignments.Create(ctx, "/subscriptions/"+ah.env.SubscriptionID()+"/resourceGroups/"+resourceGroup, uuid.DefaultGenerator.Generate(), mgmtauthorization.RoleAssignmentCreateParameters{
RoleAssignmentProperties: &mgmtauthorization.RoleAssignmentProperties{
RoleDefinitionID: to.StringPtr("/subscriptions/" + ah.env.SubscriptionID() + "/providers/Microsoft.Authorization/roleDefinitions/" + rbac.RoleOwner),
PrincipalID: res.Value,

Просмотреть файл

@ -11,7 +11,6 @@ import (
"strings"
"time"
"github.com/gofrs/uuid"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
@ -20,6 +19,7 @@ import (
"github.com/Azure/ARO-RP/pkg/env"
utillog "github.com/Azure/ARO-RP/pkg/util/log"
"github.com/Azure/ARO-RP/pkg/util/log/audit"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type logResponseWriter struct {
@ -65,7 +65,7 @@ func Log(env env.Core, auditLog, baseLog *logrus.Entry) func(http.Handler) http.
correlationData := &api.CorrelationData{
ClientRequestID: r.Header.Get("X-Ms-Client-Request-Id"),
CorrelationID: r.Header.Get("X-Ms-Correlation-Request-Id"),
RequestID: uuid.Must(uuid.NewV4()).String(),
RequestID: uuid.DefaultGenerator.Generate(),
RequestTime: t,
}

Просмотреть файл

@ -8,12 +8,12 @@ import (
"regexp"
"strings"
"github.com/gofrs/uuid"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
const (
@ -46,8 +46,8 @@ func Validate(env env.Core, apis map[string]*api.Version) func(http.Handler) htt
}
if _, found := vars["subscriptionId"]; found {
_, err := uuid.FromString(vars["subscriptionId"])
if err != nil {
valid := uuid.IsValid(vars["subscriptionId"])
if !valid {
api.WriteError(w, http.StatusBadRequest, api.CloudErrorCodeInvalidSubscriptionID, "", "The provided subscription identifier '%s' is malformed or invalid.", vars["subscriptionId"])
return
}
@ -89,8 +89,8 @@ func Validate(env env.Core, apis map[string]*api.Version) func(http.Handler) htt
}
if _, found := vars["operationId"]; found {
_, err := uuid.FromString(vars["operationId"])
if err != nil {
valid := uuid.IsValid(vars["operationId"])
if !valid {
api.WriteError(w, http.StatusBadRequest, api.CloudErrorCodeInvalidOperationID, "", "The provided operation identifier '%s' is malformed or invalid.", vars["operationId"])
return
}

Просмотреть файл

@ -6,7 +6,6 @@ package hive
import (
"context"
"github.com/gofrs/uuid"
hiveclient "github.com/openshift/hive/pkg/client/clientset/versioned"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
@ -18,6 +17,7 @@ import (
"k8s.io/client-go/util/retry"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type ClusterManager interface {
@ -80,7 +80,7 @@ func (hr *clusterManager) CreateNamespace(ctx context.Context) (*corev1.Namespac
var namespaceName string
var namespace *corev1.Namespace
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
namespaceName = "aro-" + uuid.Must(uuid.NewV4()).String()
namespaceName = "aro-" + uuid.DefaultGenerator.Generate()
namespace = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespaceName,

Просмотреть файл

@ -15,7 +15,6 @@ import (
"time"
"github.com/Azure/go-autorest/autorest/adal"
"github.com/gofrs/uuid"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"github.com/sirupsen/logrus"
@ -24,6 +23,7 @@ import (
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/util/oidc"
"github.com/Azure/ARO-RP/pkg/util/roundtripper"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
const (
@ -209,7 +209,7 @@ func (a *aad) redirect(w http.ResponseWriter, r *http.Request) {
return
}
state := uuid.Must(uuid.NewV4()).String()
state := uuid.DefaultGenerator.Generate()
session.Values = map[interface{}]interface{}{
sessionKeyState: state,

Просмотреть файл

@ -19,7 +19,6 @@ import (
"github.com/form3tech-oss/jwt-go"
"github.com/go-test/deep"
"github.com/gofrs/uuid"
"github.com/golang/mock/gomock"
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
@ -30,6 +29,7 @@ import (
"github.com/Azure/ARO-RP/pkg/util/oidc"
"github.com/Azure/ARO-RP/pkg/util/roundtripper"
utiltls "github.com/Azure/ARO-RP/pkg/util/tls"
"github.com/Azure/ARO-RP/pkg/util/uuid"
testlog "github.com/Azure/ARO-RP/test/util/log"
)
@ -490,7 +490,7 @@ func TestCallback(t *testing.T) {
{
name: "success",
request: func(a *aad) (*http.Request, error) {
uuid := uuid.Must(uuid.NewV4()).String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,
@ -540,8 +540,7 @@ func TestCallback(t *testing.T) {
{
name: "fail - state mismatch",
request: func(a *aad) (*http.Request, error) {
u, _ := uuid.NewV4()
uuid := u.String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,
@ -565,8 +564,7 @@ func TestCallback(t *testing.T) {
{
name: "fail - error returned",
request: func(a *aad) (*http.Request, error) {
u, _ := uuid.NewV4()
uuid := u.String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,
@ -592,8 +590,7 @@ func TestCallback(t *testing.T) {
{
name: "fail - oauther failed",
request: func(a *aad) (*http.Request, error) {
u, _ := uuid.NewV4()
uuid := u.String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,
@ -620,8 +617,7 @@ func TestCallback(t *testing.T) {
{
name: "fail - no idtoken",
request: func(a *aad) (*http.Request, error) {
u, _ := uuid.NewV4()
uuid := u.String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,
@ -646,8 +642,7 @@ func TestCallback(t *testing.T) {
{
name: "fail - verifier error",
request: func(a *aad) (*http.Request, error) {
u, _ := uuid.NewV4()
uuid := u.String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,
@ -677,8 +672,7 @@ func TestCallback(t *testing.T) {
{
name: "fail - invalid claims",
request: func(a *aad) (*http.Request, error) {
u, _ := uuid.NewV4()
uuid := u.String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,
@ -708,8 +702,7 @@ func TestCallback(t *testing.T) {
{
name: "fail - group mismatch",
request: func(a *aad) (*http.Request, error) {
u, _ := uuid.NewV4()
uuid := u.String()
uuid := uuid.DefaultGenerator.Generate()
cookie, err := securecookie.EncodeMulti(SessionName, map[interface{}]interface{}{
sessionKeyState: uuid,

Просмотреть файл

@ -8,9 +8,8 @@ import (
"net/http"
"strings"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/database"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
// Bearer validates a Bearer token and adds the corresponding username to the

Просмотреть файл

@ -12,7 +12,6 @@ import (
"strings"
"time"
"github.com/gofrs/uuid"
"github.com/sirupsen/logrus"
cryptossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
@ -21,6 +20,7 @@ import (
"github.com/Azure/ARO-RP/pkg/api"
utillog "github.com/Azure/ARO-RP/pkg/util/log"
"github.com/Azure/ARO-RP/pkg/util/recover"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
const (

Просмотреть файл

@ -12,11 +12,11 @@ import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
"github.com/gofrs/uuid"
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/containerregistry"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type Manager interface {
@ -65,7 +65,7 @@ func (m *manager) GetRegistryProfile(oc *api.OpenShiftCluster) *api.RegistryProf
func (m *manager) NewRegistryProfile(oc *api.OpenShiftCluster) *api.RegistryProfile {
return &api.RegistryProfile{
Name: fmt.Sprintf("%s.%s", m.r.ResourceName, m.env.Environment().ContainerRegistryDNSSuffix),
Username: "token-" + uuid.Must(uuid.NewV4()).String(),
Username: "token-" + uuid.DefaultGenerator.Generate(),
}
}

Просмотреть файл

@ -8,7 +8,7 @@ import (
"fmt"
"reflect"
"github.com/gofrs/uuid"
gofrsuuid "github.com/gofrs/uuid"
)
// MarshalJSON marshals the nested r.Resource ignoring any MarshalJSON() methods
@ -86,7 +86,7 @@ func _shadowCopy(v reflect.Value) reflect.Value {
switch v.Kind() {
case reflect.Array:
var t reflect.Type
if v.Type() == reflect.TypeOf(uuid.UUID{}) {
if v.Type() == reflect.TypeOf(gofrsuuid.UUID{}) {
// keep uuid.UUID - encoding/json will detect it and marshal it into
// a string
t = v.Type()

Просмотреть файл

@ -12,8 +12,9 @@ import (
azgraphrbac "github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/date"
"github.com/gofrs/uuid"
"k8s.io/apimachinery/pkg/util/wait"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
func (c *Cluster) getServicePrincipal(ctx context.Context, appID string) (string, error) {
@ -36,7 +37,7 @@ func (c *Cluster) getServicePrincipal(ctx context.Context, appID string) (string
}
func (c *Cluster) createApplication(ctx context.Context, displayName string) (string, string, error) {
password := uuid.Must(uuid.NewV4()).String()
password := uuid.DefaultGenerator.Generate()
app, err := c.applications.Create(ctx, azgraphrbac.ApplicationCreateParameters{
DisplayName: &displayName,

Просмотреть файл

@ -22,7 +22,6 @@ import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/go-autorest/autorest/to"
"github.com/gofrs/uuid"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait"
@ -42,6 +41,7 @@ import (
redhatopenshift20210901preview "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/redhatopenshift/2021-09-01-preview/redhatopenshift"
redhatopenshift20220401 "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/redhatopenshift/2022-04-01/redhatopenshift"
"github.com/Azure/ARO-RP/pkg/util/rbac"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
type Cluster struct {
@ -188,7 +188,7 @@ func (c *Cluster) Create(ctx context.Context, vnetResourceGroup, clusterName str
if c.ci {
// name is limited to 24 characters, but must be globally unique, so we generate one and try if it is available
kvName = "kv-" + uuid.Must(uuid.NewV4()).String()[:21]
kvName = "kv-" + uuid.DefaultGenerator.Generate()[:21]
result, err := c.vaultsClient.CheckNameAvailability(ctx, mgmtkeyvault.VaultCheckNameAvailabilityParameters{Name: &kvName, Type: to.StringPtr("Microsoft.KeyVault/vaults")})
if err != nil {
return err
@ -259,7 +259,7 @@ func (c *Cluster) Create(ctx context.Context, vnetResourceGroup, clusterName str
_, err = c.roleassignments.Create(
ctx,
scope.resource,
uuid.Must(uuid.NewV4()).String(),
uuid.DefaultGenerator.Generate(),
mgmtauthorization.RoleAssignmentCreateParameters{
RoleAssignmentProperties: &mgmtauthorization.RoleAssignmentProperties{
RoleDefinitionID: to.StringPtr("/subscriptions/" + c.env.SubscriptionID() + "/providers/Microsoft.Authorization/roleDefinitions/" + scope.role),

Просмотреть файл

@ -8,8 +8,9 @@ import (
"fmt"
"sync"
"github.com/gofrs/uuid"
"github.com/sirupsen/logrus"
"github.com/Azure/ARO-RP/pkg/util/uuid"
)
const (
@ -61,7 +62,7 @@ var (
// epoch is an unique identifier associated with the current session of the
// telemetry library running on the platform. It must be stable during a
// session, and has no implied ordering across sessions.
epoch = uuid.Must(uuid.NewV4()).String()
epoch = uuid.DefaultGenerator.Generate()
// seqNum is used to track absolute order of uploaded events, per session.
// It is reset when the ARO component is restarted. The first log will have