implemented simple ssh dual control
This commit is contained in:
parent
690613cab8
commit
60012be942
12 changed files with 446 additions and 20 deletions
|
|
@ -18,6 +18,7 @@ var (
|
|||
ErrClientIsNil = errors.New("client is nil")
|
||||
keyPath = schema.KeyPath
|
||||
reqPath = schema.ReqPath
|
||||
accessPath = schema.AccessPath
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
|
|
@ -121,3 +122,45 @@ func (c *Client) DeleteKey(ctx context.Context, id string) (err error) {
|
|||
_, err = c.c.Do(req, nil)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) Access(ctx context.Context, host, user string) (ok bool, err error) {
|
||||
path := fmt.Sprintf("%s/%s/%s", accessPath, host, user)
|
||||
req, err := c.c.NewRequest(ctx, "GET", path, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = c.c.FollowRedirectLoop(req, &ok, time.Second*2)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) GetAccess(ctx context.Context) (accessList schema.AccessList, err error) {
|
||||
path := accessPath
|
||||
req, err := c.c.NewRequest(ctx, "GET", path, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = c.c.Do(req, &accessList)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Client) RejectAccess(ctx context.Context, id string) error {
|
||||
return c.sendAccess(ctx, id, false)
|
||||
}
|
||||
|
||||
func (c *Client) AcceptAccess(ctx context.Context, id string) error {
|
||||
return c.sendAccess(ctx, id, true)
|
||||
}
|
||||
|
||||
func (c *Client) sendAccess(ctx context.Context, id string, approve bool) (err error) {
|
||||
path := fmt.Sprintf("%s/%s", accessPath, id)
|
||||
method := "DELETE"
|
||||
if approve {
|
||||
method = "PUT"
|
||||
}
|
||||
req, err := c.c.NewRequest(ctx, method, path, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = c.c.Do(req, nil)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue