Skip to content

Commit 3b4d35d

Browse files
authored
Merge pull request #972 from meshery/core-uuid-transition
Transition UUID type references to schemas core.Uuid
2 parents cb5bcff + 7de2424 commit 3b4d35d

6 files changed

Lines changed: 29 additions & 26 deletions

File tree

models/events/build.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
"github.com/gofrs/uuid"
7+
core "github.com/meshery/schemas/models/core"
78
)
89

910
type EventBuilder struct {
@@ -21,7 +22,7 @@ func NewEvent() *EventBuilder {
2122
}
2223
}
2324

24-
func (e *EventBuilder) ActedUpon(resource uuid.UUID) *EventBuilder {
25+
func (e *EventBuilder) ActedUpon(resource core.Uuid) *EventBuilder {
2526
e.event.ActedUpon = resource
2627
return e
2728
}
@@ -56,12 +57,12 @@ func (e *EventBuilder) WithStatus(status EventStatus) *EventBuilder {
5657
return e
5758
}
5859

59-
func (e *EventBuilder) FromUser(id uuid.UUID) *EventBuilder {
60+
func (e *EventBuilder) FromUser(id core.Uuid) *EventBuilder {
6061
e.event.UserID = &id
6162
return e
6263
}
6364

64-
func (e *EventBuilder) FromSystem(id uuid.UUID) *EventBuilder {
65+
func (e *EventBuilder) FromSystem(id core.Uuid) *EventBuilder {
6566
e.event.SystemID = id
6667
return e
6768
}

models/events/constants.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package events
33
import (
44
"fmt"
55

6-
"github.com/gofrs/uuid"
6+
core "github.com/meshery/schemas/models/core"
77
)
88

9-
func DesignDownloadEvent(designID uuid.UUID, designName string, userID uuid.UUID, systemID uuid.UUID) *Event {
9+
func DesignDownloadEvent(designID core.Uuid, designName string, userID core.Uuid, systemID core.Uuid) *Event {
1010

1111
event := NewEvent().ActedUpon(designID).FromSystem(systemID).FromUser(userID).WithCategory("pattern").WithAction("download").
1212
WithSeverity(Informational).WithDescription(fmt.Sprintf("Downloaded \"%s\" design", designName)).Build()
1313
return event
1414
}
1515

16-
func DesignViewEvent(designID uuid.UUID, designName string, userID uuid.UUID, systemID uuid.UUID) *Event {
16+
func DesignViewEvent(designID core.Uuid, designName string, userID core.Uuid, systemID core.Uuid) *Event {
1717

1818
event := NewEvent().ActedUpon(designID).FromSystem(systemID).FromUser(userID).WithCategory("pattern").WithAction("view").WithSeverity(Informational).WithDescription(fmt.Sprintf("Accessed \"%s\" pattern.", designName)).Build()
1919
return event

models/events/events.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/meshmodel/core/v1beta1/policy.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/gofrs/uuid"
99
"github.com/meshery/meshkit/database"
1010
"github.com/meshery/meshkit/utils"
11+
core "github.com/meshery/schemas/models/core"
1112
v1beta1 "github.com/meshery/schemas/models/v1beta1/model"
1213
"gorm.io/gorm/clause"
1314

@@ -16,22 +17,22 @@ import (
1617

1718
// swagger:response PolicyDefinition
1819
type PolicyDefinition struct {
19-
ID uuid.UUID `json:"-"`
20+
ID core.Uuid `json:"-"`
2021
Kind string `json:"kind,omitempty" yaml:"kind"`
2122
Version string `json:"version,omitempty" yaml:"version"`
22-
ModelID uuid.UUID `json:"-" gorm:"column:modelID"`
23+
ModelID core.Uuid `json:"-" gorm:"column:modelID"`
2324
Model v1beta1.ModelDefinition `json:"model"`
2425
SubType string `json:"subType" yaml:"subType"`
2526
Expression map[string]interface{} `json:"expression" yaml:"expression" gorm:"type:bytes;serializer:json"`
2627
CreatedAt time.Time `json:"-"`
2728
UpdatedAt time.Time `json:"-"`
2829
}
2930

30-
func (p PolicyDefinition) GetID() uuid.UUID {
31+
func (p PolicyDefinition) GetID() core.Uuid {
3132
return p.ID
3233
}
3334

34-
func (p *PolicyDefinition) GenerateID() (uuid.UUID, error) {
35+
func (p *PolicyDefinition) GenerateID() (core.Uuid, error) {
3536
return uuid.NewV4()
3637
}
3738

@@ -43,17 +44,17 @@ func (p *PolicyDefinition) GetEntityDetail() string {
4344
return fmt.Sprintf("type: %s, definition version: %s, name: %s, model: %s, version: %s", p.Type(), p.Version, p.Kind, p.Model.Name, p.Model.Version)
4445
}
4546

46-
func (p *PolicyDefinition) Create(db *database.Handler, hostID uuid.UUID) (uuid.UUID, error) {
47+
func (p *PolicyDefinition) Create(db *database.Handler, hostID core.Uuid) (core.Uuid, error) {
4748
p.ID, _ = p.GenerateID()
4849

4950
mid, err := p.Model.Create(db, hostID)
5051
if err != nil {
51-
return uuid.UUID{}, err
52+
return core.Uuid{}, err
5253
}
5354
p.ModelID = mid
5455
err = db.Omit(clause.Associations).Create(&p).Error
5556
if err != nil {
56-
return uuid.UUID{}, err
57+
return core.Uuid{}, err
5758
}
5859
return p.ID, nil
5960
}

models/meshmodel/entity/types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package entity
22

33
import (
4-
"github.com/gofrs/uuid"
54
"github.com/meshery/meshkit/database"
5+
core "github.com/meshery/schemas/models/core"
66
)
77

88
type EntityType string
@@ -27,7 +27,7 @@ type Entity interface {
2727
// ComponentDefinitions and PolicyDefinitions are examples of entities
2828
Type() EntityType
2929
GetEntityDetail() string
30-
GenerateID() (uuid.UUID, error)
31-
GetID() uuid.UUID
32-
Create(db *database.Handler, hostID uuid.UUID) (entityID uuid.UUID, err error)
30+
GenerateID() (core.Uuid, error)
31+
GetID() core.Uuid
32+
Create(db *database.Handler, hostID core.Uuid) (entityID core.Uuid, err error)
3333
}

models/meshmodel/registry/registry.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/gofrs/uuid"
1010
"github.com/meshery/meshkit/database"
11+
core "github.com/meshery/schemas/models/core"
1112
models "github.com/meshery/meshkit/models/meshmodel/core/v1beta1"
1213
"github.com/meshery/meshkit/models/meshmodel/entity"
1314
"github.com/meshery/schemas/models/v1alpha3/relationship"
@@ -70,9 +71,9 @@ func (c *RegistryEntityCache) Set(f entity.Filter, value EntityCacheValue) {
7071
}
7172

7273
type Registry struct {
73-
ID uuid.UUID
74-
RegistrantID uuid.UUID
75-
Entity uuid.UUID
74+
ID core.Uuid
75+
RegistrantID core.Uuid
76+
Entity core.Uuid
7677
Type entity.EntityType
7778
CreatedAt time.Time
7879
UpdatedAt time.Time

0 commit comments

Comments
 (0)