Skip to content

Commit c63fd8f

Browse files
v-fedorov-ghstgarrity
authored andcommitted
SDK update with retries and caching
1 parent 7e4161f commit c63fd8f

25 files changed

+1138
-517
lines changed

authz/client.go

Lines changed: 480 additions & 193 deletions
Large diffs are not rendered by default.

authz/constants.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package authz
22

3-
import "github.com/gofrs/uuid"
3+
import (
4+
"github.com/gofrs/uuid"
5+
6+
"userclouds.com/infra/ucdb"
7+
)
48

59
// AuthZ object types & edge types (roles) provisioned for every tenant.
610
// TODO: merge the string constant with the UUID into a const-ish struct to keep them associated,
711
// particularly if we add more of these.
812
// Keep in sync with TSX constants!
913
// TODO: we should have a better way to sync constants between TS and Go
1014
const (
11-
GroupObjectType = "_group"
12-
UserObjectType = "_user"
13-
AdminRole = "_admin"
14-
MemberRole = "_member"
15+
ObjectTypeUser = "_user"
16+
ObjectTypeGroup = "_group"
1517
)
1618

1719
// UserObjectTypeID is the ID of a built-in object type called "_user"
@@ -20,8 +22,8 @@ var UserObjectTypeID = uuid.Must(uuid.FromString("1bf2b775-e521-41d3-8b7e-78e894
2022
// GroupObjectTypeID is the ID of a built-in object type called "_group"
2123
var GroupObjectTypeID = uuid.Must(uuid.FromString("f5bce640-f866-4464-af1a-9e7474c4a90c"))
2224

23-
// AdminRoleTypeID is the ID of a built-in edge type called "_admin"
24-
var AdminRoleTypeID = uuid.Must(uuid.FromString("60b69666-4a8a-4eb3-94dd-621298fb365d"))
25-
26-
// MemberRoleTypeID is the ID of a built-in edge type called "_member"
27-
var MemberRoleTypeID = uuid.Must(uuid.FromString("1eec16ec-6130-4f9e-a51f-21bc19b20d8f"))
25+
// RBACAuthZObjectTypes is an array containing default AuthZ object types
26+
var RBACAuthZObjectTypes = []ObjectType{
27+
{BaseModel: ucdb.NewBaseWithID(UserObjectTypeID), TypeName: ObjectTypeUser},
28+
{BaseModel: ucdb.NewBaseWithID(GroupObjectTypeID), TypeName: ObjectTypeGroup},
29+
}

authz/models.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ type EdgeType struct {
8080
SourceObjectTypeID uuid.UUID `db:"source_object_type_id,immutable" json:"source_object_type_id" validate:"notnil"`
8181
TargetObjectTypeID uuid.UUID `db:"target_object_type_id,immutable" json:"target_object_type_id" validate:"notnil"`
8282
Attributes Attributes `db:"attributes" json:"attributes"`
83+
84+
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
8385
}
8486

8587
//go:generate genvalidate EdgeType
@@ -88,8 +90,10 @@ type EdgeType struct {
8890
type Object struct {
8991
ucdb.BaseModel
9092

91-
Alias string `db:"alias" json:"alias" validate:"notempty"`
93+
Alias *string `db:"alias" json:"alias,omitempty" validate:"allownil"`
9294
TypeID uuid.UUID `db:"type_id,immutable" json:"type_id" validate:"notnil"`
95+
96+
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
9397
}
9498

9599
//go:generate genvalidate Object
@@ -114,3 +118,13 @@ type Edge struct {
114118
type UserObject struct {
115119
ucdb.BaseModel
116120
}
121+
122+
// Organization defines a collection of objects inside of a single AuthZ namespace.
123+
// Uniqueness (of eg. Object aliases) is enforced by organization, rather than globally in a tenant
124+
type Organization struct {
125+
ucdb.BaseModel
126+
127+
Name string `db:"name" json:"name" validate:"notempty"`
128+
}
129+
130+
//go:generate genvalidate Organization

authz/object_validate_generated.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ func (o *Object) Validate() error {
1313
if err := o.BaseModel.Validate(); err != nil {
1414
return ucerr.Wrap(err)
1515
}
16-
if o.Alias == "" {
17-
return ucerr.Errorf("Object.Alias (%v) can't be empty", o.ID)
18-
}
1916
if o.TypeID == uuid.Nil {
2017
return ucerr.Errorf("Object.TypeID (%v) can't be nil", o.ID)
2118
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ require (
66
github.com/gofrs/uuid v4.0.0+incompatible
77
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
88
github.com/joho/godotenv v1.4.0 // indirect
9+
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
910
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keL
44
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
55
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
66
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
7+
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
8+
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=

0 commit comments

Comments
 (0)