forked from ctfer-io/go-ctfd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
76 lines (66 loc) · 2.12 KB
/
flags.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
package api
type GetFlagsParams struct {
ChallengeID *int `schema:"challenge_id,omitempty"`
Type *string `schema:"type,omitempty"`
Content *string `schema:"content,omitempty"`
Data *string `schema:"data,omitempty"`
Q *string `schema:"q,omitempty"`
Field *string `schema:"field,omitempty"`
}
func (client *Client) GetFlags(params *GetFlagsParams, opts ...Option) ([]*Flag, error) {
flags := []*Flag{}
if err := get(client, "/flags", params, &flags, opts...); err != nil {
return nil, err
}
return flags, nil
}
type PostFlagsParams struct {
Challenge int `json:"challenge"`
Content string `json:"content"`
Data string `json:"data"`
Type string `json:"type"`
}
func (client *Client) PostFlags(params *PostFlagsParams, opts ...Option) (*Flag, error) {
flag := &Flag{}
if err := post(client, "/flags", params, &flag, opts...); err != nil {
return nil, err
}
return flag, nil
}
func (client *Client) GetFlagsTypes(opts ...Option) (map[string]*Type, error) {
types := map[string]*Type{}
if err := get(client, "/flags/types", nil, &types, opts...); err != nil {
return nil, err
}
return types, nil
}
func (client *Client) GetFlagsType(typename string, opts ...Option) (*Type, error) {
tp := &Type{}
if err := get(client, "/flags/types/"+typename, nil, &tp, opts...); err != nil {
return nil, err
}
return tp, nil
}
func (client *Client) GetFlag(id string, opts ...Option) (*Flag, error) {
flag := &Flag{}
if err := get(client, "/flags/"+id, nil, &flag, opts...); err != nil {
return nil, err
}
return flag, nil
}
func (client *Client) DeleteFlag(id string, opts ...Option) error {
return delete(client, "/flags/"+id, nil, nil, opts...)
}
type PatchFlagParams struct {
Content string `json:"content"`
Data string `json:"data"`
ID string `json:"id"` // XXX should be int + duplicated with id in URL
Type string `json:"type"`
}
func (client *Client) PatchFlag(id string, params *PatchFlagParams, opts ...Option) (*Flag, error) {
flag := &Flag{}
if err := patch(client, "/flags/"+id, params, &flag, opts...); err != nil {
return nil, err
}
return flag, nil
}