-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzlogs.go
More file actions
61 lines (49 loc) · 1.15 KB
/
zlogs.go
File metadata and controls
61 lines (49 loc) · 1.15 KB
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
package zos
import (
"fmt"
"io"
"net/url"
"github.com/pkg/errors"
"github.com/threefoldtech/zosbase/pkg/gridtypes"
)
var (
validLogSchemes = map[string]struct{}{
"redis": {},
"ws": {},
"wss": {},
"http": {},
"https": {},
}
)
type ZLogs struct {
// ZMachine stream logs for which zmachine
ZMachine gridtypes.Name `json:"zmachine"`
// Output url
Output string `json:"output"`
}
func (z ZLogs) Valid(getter gridtypes.WorkloadGetter) error {
wl, err := getter.Get(z.ZMachine)
if err != nil || wl.Type != ZMachineType {
return fmt.Errorf("no zmachine with name '%s' found", z.ZMachine)
}
u, err := url.Parse(z.Output)
if err != nil {
return errors.Wrap(err, "invalid url supplied in output")
}
if _, ok := validLogSchemes[u.Scheme]; !ok {
return fmt.Errorf("invalid output schema '%s' not supported", u.Scheme)
}
return nil
}
func (z ZLogs) Challenge(w io.Writer) error {
if _, err := fmt.Fprintf(w, "%s", z.ZMachine); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "%s", z.Output); err != nil {
return err
}
return nil
}
func (z ZLogs) Capacity() (gridtypes.Capacity, error) {
return gridtypes.Capacity{}, nil
}