Skip to content

Commit

Permalink
fixed: sharding strategy for OIDCSources and HTTPSources
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Mercadal committed Jan 20, 2022
1 parent 6a2b8c2 commit de45bb0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
10 changes: 10 additions & 0 deletions internal/hasher/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ func (t *Hasher) Hash(z sharder.Shardable) error {
case *api.SparseLDAPSource:
z.SetZHash(hash(fmt.Sprintf("%s:%s", *oo.Namespace, *oo.Name)))

case *api.OIDCSource:
z.SetZHash(hash(fmt.Sprintf("%s:%s", oo.Namespace, oo.Name)))
case *api.SparseOIDCSource:
z.SetZHash(hash(fmt.Sprintf("%s:%s", *oo.Namespace, *oo.Name)))

case *api.HTTPSource:
z.SetZHash(hash(fmt.Sprintf("%s:%s", oo.Namespace, oo.Name)))
case *api.SparseHTTPSource:
z.SetZHash(hash(fmt.Sprintf("%s:%s", *oo.Namespace, *oo.Name)))

case *api.A3SSource:
z.SetZHash(hash(fmt.Sprintf("%s:%s", oo.Namespace, oo.Name)))
case *api.SparseA3SSource:
Expand Down
34 changes: 33 additions & 1 deletion internal/hasher/hasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.aporeto.io/a3s/pkgs/api"
)

func TestShard(t *testing.T) {
func TestHash(t *testing.T) {

Convey("Given I have a hasher", t, func() {

Expand Down Expand Up @@ -76,6 +76,38 @@ func TestShard(t *testing.T) {
So(o.ZHash, ShouldEqual, hash(fmt.Sprintf("%s:%s", aString, aString)))
})

Convey("Then sharding an OIDCSource should work", func() {
o := api.NewOIDCSource()
o.Namespace = aString
o.Name = aString
So(s.Hash(o), ShouldBeNil)
So(o.Zone, ShouldEqual, 0)
So(o.ZHash, ShouldEqual, hash(fmt.Sprintf("%s:%s", aString, aString)))

so := api.NewSparseOIDCSource()
so.Namespace = &aString
so.Name = &aString
So(s.Hash(so), ShouldBeNil)
So(*so.Zone, ShouldEqual, 0)
So(o.ZHash, ShouldEqual, hash(fmt.Sprintf("%s:%s", aString, aString)))
})

Convey("Then sharding an HTTPSource should work", func() {
o := api.NewHTTPSource()
o.Namespace = aString
o.Name = aString
So(s.Hash(o), ShouldBeNil)
So(o.Zone, ShouldEqual, 0)
So(o.ZHash, ShouldEqual, hash(fmt.Sprintf("%s:%s", aString, aString)))

so := api.NewSparseHTTPSource()
so.Namespace = &aString
so.Name = &aString
So(s.Hash(so), ShouldBeNil)
So(*so.Zone, ShouldEqual, 0)
So(o.ZHash, ShouldEqual, hash(fmt.Sprintf("%s:%s", aString, aString)))
})

Convey("Then sharding an A3SSource should work", func() {
o := api.NewA3SSource()
o.Namespace = aString
Expand Down

0 comments on commit de45bb0

Please sign in to comment.