Skip to content

Commit 5f20868

Browse files
authored
Merge pull request #55 from seashell/dev
dev
2 parents d3552b5 + 6a74a6c commit 5f20868

90 files changed

Lines changed: 1938 additions & 835 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ Godeps/
2727
# End of https://www.gitignore.io/api/go
2828
ui/node_modules/*
2929
ui/.eslintcache
30-
ui/build
30+
ui/build/*
3131
vendor/*
3232

33+
!*.keep
34+
3335
tmp
3436
dist/

.goreleaser.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ archives:
2222
windows: Windows
2323
386: i386
2424
amd64: x86_64
25+
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
2526
checksum:
26-
name_template: '{{ .ProjectName }}_v{{ .Version }}_checksums.txt'
27+
name_template: "{{ .ProjectName }}_v{{ .Version }}_checksums.txt"
2728
snapshot:
2829
name_template: "{{ .Tag }}-next"
2930
release:
30-
name_template: "{{ .ProjectName }}-v{{ .Version }}"
31+
name_template: "v{{ .Version }}"
3132
changelog:
3233
sort: asc
3334
filters:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Drago is meant to be simple, and provide a solid foundation for higher-level fun
7171

7272
## Usage
7373
```
74-
Usage: drago [--version] [--help] <command> [<args>]
74+
Usage: drago [--version] [--help] <command> [options]
7575
7676
Available commands:
7777
acl Interact with ACL policies and tokens

api/acl_policy.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package api
22

33
import (
4-
"fmt"
54
"path"
65

76
"github.com/seashell/drago/drago/structs"
@@ -22,8 +21,15 @@ func (c *Client) ACLPolicies() *ACLPolicies {
2221
}
2322

2423
// Create :
25-
func (p *ACLPolicies) Upsert(policy *structs.ACLPolicy) error {
26-
return fmt.Errorf("not implemented")
24+
func (p *ACLPolicies) Upsert(policy *structs.ACLPolicy) (*structs.ACLPolicy, error) {
25+
26+
var rcvPolicy *structs.ACLPolicy
27+
err := p.client.createResource(aclPoliciesPath, policy, &rcvPolicy)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
return policy, nil
2733
}
2834

2935
// Delete :
@@ -40,13 +46,13 @@ func (p *ACLPolicies) Delete(name string) error {
4046
// Get :
4147
func (p *ACLPolicies) Get(name string) (*structs.ACLPolicy, error) {
4248

43-
var policy *structs.ACLPolicy
44-
err := p.client.getResource(aclPoliciesPath, name, &policy)
49+
out := &structs.ACLPolicy{}
50+
err := p.client.getResource(aclPoliciesPath, name, out)
4551
if err != nil {
4652
return nil, err
4753
}
4854

49-
return policy, nil
55+
return out, nil
5056
}
5157

5258
// List :

api/acl_token.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ func (c *Client) ACLTokens() *ACLTokens {
2323
// Create :
2424
func (t *ACLTokens) Create(token *structs.ACLToken) (*structs.ACLToken, error) {
2525

26-
out := structs.ACLToken{}
26+
out := &structs.ACLToken{}
2727

28-
err := t.client.createResource(aclTokensPath, token, &out)
28+
err := t.client.createResource(aclTokensPath, token, out)
2929
if err != nil {
3030
return nil, err
3131
}
3232

33-
return &out, nil
33+
return out, nil
3434
}
3535

3636
// Delete :

api/connection.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,34 @@ func (n *Connections) List() ([]*structs.ConnectionListStub, error) {
4343

4444
return items, nil
4545
}
46+
47+
func (n *Connections) Create(connection *structs.Connection) error {
48+
49+
err := n.client.createResource(connectionsPath, connection, nil)
50+
if err != nil {
51+
return err
52+
}
53+
54+
return nil
55+
}
56+
57+
func (n *Connections) Update(conn *structs.Connection) (*structs.Connection, error) {
58+
59+
out := &structs.Connection{}
60+
err := n.client.createResource(connectionsPath, conn, out)
61+
if err != nil {
62+
return nil, err
63+
}
64+
65+
return out, nil
66+
}
67+
68+
func (n *Connections) Delete(id string) error {
69+
70+
err := n.client.deleteResource(id, connectionsPath, nil)
71+
if err != nil {
72+
return err
73+
}
74+
75+
return nil
76+
}

api/interface.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,32 @@ func (n *Interfaces) List(filters map[string][]string) ([]*structs.InterfaceList
4545
}
4646

4747
// Create :
48-
func (n *Interfaces) Create(nodeID, networkID string) error {
48+
func (n *Interfaces) Create(nodeID, networkID string) (*structs.Interface, error) {
4949

5050
iface := &structs.Interface{
5151
NodeID: nodeID,
5252
NetworkID: networkID,
5353
}
5454

55-
err := n.client.createResource(interfacesPath, iface, nil)
55+
out := &structs.Interface{}
56+
err := n.client.createResource(interfacesPath, iface, out)
5657
if err != nil {
57-
return err
58+
return nil, err
5859
}
5960

60-
return nil
61+
return out, nil
6162
}
6263

6364
// Update :
64-
func (n *Interfaces) Update(iface *structs.Interface) error {
65+
func (n *Interfaces) Update(iface *structs.Interface) (*structs.Interface, error) {
6566

66-
err := n.client.createResource(interfacesPath, iface, nil)
67+
out := &structs.Interface{}
68+
err := n.client.createResource(interfacesPath, iface, out)
6769
if err != nil {
68-
return err
70+
return nil, err
6971
}
7072

71-
return nil
73+
return out, err
7274
}
7375

7476
// Delete :

api/network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (n *Networks) Create(network *structs.Network) error {
2828
return err
2929
}
3030

31-
return nil
31+
return err
3232
}
3333

3434
// Delete :

client/nic/controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func (c *Controller) createLink(name string, alias string) error {
167167
}
168168

169169
} else {
170-
fmt.Println("USING KERNELSPACE WIREGUARD")
171170
if err := netlink.LinkAdd(&netlink.Wireguard{LinkAttrs: attrs}); err != nil {
172171
return fmt.Errorf("can't create network interface : %s", err.Error())
173172
}

command/acl_policy_apply.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package command
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/seashell/drago/drago/structs"
9+
cli "github.com/seashell/drago/pkg/cli"
10+
"github.com/spf13/pflag"
11+
)
12+
13+
// ACLPolicyApplyCommand :
14+
type ACLPolicyApplyCommand struct {
15+
UI cli.UI
16+
Command
17+
18+
// Parsed flags
19+
description string
20+
}
21+
22+
func (c *ACLPolicyApplyCommand) FlagSet() *pflag.FlagSet {
23+
24+
flags := c.Command.FlagSet(c.Name())
25+
flags.Usage = func() { c.UI.Output("\n" + c.Help() + "\n") }
26+
27+
return flags
28+
}
29+
30+
// Name :
31+
func (c *ACLPolicyApplyCommand) Name() string {
32+
return "acl policy apply"
33+
}
34+
35+
// Synopsis :
36+
func (c *ACLPolicyApplyCommand) Synopsis() string {
37+
return "Apply ACL policy"
38+
}
39+
40+
// Run :
41+
func (c *ACLPolicyApplyCommand) Run(ctx context.Context, args []string) int {
42+
43+
flags := c.FlagSet()
44+
45+
if err := flags.Parse(args); err != nil {
46+
return 1
47+
}
48+
49+
args = flags.Args()
50+
if len(args) != 1 {
51+
c.UI.Error("This command takes one argument: <name>")
52+
c.UI.Error(`For additional help, try 'drago acl policy apply --help'`)
53+
return 1
54+
}
55+
56+
name := args[0]
57+
58+
// Get the HTTP client
59+
api, err := c.Command.APIClient()
60+
if err != nil {
61+
c.UI.Error(fmt.Sprintf("Error setting up API client: %s", err))
62+
return 1
63+
}
64+
65+
p := &structs.ACLPolicy{
66+
Name: name,
67+
Description: c.description,
68+
}
69+
if _, err := api.ACLPolicies().Upsert(p); err != nil {
70+
c.UI.Error(fmt.Sprintf("Error applying ACL policy: %s", err))
71+
return 1
72+
}
73+
74+
return 0
75+
}
76+
77+
// Help :
78+
func (c *ACLPolicyApplyCommand) Help() string {
79+
h := `
80+
Usage: drago acl policy apply <name> [options]
81+
82+
Create or update an ACL policy.
83+
84+
General Options:
85+
` + GlobalOptions() + `
86+
87+
ACL Policy Apply Options:
88+
89+
--description=<description>
90+
Sets the description for the ACL policy.
91+
92+
`
93+
return strings.TrimSpace(h)
94+
}

0 commit comments

Comments
 (0)