Merge branch 'master' of ssh://github.com/micro/services

This commit is contained in:
Asim Aslam
2021-12-14 09:45:07 +00:00
4 changed files with 16 additions and 22 deletions

View File

@@ -20,15 +20,13 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
// Create an object. Returns error if object with this name already exists. If you want to update an existing object use the `Update` endpoint // Create an object. Returns error if object with this name already exists. Max object size of 10MB, see Upload endpoint for larger objects. If you want to update an existing object use the `Update` endpoint
// You need to send the request as a multipart/form-data rather than the usual application/json
// with each parameter as a form field.
type CreateRequest struct { type CreateRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
// The contents of the object // The contents of the object. Either base64 encoded if sending request as application/json or raw bytes if using multipart/form-data format
Object []byte `protobuf:"bytes,1,opt,name=object,proto3" json:"object,omitempty"` Object []byte `protobuf:"bytes,1,opt,name=object,proto3" json:"object,omitempty"`
// The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg // The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
@@ -138,14 +136,12 @@ func (x *CreateResponse) GetUrl() string {
} }
// Update an object. If an object with this name does not exist, creates a new one. // Update an object. If an object with this name does not exist, creates a new one.
// You need to send the request as a multipart/form-data rather than the usual application/json
// with each parameter as a form field.
type UpdateRequest struct { type UpdateRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
// The contents of the object // The contents of the object. Either base64 encoded if sending request as application/json or raw bytes if using multipart/form-data format
Object []byte `protobuf:"bytes,1,opt,name=object,proto3" json:"object,omitempty"` Object []byte `protobuf:"bytes,1,opt,name=object,proto3" json:"object,omitempty"`
// The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg // The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
@@ -984,7 +980,7 @@ func (x *DownloadResponse) GetUrl() string {
return "" return ""
} }
// Upload a large object. Returns a time limited presigned URL to be used for uploading the object // Upload a large object (> 10MB). Returns a time limited presigned URL to be used for uploading the object
type UploadRequest struct { type UploadRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -1046,7 +1042,7 @@ type UploadResponse struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
// a presigned url to be used for uploading // a presigned url to be used for uploading. To use the URL call it with HTTP PUT and pass the object as the request data
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`
} }

View File

@@ -16,10 +16,8 @@ service Space {
} }
// Create an object. Returns error if object with this name already exists. Max object size of 10MB, see Upload endpoint for larger objects. If you want to update an existing object use the `Update` endpoint // Create an object. Returns error if object with this name already exists. Max object size of 10MB, see Upload endpoint for larger objects. If you want to update an existing object use the `Update` endpoint
// You need to send the request as a multipart/form-data rather than the usual application/json
// with each parameter as a form field.
message CreateRequest { message CreateRequest {
// The contents of the object // The contents of the object. Either base64 encoded if sending request as application/json or raw bytes if using multipart/form-data format
bytes object = 1; bytes object = 1;
// The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg // The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg
string name = 2; string name = 2;
@@ -33,10 +31,8 @@ message CreateResponse {
} }
// Update an object. If an object with this name does not exist, creates a new one. // Update an object. If an object with this name does not exist, creates a new one.
// You need to send the request as a multipart/form-data rather than the usual application/json
// with each parameter as a form field.
message UpdateRequest { message UpdateRequest {
// The contents of the object // The contents of the object. Either base64 encoded if sending request as application/json or raw bytes if using multipart/form-data format
bytes object = 1; bytes object = 1;
// The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg // The name of the object. Use forward slash delimiter to implement a nested directory-like structure e.g. images/foo.jpg
string name = 2; string name = 2;

View File

@@ -499,15 +499,17 @@ func (domain *Domain) CacheReadToken(ctx context.Context, token string) (string,
var email string var email string
expires, err := cache.Context(ctx).Get(token, email) expires, err := cache.Context(ctx).Get(token, &email)
if err == cache.ErrNotFound { if err != nil && err == cache.ErrNotFound {
return "", errors.New("token not found") return "", errors.New("token not found")
} else if time.Until(expires).Seconds() < 0 {
return "", errors.New("token expired")
} else if err != nil { } else if err != nil {
return "", microerr.InternalServerError("CacheReadToken", err.Error()) return "", microerr.InternalServerError("CacheReadToken", err.Error())
} }
if time.Until(expires).Seconds() < 0 {
return "", errors.New("token expired")
}
return email, nil return email, nil
} }

View File

@@ -437,15 +437,15 @@ func (s *User) VerifyToken(ctx context.Context, req *pb.VerifyTokenRequest, rsp
// check if token is valid // check if token is valid
email, err := s.domain.CacheReadToken(ctx, token) email, err := s.domain.CacheReadToken(ctx, token)
if err.Error() == "token not found" { if err != nil && err.Error() == "token not found" {
rsp.IsValid = false rsp.IsValid = false
rsp.Message = err.Error() rsp.Message = err.Error()
return nil return nil
} else if err.Error() == "token expired" { } else if err != nil && err.Error() == "token expired" {
rsp.IsValid = false rsp.IsValid = false
rsp.Message = err.Error() rsp.Message = err.Error()
return nil return nil
} else if err.Error() == "token empty" { } else if err != nil && err.Error() == "token empty" {
rsp.IsValid = false rsp.IsValid = false
rsp.Message = err.Error() rsp.Message = err.Error()
return nil return nil