Skip to content

Commit

Permalink
Merge pull request #55 from seashell/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
edufschmidt authored Jun 11, 2021
2 parents d3552b5 + 6a74a6c commit 5f20868
Show file tree
Hide file tree
Showing 90 changed files with 1,938 additions and 835 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ Godeps/
# End of https://www.gitignore.io/api/go
ui/node_modules/*
ui/.eslintcache
ui/build
ui/build/*
vendor/*

!*.keep

tmp
dist/
5 changes: 3 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ archives:
windows: Windows
386: i386
amd64: x86_64
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
checksum:
name_template: '{{ .ProjectName }}_v{{ .Version }}_checksums.txt'
name_template: "{{ .ProjectName }}_v{{ .Version }}_checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
release:
name_template: "{{ .ProjectName }}-v{{ .Version }}"
name_template: "v{{ .Version }}"
changelog:
sort: asc
filters:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Drago is meant to be simple, and provide a solid foundation for higher-level fun

## Usage
```
Usage: drago [--version] [--help] <command> [<args>]
Usage: drago [--version] [--help] <command> [options]
Available commands:
acl Interact with ACL policies and tokens
Expand Down
18 changes: 12 additions & 6 deletions api/acl_policy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"fmt"
"path"

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

// Create :
func (p *ACLPolicies) Upsert(policy *structs.ACLPolicy) error {
return fmt.Errorf("not implemented")
func (p *ACLPolicies) Upsert(policy *structs.ACLPolicy) (*structs.ACLPolicy, error) {

var rcvPolicy *structs.ACLPolicy
err := p.client.createResource(aclPoliciesPath, policy, &rcvPolicy)
if err != nil {
return nil, err
}

return policy, nil
}

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

var policy *structs.ACLPolicy
err := p.client.getResource(aclPoliciesPath, name, &policy)
out := &structs.ACLPolicy{}
err := p.client.getResource(aclPoliciesPath, name, out)
if err != nil {
return nil, err
}

return policy, nil
return out, nil
}

// List :
Expand Down
6 changes: 3 additions & 3 deletions api/acl_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func (c *Client) ACLTokens() *ACLTokens {
// Create :
func (t *ACLTokens) Create(token *structs.ACLToken) (*structs.ACLToken, error) {

out := structs.ACLToken{}
out := &structs.ACLToken{}

err := t.client.createResource(aclTokensPath, token, &out)
err := t.client.createResource(aclTokensPath, token, out)
if err != nil {
return nil, err
}

return &out, nil
return out, nil
}

// Delete :
Expand Down
31 changes: 31 additions & 0 deletions api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,34 @@ func (n *Connections) List() ([]*structs.ConnectionListStub, error) {

return items, nil
}

func (n *Connections) Create(connection *structs.Connection) error {

err := n.client.createResource(connectionsPath, connection, nil)
if err != nil {
return err
}

return nil
}

func (n *Connections) Update(conn *structs.Connection) (*structs.Connection, error) {

out := &structs.Connection{}
err := n.client.createResource(connectionsPath, conn, out)
if err != nil {
return nil, err
}

return out, nil
}

func (n *Connections) Delete(id string) error {

err := n.client.deleteResource(id, connectionsPath, nil)
if err != nil {
return err
}

return nil
}
18 changes: 10 additions & 8 deletions api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,32 @@ func (n *Interfaces) List(filters map[string][]string) ([]*structs.InterfaceList
}

// Create :
func (n *Interfaces) Create(nodeID, networkID string) error {
func (n *Interfaces) Create(nodeID, networkID string) (*structs.Interface, error) {

iface := &structs.Interface{
NodeID: nodeID,
NetworkID: networkID,
}

err := n.client.createResource(interfacesPath, iface, nil)
out := &structs.Interface{}
err := n.client.createResource(interfacesPath, iface, out)
if err != nil {
return err
return nil, err
}

return nil
return out, nil
}

// Update :
func (n *Interfaces) Update(iface *structs.Interface) error {
func (n *Interfaces) Update(iface *structs.Interface) (*structs.Interface, error) {

err := n.client.createResource(interfacesPath, iface, nil)
out := &structs.Interface{}
err := n.client.createResource(interfacesPath, iface, out)
if err != nil {
return err
return nil, err
}

return nil
return out, err
}

// Delete :
Expand Down
2 changes: 1 addition & 1 deletion api/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (n *Networks) Create(network *structs.Network) error {
return err
}

return nil
return err
}

// Delete :
Expand Down
1 change: 0 additions & 1 deletion client/nic/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ func (c *Controller) createLink(name string, alias string) error {
}

} else {
fmt.Println("USING KERNELSPACE WIREGUARD")
if err := netlink.LinkAdd(&netlink.Wireguard{LinkAttrs: attrs}); err != nil {
return fmt.Errorf("can't create network interface : %s", err.Error())
}
Expand Down
94 changes: 94 additions & 0 deletions command/acl_policy_apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package command

import (
"context"
"fmt"
"strings"

"github.com/seashell/drago/drago/structs"
cli "github.com/seashell/drago/pkg/cli"
"github.com/spf13/pflag"
)

// ACLPolicyApplyCommand :
type ACLPolicyApplyCommand struct {
UI cli.UI
Command

// Parsed flags
description string
}

func (c *ACLPolicyApplyCommand) FlagSet() *pflag.FlagSet {

flags := c.Command.FlagSet(c.Name())
flags.Usage = func() { c.UI.Output("\n" + c.Help() + "\n") }

return flags
}

// Name :
func (c *ACLPolicyApplyCommand) Name() string {
return "acl policy apply"
}

// Synopsis :
func (c *ACLPolicyApplyCommand) Synopsis() string {
return "Apply ACL policy"
}

// Run :
func (c *ACLPolicyApplyCommand) Run(ctx context.Context, args []string) int {

flags := c.FlagSet()

if err := flags.Parse(args); err != nil {
return 1
}

args = flags.Args()
if len(args) != 1 {
c.UI.Error("This command takes one argument: <name>")
c.UI.Error(`For additional help, try 'drago acl policy apply --help'`)
return 1
}

name := args[0]

// Get the HTTP client
api, err := c.Command.APIClient()
if err != nil {
c.UI.Error(fmt.Sprintf("Error setting up API client: %s", err))
return 1
}

p := &structs.ACLPolicy{
Name: name,
Description: c.description,
}
if _, err := api.ACLPolicies().Upsert(p); err != nil {
c.UI.Error(fmt.Sprintf("Error applying ACL policy: %s", err))
return 1
}

return 0
}

// Help :
func (c *ACLPolicyApplyCommand) Help() string {
h := `
Usage: drago acl policy apply <name> [options]
Create or update an ACL policy.
General Options:
` + GlobalOptions() + `
ACL Policy Apply Options:
--description=<description>
Sets the description for the ACL policy.
`
return strings.TrimSpace(h)
}
17 changes: 5 additions & 12 deletions command/acl_policy_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@ package command

import (
"context"
"flag"
"fmt"
"strings"

"github.com/spf13/pflag"

cli "github.com/seashell/drago/pkg/cli"
)

// ACLPolicyDeleteCommand :
type ACLPolicyDeleteCommand struct {
UI cli.UI

// Parsed flags

Command
}

func (c *ACLPolicyDeleteCommand) FlagSet() *flag.FlagSet {
func (c *ACLPolicyDeleteCommand) FlagSet() *pflag.FlagSet {

flags := c.Command.FlagSet(c.Name())

flags.Usage = func() { c.UI.Output("\n" + c.Help() + "\n") }

// General options

return flags
}

Expand Down Expand Up @@ -55,22 +50,20 @@ func (c *ACLPolicyDeleteCommand) Run(ctx context.Context, args []string) int {
return 1
}

name := args[0]

// Get the HTTP client
api, err := c.Command.APIClient()
if err != nil {
c.UI.Error(fmt.Sprintf("Error setting up API client: %s", err))
return 1
}

name := args[0]

if err := api.ACLPolicies().Delete(name); err != nil {
c.UI.Error(fmt.Sprintf("Error deleting ACL policies: %s", err))
return 1
}

c.UI.Output("Deleted!")

return 0
}

Expand Down
Loading

0 comments on commit 5f20868

Please sign in to comment.