From 556516907470e4f664f675878a5160e887cfb265 Mon Sep 17 00:00:00 2001 From: Shivansh Vij Date: Tue, 21 Feb 2023 16:40:38 -0500 Subject: [PATCH 1/2] Adding `WithStorage` option, updating CHANGELOG.md (#64) Signed-off-by: Shivansh Vij --- CHANGELOG.md | 4 ++++ go/registry/registry.go | 31 ++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 975affdd..23a05dba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Features + +- Added `WithStorage` option to `go/registry` to allow for pre-configured Storage Clients to be used + ## [v0.3.8] - 2023-02-19 ### Features diff --git a/go/registry/registry.go b/go/registry/registry.go index 530a83bc..d0fb48bd 100644 --- a/go/registry/registry.go +++ b/go/registry/registry.go @@ -69,6 +69,7 @@ type config struct { baseURL string organization string client *client.ScaleAPIV1 + storage *storage.Storage } type Option func(config *config) @@ -85,6 +86,12 @@ func WithCacheDirectory(cacheDirectory string) Option { } } +func WithStorage(st *storage.Storage) Option { + return func(config *config) { + config.storage = st + } +} + func WithAPIKey(apiKey string) Option { return func(config *config) { config.apiKey = apiKey @@ -139,11 +146,13 @@ func New(name string, tag string, opts ...Option) (*scalefunc.ScaleFunc, error) } var err error - st := storage.Default - if conf.cacheDirectory != "" { - st, err = storage.New(conf.cacheDirectory) - if err != nil { - return nil, fmt.Errorf("failed to create storage for directory %s: %w", conf.cacheDirectory, err) + if conf.storage == nil { + conf.storage = storage.Default + if conf.cacheDirectory != "" { + conf.storage, err = storage.New(conf.cacheDirectory) + if err != nil { + return nil, fmt.Errorf("failed to create storage for directory %s: %w", conf.cacheDirectory, err) + } } } @@ -166,7 +175,7 @@ func New(name string, tag string, opts ...Option) (*scalefunc.ScaleFunc, error) switch conf.pullPolicy { case NeverPullPolicy: - entry, err := st.Get(name, tag, conf.organization, "") + entry, err := conf.storage.Get(name, tag, conf.organization, "") if err != nil { return nil, err } @@ -175,7 +184,7 @@ func New(name string, tag string, opts ...Option) (*scalefunc.ScaleFunc, error) } return nil, ErrNoFunction case IfNotPresentPullPolicy: - entry, err := st.Get(name, tag, conf.organization, "") + entry, err := conf.storage.Get(name, tag, conf.organization, "") if err != nil { return nil, err } @@ -227,14 +236,14 @@ func New(name string, tag string, opts ...Option) (*scalefunc.ScaleFunc, error) return nil, fmt.Errorf("failed to decode retrieved scale function %s/%s:%s: %w", conf.organization, name, tag, err) } - err = st.Put(name, tag, conf.organization, hash, sf) + err = conf.storage.Put(name, tag, conf.organization, hash, sf) if err != nil { return nil, fmt.Errorf("failed to store retrieved scale function %s/%s:%s: %w", conf.organization, name, tag, err) } return sf, nil case AlwaysPullPolicy: - entry, err := st.Get(name, tag, conf.organization, "") + entry, err := conf.storage.Get(name, tag, conf.organization, "") if err != nil { return nil, err } @@ -290,13 +299,13 @@ func New(name string, tag string, opts ...Option) (*scalefunc.ScaleFunc, error) } if entry != nil { - err = st.Delete(name, tag, entry.Organization, entry.Hash) + err = conf.storage.Delete(name, tag, entry.Organization, entry.Hash) if err != nil { return nil, fmt.Errorf("failed to delete existing scale function %s/%s:%s: %w", entry.Organization, name, tag, err) } } - err = st.Put(name, tag, conf.organization, computedHash, sf) + err = conf.storage.Put(name, tag, conf.organization, computedHash, sf) if err != nil { return nil, fmt.Errorf("failed to store retrieved scale function %s/%s:%s: %w", conf.organization, name, tag, err) } From 0bcf01db165a005b7ee406aa1976f496b5538e09 Mon Sep 17 00:00:00 2001 From: Shivansh Vij Date: Tue, 21 Feb 2023 20:07:11 -0500 Subject: [PATCH 2/2] Updating Client (go and ts), bumping verisons, updating changelog (#65) Signed-off-by: Shivansh Vij --- CHANGELOG.md | 10 +- go.mod | 2 +- go.sum | 4 +- go/client/models/models_user_info_response.go | 59 ++++ go/client/scale_api_v1_client.go | 5 + .../userinfo/post_userinfo_parameters.go | 128 +++++++ go/client/userinfo/post_userinfo_responses.go | 319 ++++++++++++++++++ go/client/userinfo/userinfo_client.go | 81 +++++ package-lock.json | 16 +- package.json | 2 +- ts/client/index.ts | 2 + ts/client/models/models_UserInfoResponse.ts | 11 + ts/client/services/UserinfoService.ts | 30 ++ 13 files changed, 656 insertions(+), 13 deletions(-) create mode 100644 go/client/models/models_user_info_response.go create mode 100644 go/client/userinfo/post_userinfo_parameters.go create mode 100644 go/client/userinfo/post_userinfo_responses.go create mode 100644 go/client/userinfo/userinfo_client.go create mode 100644 ts/client/models/models_UserInfoResponse.ts create mode 100644 ts/client/services/UserinfoService.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a05dba..8abb7d50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,16 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [v0.3.9] - 2023-02-19 + +### Changes + +- Bumping `auth` version to `v0.2.26` + ### Features - Added `WithStorage` option to `go/registry` to allow for pre-configured Storage Clients to be used +- Updated API Client to expose the new `UserInfo` endpoint from the Scale API ## [v0.3.8] - 2023-02-19 @@ -136,7 +143,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Initial release of the Scale Runtime library. -[unreleased]: https://github.com/loopholelabs/scale/compare/v0.3.8...HEAD +[unreleased]: https://github.com/loopholelabs/scale/compare/v0.3.9...HEAD +[v0.3.9]: https://github.com/loopholelabs/scale/compare/v0.3.9 [v0.3.8]: https://github.com/loopholelabs/scale/compare/v0.3.8 [v0.3.7]: https://github.com/loopholelabs/scale/compare/v0.3.7 [v0.3.6]: https://github.com/loopholelabs/scale/compare/v0.3.6 diff --git a/go.mod b/go.mod index 998891e9..69597e06 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-openapi/strfmt v0.21.3 github.com/go-openapi/swag v0.22.3 github.com/google/uuid v1.3.0 - github.com/loopholelabs/auth v0.2.25 + github.com/loopholelabs/auth v0.2.26 github.com/loopholelabs/polyglot-go v0.5.1 github.com/loopholelabs/scale-signature v0.2.9 github.com/loopholelabs/scale-signature-http v0.3.4 diff --git a/go.sum b/go.sum index fc48f484..8270fad2 100644 --- a/go.sum +++ b/go.sum @@ -92,8 +92,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/loopholelabs/auth v0.2.25 h1:0uO/Noub9c/CGZPLwwFIZM6r2zMHyfy07oUZkpyYP6A= -github.com/loopholelabs/auth v0.2.25/go.mod h1:8jY3kru3zYytaH6gmtt6i0qQO1BGfLrZlem1RlR1ENs= +github.com/loopholelabs/auth v0.2.26 h1:aTYp6ekGZuynkie91ppAkfMzv75xnlKd8Wqa/39Mib8= +github.com/loopholelabs/auth v0.2.26/go.mod h1:8jY3kru3zYytaH6gmtt6i0qQO1BGfLrZlem1RlR1ENs= github.com/loopholelabs/polyglot-go v0.5.1 h1:21QVDELp+EodPUAL+Aw8GNXLyt2BFj9gYQsGvHIFlcc= github.com/loopholelabs/polyglot-go v0.5.1/go.mod h1:Z0QiNv4KRuWjQWpUerMhmkvRh6ks1pYmEH4SGpG0EHQ= github.com/loopholelabs/scale-signature v0.2.9 h1:KGYslPu33VJ+MUQc6uWqiVW2u2On3Z1Tg6FUJeqfQ/4= diff --git a/go/client/models/models_user_info_response.go b/go/client/models/models_user_info_response.go new file mode 100644 index 00000000..4df87582 --- /dev/null +++ b/go/client/models/models_user_info_response.go @@ -0,0 +1,59 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// ModelsUserInfoResponse models user info response +// +// swagger:model models.UserInfoResponse +type ModelsUserInfoResponse struct { + + // email + Email string `json:"email,omitempty"` + + // member organizations + MemberOrganizations []string `json:"member_organizations"` + + // organization + Organization string `json:"organization,omitempty"` + + // owned organizations + OwnedOrganizations []string `json:"owned_organizations"` +} + +// Validate validates this models user info response +func (m *ModelsUserInfoResponse) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this models user info response based on context it is used +func (m *ModelsUserInfoResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *ModelsUserInfoResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ModelsUserInfoResponse) UnmarshalBinary(b []byte) error { + var res ModelsUserInfoResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/go/client/scale_api_v1_client.go b/go/client/scale_api_v1_client.go index 6b50c78d..de456f39 100644 --- a/go/client/scale_api_v1_client.go +++ b/go/client/scale_api_v1_client.go @@ -13,6 +13,7 @@ import ( "github.com/loopholelabs/scale/go/client/access" "github.com/loopholelabs/scale/go/client/health" "github.com/loopholelabs/scale/go/client/registry" + "github.com/loopholelabs/scale/go/client/userinfo" ) // Default scale API v1 HTTP client. @@ -60,6 +61,7 @@ func New(transport runtime.ClientTransport, formats strfmt.Registry) *ScaleAPIV1 cli.Access = access.New(transport, formats) cli.Health = health.New(transport, formats) cli.Registry = registry.New(transport, formats) + cli.Userinfo = userinfo.New(transport, formats) return cli } @@ -110,6 +112,8 @@ type ScaleAPIV1 struct { Registry registry.ClientService + Userinfo userinfo.ClientService + Transport runtime.ClientTransport } @@ -119,4 +123,5 @@ func (c *ScaleAPIV1) SetTransport(transport runtime.ClientTransport) { c.Access.SetTransport(transport) c.Health.SetTransport(transport) c.Registry.SetTransport(transport) + c.Userinfo.SetTransport(transport) } diff --git a/go/client/userinfo/post_userinfo_parameters.go b/go/client/userinfo/post_userinfo_parameters.go new file mode 100644 index 00000000..040c29b9 --- /dev/null +++ b/go/client/userinfo/post_userinfo_parameters.go @@ -0,0 +1,128 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package userinfo + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewPostUserinfoParams creates a new PostUserinfoParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewPostUserinfoParams() *PostUserinfoParams { + return &PostUserinfoParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewPostUserinfoParamsWithTimeout creates a new PostUserinfoParams object +// with the ability to set a timeout on a request. +func NewPostUserinfoParamsWithTimeout(timeout time.Duration) *PostUserinfoParams { + return &PostUserinfoParams{ + timeout: timeout, + } +} + +// NewPostUserinfoParamsWithContext creates a new PostUserinfoParams object +// with the ability to set a context for a request. +func NewPostUserinfoParamsWithContext(ctx context.Context) *PostUserinfoParams { + return &PostUserinfoParams{ + Context: ctx, + } +} + +// NewPostUserinfoParamsWithHTTPClient creates a new PostUserinfoParams object +// with the ability to set a custom HTTPClient for a request. +func NewPostUserinfoParamsWithHTTPClient(client *http.Client) *PostUserinfoParams { + return &PostUserinfoParams{ + HTTPClient: client, + } +} + +/* +PostUserinfoParams contains all the parameters to send to the API endpoint + + for the post userinfo operation. + + Typically these are written to a http.Request. +*/ +type PostUserinfoParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the post userinfo params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *PostUserinfoParams) WithDefaults() *PostUserinfoParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the post userinfo params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *PostUserinfoParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the post userinfo params +func (o *PostUserinfoParams) WithTimeout(timeout time.Duration) *PostUserinfoParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the post userinfo params +func (o *PostUserinfoParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the post userinfo params +func (o *PostUserinfoParams) WithContext(ctx context.Context) *PostUserinfoParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the post userinfo params +func (o *PostUserinfoParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the post userinfo params +func (o *PostUserinfoParams) WithHTTPClient(client *http.Client) *PostUserinfoParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the post userinfo params +func (o *PostUserinfoParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *PostUserinfoParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/go/client/userinfo/post_userinfo_responses.go b/go/client/userinfo/post_userinfo_responses.go new file mode 100644 index 00000000..e2afc29d --- /dev/null +++ b/go/client/userinfo/post_userinfo_responses.go @@ -0,0 +1,319 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package userinfo + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + + "github.com/loopholelabs/scale/go/client/models" +) + +// PostUserinfoReader is a Reader for the PostUserinfo structure. +type PostUserinfoReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *PostUserinfoReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewPostUserinfoOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 400: + result := NewPostUserinfoBadRequest() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 401: + result := NewPostUserinfoUnauthorized() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 500: + result := NewPostUserinfoInternalServerError() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code()) + } +} + +// NewPostUserinfoOK creates a PostUserinfoOK with default headers values +func NewPostUserinfoOK() *PostUserinfoOK { + return &PostUserinfoOK{} +} + +/* +PostUserinfoOK describes a response with status code 200, with default header values. + +OK +*/ +type PostUserinfoOK struct { + Payload *models.ModelsUserInfoResponse +} + +// IsSuccess returns true when this post userinfo o k response has a 2xx status code +func (o *PostUserinfoOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this post userinfo o k response has a 3xx status code +func (o *PostUserinfoOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this post userinfo o k response has a 4xx status code +func (o *PostUserinfoOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this post userinfo o k response has a 5xx status code +func (o *PostUserinfoOK) IsServerError() bool { + return false +} + +// IsCode returns true when this post userinfo o k response a status code equal to that given +func (o *PostUserinfoOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the post userinfo o k response +func (o *PostUserinfoOK) Code() int { + return 200 +} + +func (o *PostUserinfoOK) Error() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoOK %+v", 200, o.Payload) +} + +func (o *PostUserinfoOK) String() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoOK %+v", 200, o.Payload) +} + +func (o *PostUserinfoOK) GetPayload() *models.ModelsUserInfoResponse { + return o.Payload +} + +func (o *PostUserinfoOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.ModelsUserInfoResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPostUserinfoBadRequest creates a PostUserinfoBadRequest with default headers values +func NewPostUserinfoBadRequest() *PostUserinfoBadRequest { + return &PostUserinfoBadRequest{} +} + +/* +PostUserinfoBadRequest describes a response with status code 400, with default header values. + +Bad Request +*/ +type PostUserinfoBadRequest struct { + Payload string +} + +// IsSuccess returns true when this post userinfo bad request response has a 2xx status code +func (o *PostUserinfoBadRequest) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this post userinfo bad request response has a 3xx status code +func (o *PostUserinfoBadRequest) IsRedirect() bool { + return false +} + +// IsClientError returns true when this post userinfo bad request response has a 4xx status code +func (o *PostUserinfoBadRequest) IsClientError() bool { + return true +} + +// IsServerError returns true when this post userinfo bad request response has a 5xx status code +func (o *PostUserinfoBadRequest) IsServerError() bool { + return false +} + +// IsCode returns true when this post userinfo bad request response a status code equal to that given +func (o *PostUserinfoBadRequest) IsCode(code int) bool { + return code == 400 +} + +// Code gets the status code for the post userinfo bad request response +func (o *PostUserinfoBadRequest) Code() int { + return 400 +} + +func (o *PostUserinfoBadRequest) Error() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoBadRequest %+v", 400, o.Payload) +} + +func (o *PostUserinfoBadRequest) String() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoBadRequest %+v", 400, o.Payload) +} + +func (o *PostUserinfoBadRequest) GetPayload() string { + return o.Payload +} + +func (o *PostUserinfoBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPostUserinfoUnauthorized creates a PostUserinfoUnauthorized with default headers values +func NewPostUserinfoUnauthorized() *PostUserinfoUnauthorized { + return &PostUserinfoUnauthorized{} +} + +/* +PostUserinfoUnauthorized describes a response with status code 401, with default header values. + +Unauthorized +*/ +type PostUserinfoUnauthorized struct { + Payload string +} + +// IsSuccess returns true when this post userinfo unauthorized response has a 2xx status code +func (o *PostUserinfoUnauthorized) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this post userinfo unauthorized response has a 3xx status code +func (o *PostUserinfoUnauthorized) IsRedirect() bool { + return false +} + +// IsClientError returns true when this post userinfo unauthorized response has a 4xx status code +func (o *PostUserinfoUnauthorized) IsClientError() bool { + return true +} + +// IsServerError returns true when this post userinfo unauthorized response has a 5xx status code +func (o *PostUserinfoUnauthorized) IsServerError() bool { + return false +} + +// IsCode returns true when this post userinfo unauthorized response a status code equal to that given +func (o *PostUserinfoUnauthorized) IsCode(code int) bool { + return code == 401 +} + +// Code gets the status code for the post userinfo unauthorized response +func (o *PostUserinfoUnauthorized) Code() int { + return 401 +} + +func (o *PostUserinfoUnauthorized) Error() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoUnauthorized %+v", 401, o.Payload) +} + +func (o *PostUserinfoUnauthorized) String() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoUnauthorized %+v", 401, o.Payload) +} + +func (o *PostUserinfoUnauthorized) GetPayload() string { + return o.Payload +} + +func (o *PostUserinfoUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPostUserinfoInternalServerError creates a PostUserinfoInternalServerError with default headers values +func NewPostUserinfoInternalServerError() *PostUserinfoInternalServerError { + return &PostUserinfoInternalServerError{} +} + +/* +PostUserinfoInternalServerError describes a response with status code 500, with default header values. + +Internal Server Error +*/ +type PostUserinfoInternalServerError struct { + Payload string +} + +// IsSuccess returns true when this post userinfo internal server error response has a 2xx status code +func (o *PostUserinfoInternalServerError) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this post userinfo internal server error response has a 3xx status code +func (o *PostUserinfoInternalServerError) IsRedirect() bool { + return false +} + +// IsClientError returns true when this post userinfo internal server error response has a 4xx status code +func (o *PostUserinfoInternalServerError) IsClientError() bool { + return false +} + +// IsServerError returns true when this post userinfo internal server error response has a 5xx status code +func (o *PostUserinfoInternalServerError) IsServerError() bool { + return true +} + +// IsCode returns true when this post userinfo internal server error response a status code equal to that given +func (o *PostUserinfoInternalServerError) IsCode(code int) bool { + return code == 500 +} + +// Code gets the status code for the post userinfo internal server error response +func (o *PostUserinfoInternalServerError) Code() int { + return 500 +} + +func (o *PostUserinfoInternalServerError) Error() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoInternalServerError %+v", 500, o.Payload) +} + +func (o *PostUserinfoInternalServerError) String() string { + return fmt.Sprintf("[POST /userinfo][%d] postUserinfoInternalServerError %+v", 500, o.Payload) +} + +func (o *PostUserinfoInternalServerError) GetPayload() string { + return o.Payload +} + +func (o *PostUserinfoInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/go/client/userinfo/userinfo_client.go b/go/client/userinfo/userinfo_client.go new file mode 100644 index 00000000..1d2db504 --- /dev/null +++ b/go/client/userinfo/userinfo_client.go @@ -0,0 +1,81 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package userinfo + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" +) + +// New creates a new userinfo API client. +func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService { + return &Client{transport: transport, formats: formats} +} + +/* +Client for userinfo API +*/ +type Client struct { + transport runtime.ClientTransport + formats strfmt.Registry +} + +// ClientOption is the option for Client methods +type ClientOption func(*runtime.ClientOperation) + +// ClientService is the interface for Client methods +type ClientService interface { + PostUserinfo(params *PostUserinfoParams, opts ...ClientOption) (*PostUserinfoOK, error) + + SetTransport(transport runtime.ClientTransport) +} + +/* +PostUserinfo users info checks if a user is logged in and returns their info + +UserInfo checks if a user is logged in and returns their info +*/ +func (a *Client) PostUserinfo(params *PostUserinfoParams, opts ...ClientOption) (*PostUserinfoOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPostUserinfoParams() + } + op := &runtime.ClientOperation{ + ID: "PostUserinfo", + Method: "POST", + PathPattern: "/userinfo", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &PostUserinfoReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*PostUserinfoOK) + if ok { + return success, nil + } + // unexpected success response + // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue + msg := fmt.Sprintf("unexpected success response for PostUserinfo: API contract not enforced by server. Client expected to get an error, but got: %T", result) + panic(msg) +} + +// SetTransport changes the transport on the client +func (a *Client) SetTransport(transport runtime.ClientTransport) { + a.transport = transport +} diff --git a/package-lock.json b/package-lock.json index f76ba3f4..c9acad52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@loopholelabs/scale", - "version": "0.3.8", + "version": "0.3.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@loopholelabs/scale", - "version": "0.3.8", + "version": "0.3.9", "license": "apache-2.0", "dependencies": { "@loopholelabs/polyglot-ts": "^0.4.0", @@ -2276,9 +2276,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.304", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.304.tgz", - "integrity": "sha512-6c8M+ojPgDIXN2NyfGn8oHASXYnayj+gSEnGeLMKb9zjsySeVB/j7KkNAAG9yDcv8gNlhvFg5REa1N/kQU6pgA==" + "version": "1.4.305", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.305.tgz", + "integrity": "sha512-WETy6tG0CT5gm1O+xCbyapWNsCcmIvrn4NHViIGYo2AT8FV2qUCXdaB+WqYxSv/vS5mFqhBYnfZAAkVArjBmUg==" }, "node_modules/elliptic": { "version": "6.5.4", @@ -5649,9 +5649,9 @@ "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" }, "node_modules/yargs": { - "version": "17.7.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.0.tgz", - "integrity": "sha512-dwqOPg5trmrre9+v8SUo2q/hAwyKoVfu8OC1xPHKJGNdxAvPl4sKxL4vBnh3bQz/ZvvGAFeA5H3ou2kcOY8sQQ==", + "version": "17.7.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.1.tgz", + "integrity": "sha512-cwiTb08Xuv5fqF4AovYacTFNxk62th7LKJ6BL9IGUpTJrWoU7/7WdQGTP2SjKf1dUNBGzDd28p/Yfs/GI6JrLw==", "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", diff --git a/package.json b/package.json index 705845bc..f09d5ad5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@loopholelabs/scale", - "version": "0.3.8", + "version": "0.3.9", "description": "Scale is a highly-performant WebAssembly function runtime that enables composable, language-agnostic software development.", "source": "ts/index.ts", "main": "main.js", diff --git a/ts/client/index.ts b/ts/client/index.ts index 69b389a6..c1fbfdf9 100644 --- a/ts/client/index.ts +++ b/ts/client/index.ts @@ -11,8 +11,10 @@ export type { models_CreateFunctionResponse } from './models/models_CreateFuncti export type { models_GetAPIKeyResponse } from './models/models_GetAPIKeyResponse'; export type { models_GetFunctionResponse } from './models/models_GetFunctionResponse'; export type { models_GetHealthResponse } from './models/models_GetHealthResponse'; +export type { models_UserInfoResponse } from './models/models_UserInfoResponse'; export { AccessService } from './services/AccessService'; export { FunctionService } from './services/FunctionService'; export { HealthService } from './services/HealthService'; export { RegistryService } from './services/RegistryService'; +export { UserinfoService } from './services/UserinfoService'; diff --git a/ts/client/models/models_UserInfoResponse.ts b/ts/client/models/models_UserInfoResponse.ts new file mode 100644 index 00000000..605df734 --- /dev/null +++ b/ts/client/models/models_UserInfoResponse.ts @@ -0,0 +1,11 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type models_UserInfoResponse = { + email?: string; + member_organizations?: Array; + organization?: string; + owned_organizations?: Array; +}; + diff --git a/ts/client/services/UserinfoService.ts b/ts/client/services/UserinfoService.ts new file mode 100644 index 00000000..9340326f --- /dev/null +++ b/ts/client/services/UserinfoService.ts @@ -0,0 +1,30 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { models_UserInfoResponse } from '../models/models_UserInfoResponse'; + +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; + +export class UserinfoService { + + /** + * UserInfo checks if a user is logged in and returns their info + * UserInfo checks if a user is logged in and returns their info + * @returns models_UserInfoResponse OK + * @throws ApiError + */ + public static postUserinfo(): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/userinfo', + errors: { + 400: `Bad Request`, + 401: `Unauthorized`, + 500: `Internal Server Error`, + }, + }); + } + +}