/
client.go
57 lines (51 loc) · 1.35 KB
/
client.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
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package client
import (
"encoding/json"
"github.com/elastic/k8s-operators/local-volume/pkg/driver/protocol"
)
// Init performs a call to the /init path using the client.
func Init(c Caller) string {
output, err := c.Get("/init")
if err != nil {
return err.Error()
}
return output
}
// Mount performs a call to the /mount path using the client.
func Mount(c Caller, args []string) string {
// parse args
directory := args[0]
var options protocol.MountOptions
if len(args) > 1 {
if err := json.Unmarshal([]byte(args[1]), &options); err != nil {
return err.Error()
}
}
// make request
reqBody := &protocol.MountRequest{
TargetDir: directory,
Options: options,
}
output, err := c.Post("/mount", reqBody)
if err != nil {
return err.Error()
}
return string(output)
}
// Unmount performs a call to the /unmount path using the client.
func Unmount(c Caller, args []string) string {
// parse args
directory := args[0]
// make request
reqBody := &protocol.UnmountRequest{
TargetDir: directory,
}
output, err := c.Post("/unmount", reqBody)
if err != nil {
return err.Error()
}
return string(output)
}