Skip to content

Commit 4241d71

Browse files
uc-build-userg-woss-gh
authored andcommitted
Sync monorepo state at 11b980faba6eb53dad59c54e0d9ac11204ce5b01
1 parent eb90563 commit 4241d71

File tree

11 files changed

+216
-47
lines changed

11 files changed

+216
-47
lines changed

CHANGELOG.md

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

3+
## 1.5.0 - 30-07-2024
4+
5+
- Update userstore sample to exercise multi-key execute accessor pagination
6+
37
## 1.4.0 - 18-07-2024
48

59
- Deprecate v1.0.0 and v1.1.0

idp/policy/models.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ func (a AccessPolicy) extraValidate() error {
230230
return ucerr.Friendlyf(nil, `Access policy name "%s" has invalid characters`, a.Name)
231231
}
232232

233+
if len(a.Components) == 0 {
234+
return ucerr.New("AccessPolicy must have at least one component")
235+
}
236+
233237
return nil
234238
}
235239

idp/userstore/types.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,18 @@ const (
135135
// in the user data store of a tenant.
136136
type Column struct {
137137
// Columns may be renamed, but their ID cannot be changed.
138-
ID uuid.UUID `json:"id"`
139-
Table string `json:"table"` // TODO (sgarrity 6/24): validate & mark as required once people update
140-
Name string `json:"name" validate:"length:1,128" required:"true"`
141-
DataType ResourceID `json:"data_type" required:"true"`
142-
Type DataType `json:"type" validate:"skip"`
143-
IsArray bool `json:"is_array" required:"true"`
144-
DefaultValue string `json:"default_value"`
145-
IndexType ColumnIndexType `json:"index_type" required:"true"`
146-
IsSystem bool `json:"is_system" description:"Whether this column is a system column. System columns cannot be deleted or modified. This property cannot be changed."`
147-
Constraints ColumnConstraints `json:"constraints" description:"Optional constraints for configuring the behavior of the associated column Type."`
138+
ID uuid.UUID `json:"id"`
139+
Table string `json:"table"` // TODO (sgarrity 6/24): validate & mark as required once people update
140+
Name string `json:"name" validate:"length:1,128" required:"true"`
141+
DataType ResourceID `json:"data_type" required:"true"`
142+
Type DataType `json:"type" validate:"skip"`
143+
IsArray bool `json:"is_array" required:"true"`
144+
DefaultValue string `json:"default_value"`
145+
DefaultTransformer ResourceID `json:"default_transformer" validate:"skip"`
146+
DefaultTokenAccessPolicy ResourceID `json:"default_token_access_policy" validate:"skip"`
147+
IndexType ColumnIndexType `json:"index_type" required:"true"`
148+
IsSystem bool `json:"is_system" description:"Whether this column is a system column. System columns cannot be deleted or modified. This property cannot be changed."`
149+
Constraints ColumnConstraints `json:"constraints" description:"Optional constraints for configuring the behavior of the associated column Type."`
148150
}
149151

150152
//go:generate genvalidate Column
@@ -238,7 +240,7 @@ func (r ResourceID) Validate() error {
238240
// ColumnOutputConfig is a struct that contains a column and the transformer to apply to that column
239241
type ColumnOutputConfig struct {
240242
Column ResourceID `json:"column"`
241-
Transformer ResourceID `json:"transformer"`
243+
Transformer ResourceID `json:"transformer" validate:"skip"`
242244
}
243245

244246
// GetRetentionTimeoutImmediateDeletion returns the immediate deletion retention timeout
@@ -348,10 +350,6 @@ func (o *Accessor) extraValidate() error {
348350
if err := ct.Column.Validate(); err != nil {
349351
return ucerr.Friendlyf(err, "Each element of Accessor.Columns (%v) must have a column ID or name", o.ID)
350352
}
351-
352-
if err := ct.Transformer.Validate(); err != nil {
353-
return ucerr.Friendlyf(err, "Each element of Accessor.Columns (%v) must have a transformer ID or name", o.ID)
354-
}
355353
}
356354

357355
if err := o.AccessPolicy.Validate(); err != nil {

infra/namespace/region/regions.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"userclouds.com/infra/ucerr"
1010
)
1111

12-
const regionEnvVar = "UC_REGION"
12+
// RegionEnvVar is the environment variable that contains the region
13+
const RegionEnvVar = "UC_REGION"
1314

1415
// MachineRegion represents a region for our systems or located
1516
type MachineRegion string
@@ -33,7 +34,7 @@ func MachineRegionsForUniverse(u universe.Universe) []MachineRegion {
3334
// Current returns the current region, or empty string
3435
// TODO: error check against known list?
3536
func Current() MachineRegion {
36-
r := os.Getenv(regionEnvVar)
37+
r := os.Getenv(RegionEnvVar)
3738
return MachineRegion(r)
3839
}
3940

infra/namespace/universe/universe.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const (
1717
)
1818

1919
// Supported universes.
20-
// NOTE: keep in sync with `enum Universe` in TSX codebase
2120
const (
2221
Undefined Universe = "undefined" // undefined universe
2322
Dev Universe = "dev" // local dev laptops

infra/pagination/options.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ func EndingBefore(cursor Cursor) Option {
5050
// For LEAF queries, KEY must be a valid result type key for type of the result being returned. Valid keys are stored
5151
// in a KeyTypes map in a configured paginator, mapping a key name to a KeyType. Supported KeyTypes include:
5252
//
53-
// ArrayKeyType (must be a string value to be searched for in an array of strings)
54-
// BoolKeyType (value may be specified as any string that can be parsed by https://pkg.go.dev/strconv#example-ParseBool)
55-
// IntKeyType (must be a valid string representation of an int64)
56-
// StringKeyType (string value can only have single-quotes or double-quotes in the string that are escaped with a
57-
// back-slash (i.e., \' or \"))
58-
// TimestampKeyType (the number of microseconds since January 1, 1970 UTC)
59-
// UUIDArrayKeyType (must be a valid string representation of a UUID)
60-
// UUIDKeyType (must be a valid string representation of a UUID)
53+
// ArrayKeyType (must be a string value to be searched for in an array of strings)
54+
// BoolKeyType (value may be specified as any string that can be parsed by https://pkg.go.dev/strconv#example-ParseBool)
55+
// IntKeyType (must be a valid string representation of an int64)
56+
// NullableBoolKeyType (value must either be unspecified (i.e., NULL) or a valid BoolKeyType
57+
// NullableIntKeyType (value must either be unspecified (i.e., NULL) or a valid IntKeyType
58+
// NullableStringKeyType (value must either be unspecified (i.e., NULL) or a valid StringKeyType
59+
// NullableTimestampKeyType (value must either be unspecified (i.e., NULL) or a valid TimestampKeyType
60+
// NullableUUIDKeyType (value must either be unspecified (i.e., NULL) or a valid UUIDKeyType
61+
// StringKeyType (string value can only have single-quotes or double-quotes in the string that are escaped with a
62+
// back-slash (i.e., \' or \"))
63+
// TimestampKeyType (the number of microseconds since January 1, 1970 UTC)
64+
// UUIDArrayKeyType (must be a valid string representation of a UUID)
65+
// UUIDKeyType (must be a valid string representation of a UUID)
6166
//
6267
// By default, all result types support "id" as a valid key of KeyType UUIDKeyType. New supported keys can be added
6368
// to a result type by defining the GetPaginationKeys() method of the PageableType interface for the result type,

infra/pagination/pager.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ type Paginator struct {
1919
hasResultType bool // set if type of result has been specified
2020
limit int // set via Limit option or defaulted to DefaultLimit
2121
sortKey Key // set via SortKey option, defaults to "id"
22-
sortOrder Order // set via SortOrder option, defaults to SortAscending
22+
sortOrder Order // set via SortOrder option, defaults to OrderAscending
2323
filter string // set via Filter option
2424
filterQuery *FilterQuery // parsed filter
2525
supportedKeys KeyTypes // set based on type of result
2626
anyDuplicateSortKeys bool // set as part of initialization and validation of sort keys
2727
anyUnsupportedSortKeys bool // set as part of initialization and validation of sort keys
28+
finalSortKeyValid bool // set as part of initialization and validation of sort keys
2829
options []Option // collection of options used to produce the Paginator
2930
version Version // the pagination request version
3031
isKeySupported func(string) bool // function that checks whether key is supported
32+
isNullableKey func(string) bool // function that checks whether key has a nullable key type
33+
isValidFinalSortKey func(string) bool // function that checks whether key is a valid final sort key
3134
keyValueValidator func(string, string) error // function that returns an error if key or value are invalid
3235
supportedKeysValidator func() error // function that returns an error if the supported keys are invalid
3336
}
@@ -39,6 +42,7 @@ func ApplyOptions(options ...Option) (*Paginator, error) {
3942
sortOrder: OrderAscending,
4043
supportedKeys: KeyTypes{},
4144
version: Version3,
45+
isNullableKey: func(string) bool { return false },
4246
}
4347

4448
for _, option := range options {
@@ -96,13 +100,20 @@ func (p *Paginator) AdvanceCursor(rf ResponseFields) bool {
96100
}
97101

98102
func (p *Paginator) classifySortKeys() {
103+
p.finalSortKeyValid = true
104+
99105
uniqueSortKeys := map[string]bool{}
100106
for _, key := range strings.Split(string(p.sortKey), ",") {
101107
if uniqueSortKeys[key] {
102108
p.anyDuplicateSortKeys = true
103-
} else if p.isKeySupported != nil {
104-
if !p.isKeySupported(key) {
105-
p.anyUnsupportedSortKeys = true
109+
} else {
110+
if p.isKeySupported != nil {
111+
if !p.isKeySupported(key) {
112+
p.anyUnsupportedSortKeys = true
113+
}
114+
}
115+
if p.isValidFinalSortKey != nil {
116+
p.finalSortKeyValid = p.isValidFinalSortKey(key)
106117
}
107118
}
108119
uniqueSortKeys[key] = true
@@ -134,11 +145,6 @@ func (p Paginator) IsForward() bool {
134145
return p.direction == DirectionForward
135146
}
136147

137-
// IsCachable returns true if the paginator is configured to be default and cached value can be returned
138-
func (p Paginator) IsCachable() bool {
139-
return p.filter == "" && p.sortKey == "id" && p.sortOrder == OrderAscending
140-
}
141-
142148
// Query converts the paginator settings into HTTP GET query parameters.
143149
func (p Paginator) Query() url.Values {
144150
query := url.Values{}
@@ -240,6 +246,10 @@ func (p Paginator) Validate() error {
240246
return ucerr.Errorf("specified sort key contains duplicate keys: %v", p.sortKey)
241247
}
242248

249+
if !p.finalSortKeyValid {
250+
return ucerr.Errorf("final sort key must be 'id', which is guaranteed to be non-nil and unique: %v", p.sortKey)
251+
}
252+
243253
if p.filter != "" {
244254
if p.filterQuery == nil {
245255
return ucerr.Errorf("could not successfully parse filter '%s'", p.filter)

infra/pagination/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ type QueryParams struct {
6464
EndingBefore *string `description:"A cursor value before which the returned list will end" query:"ending_before"`
6565
Limit *string `description:"The maximum number of results to be returned per page" query:"limit"`
6666
Filter *string `description:"A filter clause to use in the pagination query" query:"filter"`
67-
SortKey *string `description:"The field(s) used to sort the results" query:"sort_key"`
68-
SortOrder *string `description:"The sort order for each field (ascending or descending)" query:"sort_order"`
67+
SortKey *string `description:"A comma-delimited list of field names to sort the returned results by - the last field name must be 'id'" query:"sort_key"`
68+
SortOrder *string `description:"The order in which results should be sorted (ascending or descending)" query:"sort_order"`
6969
Version *string `description:"The version of the API to be called" query:"version"`
7070
}
7171

infra/pagination/types.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ type KeyType string
2929

3030
// Valid KeyTypes
3131
const (
32-
ArrayKeyType KeyType = "Array"
33-
BoolKeyType KeyType = "Boolean"
34-
IntKeyType KeyType = "Int"
35-
StringKeyType KeyType = "String"
36-
TimestampKeyType KeyType = "Timestamp"
37-
UUIDArrayKeyType KeyType = "UUIDArray"
38-
UUIDKeyType KeyType = "UUID"
32+
ArrayKeyType KeyType = "Array"
33+
BoolKeyType KeyType = "Boolean"
34+
IntKeyType KeyType = "Int"
35+
NullableBoolKeyType KeyType = "NullableBoolean"
36+
NullableIntKeyType KeyType = "NullableInt"
37+
NullableStringKeyType KeyType = "NullableString"
38+
NullableTimestampKeyType KeyType = "NullableTimestamp"
39+
NullableUUIDKeyType KeyType = "NullableUUID"
40+
StringKeyType KeyType = "String"
41+
TimestampKeyType KeyType = "Timestamp"
42+
UUIDArrayKeyType KeyType = "UUIDArray"
43+
UUIDKeyType KeyType = "UUID"
3944
)
4045

4146
// Validate implements the Validatable interface
@@ -44,6 +49,11 @@ func (kt KeyType) Validate() error {
4449
case ArrayKeyType:
4550
case BoolKeyType:
4651
case IntKeyType:
52+
case NullableBoolKeyType:
53+
case NullableIntKeyType:
54+
case NullableStringKeyType:
55+
case NullableTimestampKeyType:
56+
case NullableUUIDKeyType:
4757
case StringKeyType:
4858
case TimestampKeyType:
4959
case UUIDArrayKeyType:

infra/sdkclient/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package sdkclient
22

3-
var sdkVersion = "1.4.0"
3+
var sdkVersion = "1.5.0"
44

55
func getSDKVersion() string {
66
return sdkVersion

0 commit comments

Comments
 (0)