Skip to content

Commit 47dd315

Browse files
uc-build-userg-woss-gh
authored andcommitted
Sync monorepo state at 6d9a89fb46c870952be0a85ab7d02c9dc0e83c5b
1 parent 4241d71 commit 47dd315

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+684
-434
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Changelog
22

3+
## 1.6.0 - 12-09-2024
4+
5+
- add ObjectStore CRUD methods
6+
- add Truncated flag to ExecuteAccessorResponse
7+
- add Version to Transformer
8+
- add UpdateTransformerRequest
9+
- add GetTransformerByVersion method
10+
- add UpdateTransformer method
11+
- add SearchIndexed and AccessPolicy to Column
12+
- add TokenAccessPolicy to ColumnOutputConfig
13+
- add AreColumnAccessPoliciesOverridden, IsAutoGenerated, UseSearchIndex to Accessor
14+
- add Schemas to ColumnInputConfig
15+
- add ShimObjectStore
16+
- client cache improvements
17+
- logging improvements
18+
- add onprem region and universe
19+
320
## 1.5.0 - 30-07-2024
421

522
- Update userstore sample to exercise multi-key execute accessor pagination

authz/cache_name_provider.go

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

33
import (
4+
"context"
45
"fmt"
56
"time"
67

78
"github.com/gofrs/uuid"
89

910
"userclouds.com/infra/cache"
11+
"userclouds.com/infra/uclog"
1012
)
1113

1214
const (
@@ -329,7 +331,11 @@ func (ot ObjectType) GetGlobalCollectionPagesKey(c cache.KeyNameProvider) cache.
329331

330332
// GetSecondaryKeys returns the secondary cache key names for object type
331333
func (ot ObjectType) GetSecondaryKeys(c cache.KeyNameProvider) []cache.Key {
332-
return []cache.Key{c.GetKeyNameWithString(ObjectTypeNameKeyID, ot.TypeName)}
334+
if ot.TypeName != "" {
335+
return []cache.Key{c.GetKeyNameWithString(ObjectTypeNameKeyID, ot.TypeName)}
336+
}
337+
uclog.Verbosef(context.Background(), "ObjectType %v has no name. Dropping secondary key", ot.ID)
338+
return []cache.Key{}
333339
}
334340

335341
// GetPerItemCollectionKey returns the per item collection key name for object type
@@ -384,7 +390,11 @@ func (et EdgeType) GetPerItemCollectionKey(c cache.KeyNameProvider) cache.Key {
384390

385391
// GetSecondaryKeys returns the secondary cache key names for edge type
386392
func (et EdgeType) GetSecondaryKeys(c cache.KeyNameProvider) []cache.Key {
387-
return []cache.Key{c.GetKeyNameWithString(EdgeTypeNameKeyID, et.TypeName)}
393+
if et.TypeName != "" {
394+
return []cache.Key{c.GetKeyNameWithString(EdgeTypeNameKeyID, et.TypeName)}
395+
}
396+
uclog.Verbosef(context.Background(), "EdgeType %v has no name. Dropping secondary key", et.ID)
397+
return []cache.Key{}
388398
}
389399

390400
// GetDependenciesKey returns the dependencies key name for edge type
@@ -510,7 +520,11 @@ func (e Edge) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
510520

511521
// GetSecondaryKeys returns the secondary cache key names for edge
512522
func (e Edge) GetSecondaryKeys(c cache.KeyNameProvider) []cache.Key {
513-
return []cache.Key{c.GetKeyName(EdgeFullKeyID, []string{e.SourceObjectID.String(), e.TargetObjectID.String(), e.EdgeTypeID.String()})}
523+
if !e.SourceObjectID.IsNil() || !e.TargetObjectID.IsNil() || !e.EdgeTypeID.IsNil() {
524+
return []cache.Key{c.GetKeyName(EdgeFullKeyID, []string{e.SourceObjectID.String(), e.TargetObjectID.String(), e.EdgeTypeID.String()})}
525+
}
526+
uclog.Verbosef(context.Background(), "Edge %v has no source, target or edge type. Dropping secondary key", e.ID)
527+
return []cache.Key{}
514528
}
515529

516530
// TTL returns the TTL for edge
@@ -614,7 +628,11 @@ func (o Organization) GetDependencyKeys(c cache.KeyNameProvider) []cache.Key {
614628

615629
// GetSecondaryKeys returns the secondary cache key names for organization (none)
616630
func (o Organization) GetSecondaryKeys(c cache.KeyNameProvider) []cache.Key {
617-
return []cache.Key{c.GetKeyNameWithString(OrganizationNameKeyID, o.Name)}
631+
if o.Name != "" {
632+
return []cache.Key{c.GetKeyNameWithString(OrganizationNameKeyID, o.Name)}
633+
}
634+
uclog.Verbosef(context.Background(), "Organization %v has no name. Dropping secondary key", o.ID)
635+
return []cache.Key{}
618636
}
619637

620638
// TTL returns the TTL for edge

authz/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func (c *Client) ListEdgeTypes(ctx context.Context, opts ...Option) ([]EdgeType,
643643

644644
for {
645645
query := pager.Query()
646-
if options.organizationID != uuid.Nil {
646+
if !options.organizationID.IsNil() {
647647
query.Add("organization_id", options.organizationID.String())
648648
}
649649

@@ -687,7 +687,7 @@ func (c *Client) ListEdgeTypesPaginated(ctx context.Context, opts ...Option) (*L
687687

688688
query := pager.Query()
689689

690-
if options.organizationID != uuid.Nil {
690+
if !options.organizationID.IsNil() {
691691
query.Add("organization_id", options.organizationID.String())
692692
}
693693

@@ -957,7 +957,7 @@ func (c *Client) ListObjects(ctx context.Context, opts ...Option) (*ListObjectsR
957957
return nil, ucerr.Wrap(err)
958958
}
959959
query := pager.Query()
960-
if options.organizationID != uuid.Nil {
960+
if !options.organizationID.IsNil() {
961961
query.Add("organization_id", options.organizationID.String())
962962
}
963963
return c.ListObjectsFromQuery(ctx, query, opts...)
@@ -971,7 +971,7 @@ func (c *Client) ListObjectsFromQuery(ctx context.Context, query url.Values, opt
971971
for _, opt := range opts {
972972
opt.apply(&options)
973973
}
974-
if options.organizationID != uuid.Nil {
974+
if !options.organizationID.IsNil() {
975975
query.Add("organization_id", options.organizationID.String())
976976
}
977977

@@ -1559,7 +1559,7 @@ func (c *Client) GetOrganizationForName(ctx context.Context, name string, opts .
15591559
}
15601560

15611561
pager, err := pagination.ApplyOptions(
1562-
pagination.Filter("('name',EQ,'testorg')"),
1562+
pagination.Filter(fmt.Sprintf("('name',EQ,'%s')", name)),
15631563
)
15641564
if err != nil {
15651565
return nil, ucerr.Wrap(err)

authz/models.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/gofrs/uuid"
88

99
"userclouds.com/infra/namespace/region"
10-
"userclouds.com/infra/pagination"
1110
"userclouds.com/infra/ucdb"
1211
"userclouds.com/infra/ucerr"
1312
)
@@ -19,16 +18,6 @@ type ObjectType struct {
1918
TypeName string `db:"type_name" json:"type_name" validate:"notempty" required:"true"`
2019
}
2120

22-
// GetPaginationKeys is part of the pagination.PageableType interface
23-
func (ObjectType) GetPaginationKeys() pagination.KeyTypes {
24-
return pagination.KeyTypes{
25-
"id": pagination.UUIDKeyType,
26-
"type_name": pagination.StringKeyType,
27-
"created": pagination.TimestampKeyType,
28-
"updated": pagination.TimestampKeyType,
29-
}
30-
}
31-
3221
// EqualsIgnoringID returns true if two object types are equal, ignoring the ID field
3322
func (ot *ObjectType) EqualsIgnoringID(other *ObjectType) bool {
3423
return ot.TypeName == other.TypeName
@@ -140,19 +129,6 @@ func (e *EdgeType) EqualsIgnoringID(other *EdgeType) bool {
140129

141130
//go:generate genvalidate EdgeType
142131

143-
// GetPaginationKeys is part of the pagination.PageableType interface
144-
func (EdgeType) GetPaginationKeys() pagination.KeyTypes {
145-
return pagination.KeyTypes{
146-
"id": pagination.UUIDKeyType,
147-
"type_name": pagination.StringKeyType,
148-
"organization_id": pagination.UUIDKeyType,
149-
"source_object_type_id": pagination.UUIDKeyType,
150-
"target_object_type_id": pagination.UUIDKeyType,
151-
"created": pagination.TimestampKeyType,
152-
"updated": pagination.TimestampKeyType,
153-
}
154-
}
155-
156132
// Object represents an instance of an AuthZ object used for modeling permissions.
157133
type Object struct {
158134
ucdb.BaseModel
@@ -176,18 +152,6 @@ func (o *Object) EqualsIgnoringID(other *Object) bool {
176152

177153
//go:generate genvalidate Object
178154

179-
// GetPaginationKeys is part of the pagination.PageableType interface
180-
func (Object) GetPaginationKeys() pagination.KeyTypes {
181-
return pagination.KeyTypes{
182-
"id": pagination.UUIDKeyType,
183-
"alias": pagination.StringKeyType,
184-
"organization_id": pagination.UUIDKeyType,
185-
"type_id": pagination.UUIDKeyType,
186-
"created": pagination.TimestampKeyType,
187-
"updated": pagination.TimestampKeyType,
188-
}
189-
}
190-
191155
// Edge represents a directional relationship between a "source"
192156
// object and a "target" object.
193157
type Edge struct {
@@ -207,17 +171,6 @@ func (e *Edge) EqualsIgnoringID(other *Edge) bool {
207171

208172
//go:generate genvalidate Edge
209173

210-
// GetPaginationKeys is part of the pagination.PageableType interface
211-
func (Edge) GetPaginationKeys() pagination.KeyTypes {
212-
return pagination.KeyTypes{
213-
"id": pagination.UUIDKeyType,
214-
"source_object_id": pagination.UUIDKeyType,
215-
"target_object_id": pagination.UUIDKeyType,
216-
"created": pagination.TimestampKeyType,
217-
"updated": pagination.TimestampKeyType,
218-
}
219-
}
220-
221174
// Organization defines a collection of objects inside of a single AuthZ namespace.
222175
// Uniqueness (of eg. Object aliases) is enforced by organization, rather than globally in a tenant
223176
type Organization struct {
@@ -229,16 +182,6 @@ type Organization struct {
229182

230183
//go:generate genvalidate Organization
231184

232-
// GetPaginationKeys is part of the pagination.PageableType interface
233-
func (Organization) GetPaginationKeys() pagination.KeyTypes {
234-
return pagination.KeyTypes{
235-
"id": pagination.UUIDKeyType,
236-
"name": pagination.StringKeyType,
237-
"created": pagination.TimestampKeyType,
238-
"updated": pagination.TimestampKeyType,
239-
}
240-
}
241-
242185
//go:generate genvalidate CreateObjectTypeRequest
243186

244187
//go:generate genvalidate CreateEdgeTypeRequest

idp/client.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,106 @@ func (c *Client) UpdateDatabase(ctx context.Context, databaseID uuid.UUID, updat
358358
return &resp, nil
359359
}
360360

361+
// CreateObjectStoreRequest is the request body for creating a new object store
362+
type CreateObjectStoreRequest struct {
363+
ObjectStore userstore.ShimObjectStore `json:"objectStore"`
364+
}
365+
366+
//go:generate genvalidate CreateObjectStoreRequest
367+
368+
// CreateObjectStore creates a new sqlshim object store for the tenant
369+
func (c *Client) CreateObjectStore(ctx context.Context, objectStore userstore.ShimObjectStore, opts ...Option) (*userstore.ShimObjectStore, error) {
370+
options := c.options
371+
for _, opt := range opts {
372+
opt.apply(&options)
373+
}
374+
375+
req := CreateObjectStoreRequest{
376+
ObjectStore: objectStore,
377+
}
378+
379+
var resp userstore.ShimObjectStore
380+
if options.ifNotExists {
381+
exists, existingID, err := c.client.CreateIfNotExists(ctx, paths.CreateObjectStorePath, req, &resp)
382+
if err != nil {
383+
return nil, ucerr.Wrap(err)
384+
}
385+
if exists {
386+
resp = req.ObjectStore
387+
resp.ID = existingID
388+
}
389+
} else {
390+
if err := c.client.Post(ctx, paths.CreateObjectStorePath, req, &resp); err != nil {
391+
return nil, ucerr.Wrap(err)
392+
}
393+
}
394+
395+
return &resp, nil
396+
}
397+
398+
// DeleteObjectStore deletes the object store specified by the object store ID for the associated tenant
399+
func (c *Client) DeleteObjectStore(ctx context.Context, objectStoreID uuid.UUID) error {
400+
return ucerr.Wrap(c.client.Delete(ctx, paths.DeleteObjectStorePath(objectStoreID), nil))
401+
}
402+
403+
// GetObjectStore returns the object store specified by the object store ID for the associated tenant
404+
func (c *Client) GetObjectStore(ctx context.Context, objectStoreID uuid.UUID) (*userstore.ShimObjectStore, error) {
405+
var resp userstore.ShimObjectStore
406+
if err := c.client.Get(ctx, paths.GetObjectStorePath(objectStoreID), &resp); err != nil {
407+
return nil, ucerr.Wrap(err)
408+
}
409+
410+
return &resp, nil
411+
}
412+
413+
// ListObjectStoresResponse is the paginated response struct for listing object stores
414+
type ListObjectStoresResponse struct {
415+
Data []userstore.ShimObjectStore `json:"data"`
416+
pagination.ResponseFields
417+
}
418+
419+
// ListObjectStores lists all object stores for the associated tenant
420+
func (c *Client) ListObjectStores(ctx context.Context, opts ...Option) (*ListObjectStoresResponse, error) {
421+
options := c.options
422+
for _, opt := range opts {
423+
opt.apply(&options)
424+
}
425+
426+
pager, err := pagination.ApplyOptions(options.paginationOptions...)
427+
if err != nil {
428+
return nil, ucerr.Wrap(err)
429+
}
430+
431+
query := pager.Query()
432+
var res ListObjectStoresResponse
433+
if err := c.client.Get(ctx, fmt.Sprintf("%s?%s", paths.ObjectStorePath, query.Encode()), &res); err != nil {
434+
return nil, ucerr.Wrap(err)
435+
}
436+
437+
return &res, nil
438+
}
439+
440+
// UpdateObjectStoreRequest is the request body for updating a object store
441+
type UpdateObjectStoreRequest struct {
442+
ObjectStore userstore.ShimObjectStore `json:"objectStore"`
443+
}
444+
445+
//go:generate genvalidate UpdateObjectStoreRequest
446+
447+
// UpdateObjectStore updates the object store specified by the object store ID with the specified data for the associated tenant
448+
func (c *Client) UpdateObjectStore(ctx context.Context, objectStoreID uuid.UUID, updatedObjectStore userstore.ShimObjectStore) (*userstore.ShimObjectStore, error) {
449+
req := UpdateObjectStoreRequest{
450+
ObjectStore: updatedObjectStore,
451+
}
452+
453+
var resp userstore.ShimObjectStore
454+
if err := c.client.Put(ctx, paths.UpdateObjectStorePath(objectStoreID), req, &resp); err != nil {
455+
return nil, ucerr.Wrap(err)
456+
}
457+
458+
return &resp, nil
459+
}
460+
361461
// CreateDataTypeRequest is the request body for creating a new data type
362462
type CreateDataTypeRequest struct {
363463
DataType userstore.ColumnDataType `json:"data_type"`
@@ -1176,6 +1276,8 @@ type ExecuteAccessorRequest struct {
11761276
type ExecuteAccessorResponse struct {
11771277
Data []string `json:"data"`
11781278
Debug map[string]interface{} `json:"debug,omitempty"`
1279+
// TODO: Truncated will need to be added to our python SDK if we keep it
1280+
Truncated bool `json:"truncated" description:"Will be true if an incomplete set of results could be returned for the query"`
11791281
pagination.ResponseFields
11801282
}
11811283

idp/paths/paths.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ var (
2727
UpdateDatabasePath = singleDatabasePath
2828
DeleteDatabasePath = singleDatabasePath
2929

30+
ObjectStorePath = fmt.Sprintf("%s/objectstores", BaseConfigPath)
31+
CreateObjectStorePath = ObjectStorePath
32+
ListObjectStoresPath = ObjectStorePath
33+
singleObjectStorePath = func(id uuid.UUID) string { return fmt.Sprintf("%s/%s", ObjectStorePath, id) }
34+
GetObjectStorePath = singleObjectStorePath
35+
UpdateObjectStorePath = singleObjectStorePath
36+
DeleteObjectStorePath = singleObjectStorePath
37+
3038
BaseConfigColumnsPath = fmt.Sprintf("%s/columns", BaseConfigPath)
3139
singleConfigColumnPath = func(id uuid.UUID) string {
3240
return fmt.Sprintf("%s/%s", BaseConfigColumnsPath, id)
@@ -156,7 +164,14 @@ var (
156164
GetTransformer = func(id uuid.UUID) string {
157165
return fmt.Sprintf("%s/%s", BaseTransformerPath, id)
158166
}
167+
GetTransformerByVersion = func(id uuid.UUID, version int) string {
168+
return fmt.Sprintf("%s/%s?transformer_version=%d", BaseTransformerPath, id, version)
169+
}
170+
GetTransformerByNameAndVersion = func(name string, version int) string {
171+
return fmt.Sprintf("%s?transformer_name=%s&transformer_version=%d", BaseTransformerPath, name, version)
172+
}
159173
CreateTransformer = BaseTransformerPath
174+
UpdateTransformer = func(id uuid.UUID) string { return fmt.Sprintf("%s/%s", BaseTransformerPath, id) }
160175
DeleteTransformer = func(id uuid.UUID) string { return fmt.Sprintf("%s/%s", BaseTransformerPath, id) }
161176
TestTransformer = fmt.Sprintf("%s/actions/test", BaseTransformerPath)
162177
ExecuteTransformer = fmt.Sprintf("%s/actions/execute", BaseTransformerPath)

0 commit comments

Comments
 (0)