-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split auth and node management into two functions
- Loading branch information
Showing
12 changed files
with
203 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package node | ||
|
||
import "github.com/mantil-io/mantil.go" | ||
|
||
const ( | ||
usersPartition = "users" | ||
projectsPartition = "projects" | ||
) | ||
|
||
type Store struct { | ||
users *mantil.KV | ||
projects *mantil.KV | ||
} | ||
|
||
func NewStore() (*Store, error) { | ||
users, err := mantil.NewKV(usersPartition) | ||
if err != nil { | ||
return nil, err | ||
} | ||
projects, err := mantil.NewKV(projectsPartition) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Store{ | ||
users: users, | ||
projects: projects, | ||
}, nil | ||
} | ||
|
||
type user struct { | ||
Name string | ||
} | ||
|
||
func (s *Store) StoreUser(name string) error { | ||
return s.users.Put(name, &user{ | ||
Name: name, | ||
}) | ||
} | ||
|
||
func (s *Store) FindUser(name string) (*user, error) { | ||
u := &user{} | ||
if err := s.users.Get(name, u); err != nil { | ||
return nil, err | ||
} | ||
return u, nil | ||
} | ||
|
||
type project struct { | ||
Repo string | ||
} | ||
|
||
func (s *Store) StoreProject(repo string) error { | ||
return s.projects.Put(repo, &project{ | ||
Repo: repo, | ||
}) | ||
} | ||
|
||
func (s *Store) FindProjects() ([]*project, error) { | ||
projects := []*project{} | ||
_, err := s.projects.FindAll(&projects) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return projects, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bootstrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/mantil-io/mantil.go" | ||
"github.com/mantil-io/mantil/node/api/node" | ||
) | ||
|
||
type Node struct { | ||
store *node.Store | ||
} | ||
|
||
func New() *Node { | ||
s, err := node.NewStore() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return &Node{ | ||
store: s, | ||
} | ||
} | ||
|
||
type AddUserRequest struct { | ||
Username string `json:"username"` | ||
} | ||
|
||
func (n *Node) AddUser(ctx context.Context, req *AddUserRequest) error { | ||
return n.store.StoreUser(req.Username) | ||
} | ||
|
||
type AddProjectRequest struct { | ||
Repo string `json:"repo"` | ||
} | ||
|
||
func (n *Node) AddProject(ctx context.Context, req *AddProjectRequest) error { | ||
return n.store.StoreProject(req.Repo) | ||
} | ||
|
||
func main() { | ||
var api = New() | ||
mantil.LambdaHandler(api) | ||
} |
Oops, something went wrong.