github.com/cs3org/reva/v2@v2.27.7/pkg/ocm/client/payload.go (about) 1 package client 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "io" 7 8 "github.com/cs3org/reva/v2/internal/http/services/ocmd" 9 ) 10 11 // https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post 12 // NotificationType one of "SHARE_ACCEPTED", "SHARE_DECLINED", "SHARE_CHANGE_PERMISSION", "SHARE_UNSHARED", "USER_REMOVED" 13 const ( 14 SHARE_UNSHARED = "SHARE_UNSHARED" 15 SHARE_CHANGE_PERMISSION = "SHARE_CHANGE_PERMISSION" 16 ) 17 18 // InviteAcceptedRequest contains the parameters for accepting 19 // an invitation. 20 type InviteAcceptedRequest struct { 21 UserID string `json:"userID"` 22 Email string `json:"email"` 23 Name string `json:"name"` 24 RecipientProvider string `json:"recipientProvider"` 25 Token string `json:"token"` 26 } 27 28 // User contains the remote user's information when accepting 29 // an invitation. 30 type User struct { 31 UserID string `json:"userID"` 32 Email string `json:"email"` 33 Name string `json:"name"` 34 } 35 36 func (r *InviteAcceptedRequest) toJSON() (io.Reader, error) { 37 var b bytes.Buffer 38 if err := json.NewEncoder(&b).Encode(r); err != nil { 39 return nil, err 40 } 41 return &b, nil 42 } 43 44 // NewShareRequest contains the parameters for creating a new OCM share. 45 type NewShareRequest struct { 46 ShareWith string `json:"shareWith"` 47 Name string `json:"name"` 48 Description string `json:"description"` 49 ProviderID string `json:"providerId"` 50 Owner string `json:"owner"` 51 Sender string `json:"sender"` 52 OwnerDisplayName string `json:"ownerDisplayName"` 53 SenderDisplayName string `json:"senderDisplayName"` 54 ShareType string `json:"shareType"` 55 Expiration uint64 `json:"expiration"` 56 ResourceType string `json:"resourceType"` 57 Protocols ocmd.Protocols `json:"protocol"` 58 } 59 60 func (r *NewShareRequest) toJSON() (io.Reader, error) { 61 var b bytes.Buffer 62 if err := json.NewEncoder(&b).Encode(r); err != nil { 63 return nil, err 64 } 65 return &b, nil 66 } 67 68 // Capabilities contains a set of properties exposed by 69 // a remote cloud storage. 70 type Capabilities struct { 71 Enabled bool `json:"enabled"` 72 APIVersion string `json:"apiVersion"` 73 EndPoint string `json:"endPoint"` 74 Provider string `json:"provider"` 75 ResourceTypes []struct { 76 Name string `json:"name"` 77 ShareTypes []string `json:"shareTypes"` 78 Protocols struct { 79 Webdav *string `json:"webdav"` 80 Webapp *string `json:"webapp"` 81 Datatx *string `json:"datatx"` 82 } `json:"protocols"` 83 } `json:"resourceTypes"` 84 Capabilities []string `json:"capabilities"` 85 } 86 87 // NotificationRequest is the request payload for the OCM API notifications endpoint. 88 // https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post 89 type NotificationRequest struct { 90 NotificationType string `json:"notificationType" validate:"required"` 91 ResourceType string `json:"resourceType" validate:"required"` 92 // Identifier to identify the shared resource at the provider side. This is unique per provider such that if the same resource is shared twice, this providerId will not be repeated. 93 ProviderId string `json:"providerId" validate:"required"` 94 // Optional additional parameters, depending on the notification and the resource type. 95 Notification *Notification `json:"notification,omitempty"` 96 } 97 98 // Notification is the payload for the notification field in the NotificationRequest. 99 type Notification struct { 100 // Owner string `json:"owner,omitempty"` 101 Grantee string `json:"grantee,omitempty"` 102 SharedSecret string `json:"sharedSecret,omitempty"` 103 Protocols ocmd.Protocols `json:"protocol,omitempty"` 104 } 105 106 // ToJSON returns the JSON io.Reader of the NotificationRequest. 107 func (r *NotificationRequest) ToJSON() (io.Reader, error) { 108 var b bytes.Buffer 109 if err := json.NewEncoder(&b).Encode(r); err != nil { 110 return nil, err 111 } 112 return &b, nil 113 } 114 115 // NewShareResponse is the response returned when creating a new share. 116 type NewShareResponse struct { 117 RecipientDisplayName string `json:"recipientDisplayName"` 118 } 119 120 // ErrorMessageResponse is the response returned by the OCM API in case of an error. 121 // https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post 122 type ErrorMessageResponse struct { 123 Message string `json:"message"` 124 ValidationErrors []*ValidationError `json:"validationErrors,omitempty"` 125 } 126 127 // ValidationError is the payload for the validationErrors field in the ErrorMessageResponse. 128 type ValidationError struct { 129 Name string `json:"name"` 130 Message string `json:"message"` 131 }