diff --git a/VERSION b/VERSION index a803cc2..a551051 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.14.0 +0.15.0 diff --git a/arkruntime/model/file/oas_json_gen.go b/arkruntime/model/file/oas_json_gen.go index bf78866..51d45e0 100644 --- a/arkruntime/model/file/oas_json_gen.go +++ b/arkruntime/model/file/oas_json_gen.go @@ -840,6 +840,12 @@ func (s *FileObject) encodeFields(e *jx.Encoder) { s.DownloadURL.Encode(e) } } + { + if s.Tos.Set { + e.FieldStart("tos") + s.Tos.Encode(e) + } + } { if s.Error.Set { e.FieldStart("error") @@ -854,7 +860,7 @@ func (s *FileObject) encodeFields(e *jx.Encoder) { } } -var jsonFieldsNameOfFileObject = [14]string{ +var jsonFieldsNameOfFileObject = [15]string{ 0: "object", 1: "id", 2: "purpose", @@ -867,8 +873,9 @@ var jsonFieldsNameOfFileObject = [14]string{ 9: "expire_at", 10: "status", 11: "download_url", - 12: "error", - 13: "preprocess_configs", + 12: "tos", + 13: "error", + 14: "preprocess_configs", } // Decode decodes FileObject from json. @@ -1008,6 +1015,16 @@ func (s *FileObject) Decode(d *jx.Decoder) error { }(); err != nil { return errors.Wrap(err, "decode field \"download_url\"") } + case "tos": + if err := func() error { + s.Tos.Reset() + if err := s.Tos.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"tos\"") + } case "error": if err := func() error { s.Error.Reset() @@ -1327,6 +1344,39 @@ func (s *OptString) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes TosLocation as json. +func (o OptTosLocation) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes TosLocation from json. +func (o *OptTosLocation) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptTosLocation to nil") + } + o.Set = true + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptTosLocation) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptTosLocation) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes TosStorage as json. func (o OptTosStorage) Encode(e *jx.Encoder) { if !o.Set { @@ -1540,6 +1590,119 @@ func (s *Status) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *TosLocation) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *TosLocation) encodeFields(e *jx.Encoder) { + { + e.FieldStart("bucket") + e.Str(s.Bucket) + } + { + e.FieldStart("object_key") + e.Str(s.ObjectKey) + } +} + +var jsonFieldsNameOfTosLocation = [2]string{ + 0: "bucket", + 1: "object_key", +} + +// Decode decodes TosLocation from json. +func (s *TosLocation) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode TosLocation to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "bucket": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Str() + s.Bucket = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"bucket\"") + } + case "object_key": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.ObjectKey = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"object_key\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode TosLocation") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfTosLocation) { + name = jsonFieldsNameOfTosLocation[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *TosLocation) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *TosLocation) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode implements json.Marshaler. func (s *TosStorage) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/arkruntime/model/file/oas_schemas_gen.go b/arkruntime/model/file/oas_schemas_gen.go index adbec2a..1ba1e92 100644 --- a/arkruntime/model/file/oas_schemas_gen.go +++ b/arkruntime/model/file/oas_schemas_gen.go @@ -364,6 +364,8 @@ type FileObject struct { Status Status `json:"status"` // Pre-signed download URL pointing at the underlying TOS object. DownloadURL OptString `json:"download_url"` + // Stored object location. Only returned for files in user-owned TOS buckets. + Tos OptTosLocation `json:"tos"` // Failure details. Only set when `status` is `failed`. Error OptFileError `json:"error"` // Preprocessing configuration applied at upload time. @@ -430,6 +432,11 @@ func (s *FileObject) GetDownloadURL() OptString { return s.DownloadURL } +// GetTos returns the value of Tos. +func (s *FileObject) GetTos() OptTosLocation { + return s.Tos +} + // GetError returns the value of Error. func (s *FileObject) GetError() OptFileError { return s.Error @@ -500,6 +507,11 @@ func (s *FileObject) SetDownloadURL(val OptString) { s.DownloadURL = val } +// SetTos sets the value of Tos. +func (s *FileObject) SetTos(val OptTosLocation) { + s.Tos = val +} + // SetError sets the value of Error. func (s *FileObject) SetError(val OptFileError) { s.Error = val @@ -913,6 +925,52 @@ func (o OptString) Or(d string) string { return d } +// NewOptTosLocation returns new OptTosLocation with value set to v. +func NewOptTosLocation(v TosLocation) OptTosLocation { + return OptTosLocation{ + Value: v, + Set: true, + } +} + +// OptTosLocation is optional TosLocation. +type OptTosLocation struct { + Value TosLocation + Set bool +} + +// IsSet returns true if OptTosLocation was set. +func (o OptTosLocation) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptTosLocation) Reset() { + var v TosLocation + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptTosLocation) SetTo(v TosLocation) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptTosLocation) Get() (v TosLocation, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptTosLocation) Or(d TosLocation) TosLocation { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptTosStorage returns new OptTosStorage with value set to v. func NewOptTosStorage(v TosStorage) OptTosStorage { return OptTosStorage{ @@ -1165,6 +1223,35 @@ func (s *Status) UnmarshalText(data []byte) error { } } +// Location of a file stored in a user-owned TOS bucket. +// Ref: #/components/schemas/TosLocation +type TosLocation struct { + // TOS bucket name. + Bucket string `json:"bucket"` + // Full stored object key, including the upload prefix. + ObjectKey string `json:"object_key"` +} + +// GetBucket returns the value of Bucket. +func (s *TosLocation) GetBucket() string { + return s.Bucket +} + +// GetObjectKey returns the value of ObjectKey. +func (s *TosLocation) GetObjectKey() string { + return s.ObjectKey +} + +// SetBucket sets the value of Bucket. +func (s *TosLocation) SetBucket(val string) { + s.Bucket = val +} + +// SetObjectKey sets the value of ObjectKey. +func (s *TosLocation) SetObjectKey(val string) { + s.ObjectKey = val +} + // User-owned TOS bucket destination. When provided, files are stored in // the user's bucket instead of the default storage and do not count // against the 20GB free quota.