-
Notifications
You must be signed in to change notification settings - Fork 0
/
pydio8_store_v1.go
278 lines (229 loc) · 7.15 KB
/
pydio8_store_v1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package pydio8
import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"path"
"time"
json "github.com/pydio/cells/x/jsonx"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/pydio/cells/common/service/frontend"
"github.com/pydio/pydio-sdk-go/config"
)
type ClientV1 struct {
cli runtime.ClientTransport
}
/*GetConfigParams contains all the parameters to send to the API endpoint
for the get people operation typically these are written to a http.Request
*/
type GetConfigParams struct {
Format *string
Plugin string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WriteToRequest writes these params to a swagger request
func (o *GetConfigParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Format != nil {
// query param format
var qrFormat string
if o.Format != nil {
qrFormat = *o.Format
}
qFormat := qrFormat
if qFormat != "" {
if err := r.SetQueryParam("format", qFormat); err != nil {
return err
}
}
}
// path param path
if err := r.SetPathParam("plugin", o.Plugin); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (a *ClientV1) GetConfig(params *GetConfigParams) (*GetConfigOK, error) {
result, err := a.cli.Submit(&runtime.ClientOperation{
ID: "getConfig",
Method: "GET",
PathPattern: "/settings/get_plugin_manifest/{plugin}",
ProducesMediaTypes: []string{"application/json", "application/xml"},
ConsumesMediaTypes: []string{""},
Schemes: []string{"http"},
Params: params,
Reader: &GetConfigReader{},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*GetConfigOK), nil
}
// GetConfigReader is a Reader for the GetConfig structure.
type GetConfigReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetConfigReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetConfigOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewGetConfigOK creates a GetConfigOK with default headers values
func NewGetConfigOK() *GetConfigOK {
return &GetConfigOK{}
}
/*GetConfigOK handles this case with default header values.
A list of roles represented as standard nodes
*/
type GetConfigOK struct {
PluginSettingsValues *frontend.Cplugin_settings_values
}
func (o *GetConfigOK) Error() string {
return fmt.Sprintf("[GET /settings/get_plugin_manifest/][%d] getCoreAuthOK %+v", 200, o.PluginSettingsValues)
}
func (o *GetConfigOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
data := new(frontend.Cadmin_data)
// response payload
if err := consumer.Consume(response.Body(), &data); err != nil && err != io.EOF {
return err
}
o.PluginSettingsValues = data.Cplugin_settings_values
return nil
}
type GetAdvancedUserInfoResponse struct {
Login string `json:"login"`
AuthSource string `json:"authsource,omitempty"`
Password string `json:"password,omitempty"`
Profile string `json:"profile,omitempty"`
OwnerLogin string `json:"parent,omitempty"`
}
type GetDomainNameResponse struct {
DomainName string `json:"domainname"`
}
func (a *ClientV1) GetAdvancedUserInfo(userId string, sdkConfig *config.SdkConfig) (*GetAdvancedUserInfoResponse, error) {
httpClient := config.GetHttpClient(sdkConfig)
wPath := path.Join(sdkConfig.Url, sdkConfig.Path, "api/settings/hashedpassword")
getUrl := fmt.Sprintf("%s://%s/%s", sdkConfig.Protocol, wPath, userId)
req, _ := http.NewRequest("GET", getUrl, nil)
req.SetBasicAuth(sdkConfig.User, sdkConfig.Password)
resp, e := httpClient.Do(req)
if e != nil {
return nil, e
}
body, e := ioutil.ReadAll(resp.Body)
if e != nil {
return nil, e
}
var result GetAdvancedUserInfoResponse
if e := json.Unmarshal(body, &result); e != nil {
return nil, e
}
return &result, nil
}
func (a *ClientV1) GetDomainName(sdkConfig *config.SdkConfig) (*GetDomainNameResponse, error) {
httpClient := config.GetHttpClient(sdkConfig)
wPath := path.Join(sdkConfig.Url, sdkConfig.Path, "api/settings/ldapdomainname")
getUrl := fmt.Sprintf("%s://%s", sdkConfig.Protocol, wPath)
req, _ := http.NewRequest("GET", getUrl, nil)
req.SetBasicAuth(sdkConfig.User, sdkConfig.Password)
resp, e := httpClient.Do(req)
if e != nil {
return nil, e
}
body, e := ioutil.ReadAll(resp.Body)
if e != nil {
return nil, e
}
var result GetDomainNameResponse
if e := json.Unmarshal(body, &result); e != nil {
return nil, e
}
return &result, nil
}
type NonTechRole struct {
RoleId string `json:"role_id"`
RoleLabel string `json:"role_label"`
AppliesTo string `json:"applies_to"`
OwnerId string `json:"owner_id"`
ForceOverride bool `json:"force_override"`
RoleData map[string]interface{} `json:"role"`
}
func (a *ClientV1) ListNonTechnicalRoles(teams bool, sdkConfig *config.SdkConfig) (map[string]*NonTechRole, error) {
httpClient := config.GetHttpClient(sdkConfig)
var param = ""
if teams {
param = "?teams=true"
}
wPath := path.Join(sdkConfig.Url, sdkConfig.Path, "api/settings/listroles"+param)
getUrl := fmt.Sprintf("%s://%s", sdkConfig.Protocol, wPath)
req, _ := http.NewRequest("GET", getUrl, nil)
req.SetBasicAuth(sdkConfig.User, sdkConfig.Password)
resp, e := httpClient.Do(req)
if e != nil {
return nil, e
}
body, e := ioutil.ReadAll(resp.Body)
if e != nil {
return nil, e
}
var result map[string]*NonTechRole
if e := json.Unmarshal(body, &result); e != nil {
return nil, e
}
return result, nil
}
const (
P8GlobalMetaSharedUser = "AJXP_METADATA_SHAREDUSER"
P8GlobalMetaWatchRead = "META_WATCH_READ"
P8GlobalMetaWatchChange = "META_WATCH_CHANGE"
P8GlobalMetaWatchBoth = "META_WATCH_BOTH"
)
type P8GlobalMetaNode struct {
Watches map[string]string `json:"WATCH"`
Bookmark map[string]bool `json:"BOOKMARK"`
}
type P8GlobalMetaNodes map[string]P8GlobalMetaNode
type P8GlobalMetaUsers map[string]P8GlobalMetaNodes
type P8GlobalMeta map[string]P8GlobalMetaUsers
func (a *ClientV1) ListP8GlobalMeta(sdkConfig *config.SdkConfig) (P8GlobalMeta, error) {
httpClient := config.GetHttpClient(sdkConfig)
wPath := path.Join(sdkConfig.Url, sdkConfig.Path, "api/settings/getmetadata")
getUrl := fmt.Sprintf("%s://%s", sdkConfig.Protocol, wPath)
req, _ := http.NewRequest("GET", getUrl, nil)
req.SetBasicAuth(sdkConfig.User, sdkConfig.Password)
resp, e := httpClient.Do(req)
if e != nil {
return nil, e
}
body, e := ioutil.ReadAll(resp.Body)
if e != nil {
return nil, e
}
var result P8GlobalMeta
if e := json.Unmarshal(body, &result); e != nil {
return nil, e
}
return result, nil
}