first working version
This commit is contained in:
parent
398ff981d1
commit
39cae64854
8 changed files with 23 additions and 16 deletions
|
|
@ -26,7 +26,7 @@ func NewApprover() *Approver {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *Approver) New(id, name string) (aid string, err error) {
|
||||
func (a *Approver) New(id, name, ip string) (aid string, err error) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
size := len(a.m)
|
||||
|
|
@ -41,6 +41,7 @@ func (a *Approver) New(id, name string) (aid string, err error) {
|
|||
a.m[aid] = Approval{
|
||||
ID: id,
|
||||
Name: name,
|
||||
IP: ip,
|
||||
Created: time.Now().Unix(),
|
||||
}
|
||||
return
|
||||
|
|
@ -52,13 +53,13 @@ func (a *Approver) List() (m ApprovalMap) {
|
|||
a.mu.RUnlock()
|
||||
return
|
||||
}
|
||||
func (a *Approver) Status(id, aid string) (s Status) {
|
||||
func (a *Approver) Status(id, aid, ip string) (s Status) {
|
||||
a.mu.RLock()
|
||||
if app, ok := a.m[aid]; ok && app.ID == id {
|
||||
if app, ok := a.m[aid]; ok && app.ID == id && app.IP == ip {
|
||||
s = app.Status
|
||||
}
|
||||
a.mu.RUnlock()
|
||||
if s == Rejected {
|
||||
if s == Approved || s == Rejected {
|
||||
a.mu.Lock()
|
||||
delete(a.m, aid)
|
||||
a.mu.Unlock()
|
||||
|
|
@ -78,6 +79,7 @@ func (a *Approver) Update(aid string, s Status) {
|
|||
type Approval struct {
|
||||
ID string
|
||||
Name string
|
||||
IP string
|
||||
Created int64
|
||||
Status Status
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ var (
|
|||
ErrKeyNotFound = newError("key not found", http.StatusNotFound)
|
||||
ErrReqNotFound = newError("key request not found", http.StatusNotFound)
|
||||
ErrTooManyApprovals = newError("too many approvals pending", http.StatusConflict)
|
||||
ErrKeyRequestRejected = newError("key request rejected", http.StatusConflict)
|
||||
ErrKeyRequestRejected = newError("key request rejected", http.StatusForbidden)
|
||||
ErrMNA = newError("method not allowed", http.StatusMethodNotAllowed)
|
||||
ErrISE = newError("internal server error", http.StatusInternalServerError)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue