Skip to content

Commit

Permalink
relationships
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Siwiec <[email protected]>
  • Loading branch information
rizzza committed Aug 25, 2023
1 parent 900a9ab commit ba9529f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
go.infratographer.com/permissions-api v0.2.4
go.infratographer.com/x v0.3.7
go.uber.org/zap v1.25.0
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
)

require (
Expand Down Expand Up @@ -138,6 +137,7 @@ require (
go.step.sm/crypto v0.31.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E=
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
Expand Down Expand Up @@ -400,6 +401,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sebdah/goldie/v2 v2.5.3 h1:9ES/mNN+HNUbNWpVAlrzuZ7jE+Nrczbj8uFRjM7624Y=
Expand Down Expand Up @@ -448,6 +451,9 @@ github.com/testcontainers/testcontainers-go v0.21.0 h1:syePAxdeTzfkap+RrJaQZpJQ/
github.com/testcontainers/testcontainers-go v0.21.0/go.mod h1:c1ez3WVRHq7T/Aj+X3TIipFBwkBaNT5iNCY8+1b83Ng=
github.com/testcontainers/testcontainers-go/modules/postgres v0.21.0 h1:rFPyTR7pPMiHcDktXwd5iZ+mA1cHH/WRa+knxBcY8wU=
github.com/testcontainers/testcontainers-go/modules/postgres v0.21.0/go.mod h1:Uoia8PX1RewxkJTbeXGBK6vgMjlmRbnL/4n0EXH2Z54=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
Expand All @@ -463,6 +469,8 @@ github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vb
github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/wundergraph/graphql-go-tools v1.62.3 h1:WKpkhKqWoTq/AE0AbrZ+66ezUe3l/wAqZZurZeL5qqQ=
github.com/wundergraph/graphql-go-tools v1.62.3/go.mod h1:Lsg/b4nVfNQLyJE1mjPV73O/JuhhCxH5qmaWQjitVHM=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
4 changes: 3 additions & 1 deletion internal/ent/entc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func main() {
log.Fatalf("creating entx extension: %v", err)
}

pubsubExt, err := pubsubinfo.NewExtension()
pubsubExt, err := pubsubinfo.NewExtension(
pubsubinfo.WithEventHooks(),
)
if err != nil {
log.Fatalf("creating pubsubinfo extension: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ent/schema/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (Origin) Fields() []ent.Field {
Annotations(
entgql.Type("ID"),
entgql.Skip(entgql.SkipWhereInput, entgql.SkipMutationUpdateInput),
pubsubinfo.EventsHookAdditionalSubject("loadbalancerorigin"),
pubsubinfo.EventsHookAdditionalSubject("pool"),
),
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ent/schema/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (Pool) Fields() []ent.Field {
Annotations(
entgql.Type("ID"),
entgql.Skip(entgql.SkipWhereInput, entgql.SkipMutationUpdateInput),
pubsubinfo.EventsHookAdditionalSubject("loadbalancerpool"),
pubsubinfo.EventsHookAdditionalSubject("owner"),
),
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ent/schema/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (Port) Fields() []ent.Field {
Annotations(
entgql.Type("ID"),
entgql.Skip(entgql.SkipWhereInput, entgql.SkipMutationUpdateInput),
pubsubinfo.EventsHookAdditionalSubject("loadbalancer"),
// pubsubinfo.EventsHookAdditionalSubject("loadbalancer"),
),
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/ent/schema/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"entgo.io/ent/schema/index"
"go.infratographer.com/x/entx"
"go.infratographer.com/x/gidx"

"go.infratographer.com/load-balancer-api/x/pubsubinfo"
)

// Provider holds the schema definition for the LoadBalancerProvider entity.
Expand Down Expand Up @@ -51,6 +53,7 @@ func (Provider) Fields() []ent.Field {
entgql.Type("ID"),
entgql.Skip(entgql.SkipWhereInput, entgql.SkipMutationUpdateInput, entgql.SkipType),
entgql.OrderField("OWNER"),
pubsubinfo.EventsHookAdditionalSubject("owner"),
),
}
}
Expand Down
29 changes: 9 additions & 20 deletions internal/manualhooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func OriginHooks() []ent.Hook {
additionalSubjects = append(additionalSubjects, pool_id)

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancerorigin",
Relation: "pool",
SubjectID: pool_id,
})

Expand Down Expand Up @@ -541,15 +541,8 @@ func OriginHooks() []ent.Hook {

additionalSubjects = append(additionalSubjects, dbObj.PoolID)

addSubjPort, err := m.Client().Port.Query().Where(port.HasPoolsWith(pool.HasOriginsWith(origin.IDEQ(objID)))).Only(ctx)
if err == nil {
if !slices.Contains(additionalSubjects, addSubjPort.LoadBalancerID) {
additionalSubjects = append(additionalSubjects, addSubjPort.LoadBalancerID)
}
}

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancerorigin",
Relation: "pool",
SubjectID: dbObj.PoolID,
})

Expand Down Expand Up @@ -721,7 +714,7 @@ func PoolHooks() []ent.Hook {
additionalSubjects = append(additionalSubjects, owner_id)

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancerpool",
Relation: "owner",
SubjectID: owner_id,
})

Expand Down Expand Up @@ -801,7 +794,7 @@ func PoolHooks() []ent.Hook {
additionalSubjects = append(additionalSubjects, dbObj.OwnerID)

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancerpool",
Relation: "owner",
SubjectID: dbObj.OwnerID,
})

Expand Down Expand Up @@ -975,11 +968,6 @@ func PortHooks() []ent.Hook {
}
additionalSubjects = append(additionalSubjects, load_balancer_id)

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancer",
SubjectID: load_balancer_id,
})

if ok {
cv_load_balancer_id = fmt.Sprintf("%s", fmt.Sprint(load_balancer_id))
pv_load_balancer_id := ""
Expand Down Expand Up @@ -1048,10 +1036,10 @@ func PortHooks() []ent.Hook {

additionalSubjects = append(additionalSubjects, dbObj.LoadBalancerID)

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancer",
SubjectID: dbObj.LoadBalancerID,
})
// relationships = append(relationships, events.AuthRelationshipRelation{
// Relation: "owner",
// SubjectID: dbObj,
// })

addSubjLoadBalancer, err := m.Client().LoadBalancer.Get(ctx, dbObj.LoadBalancerID)
if err != nil {
Expand Down Expand Up @@ -1108,6 +1096,7 @@ func PubsubHooks(c *generated.Client) {
c.Pool.Use(PoolHooks()...)

c.Port.Use(PortHooks()...)

}

func eventType(op ent.Op) string {
Expand Down

0 comments on commit ba9529f

Please sign in to comment.