implemented simple ssh dual control
This commit is contained in:
parent
690613cab8
commit
60012be942
12 changed files with 446 additions and 20 deletions
|
|
@ -14,11 +14,13 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version = "v1"
|
||||
KeyName = "key"
|
||||
ReqName = "req"
|
||||
KeyPath = "/" + Version + "/" + KeyName
|
||||
ReqPath = "/" + Version + "/" + ReqName
|
||||
Version = "v1"
|
||||
KeyName = "key"
|
||||
ReqName = "req"
|
||||
KeyPath = "/" + Version + "/" + KeyName
|
||||
ReqPath = "/" + Version + "/" + ReqName
|
||||
SSH = "ssh"
|
||||
AccessPath = "/" + Version + "/" + SSH
|
||||
)
|
||||
|
||||
type NewKey struct {
|
||||
|
|
@ -68,6 +70,10 @@ func ApproveURL(id, aid string) string {
|
|||
return KeyPath + "/" + id + "/" + aid
|
||||
}
|
||||
|
||||
func AccessURL(host, user, aid string) string {
|
||||
return AccessPath + "/" + host + "/" + user + "/" + aid
|
||||
}
|
||||
|
||||
type Key struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
|
@ -170,3 +176,47 @@ func NewApprovals(m types.ApprovalMap) (a Approvals) {
|
|||
a.Sort()
|
||||
return
|
||||
}
|
||||
|
||||
type Access struct {
|
||||
Host string `json:"host"`
|
||||
User string `json:"user"`
|
||||
AID string `json:"aid"`
|
||||
IP string `json:"ip"`
|
||||
Status types.Status `json:"status"`
|
||||
}
|
||||
|
||||
type AccessList []Access
|
||||
|
||||
func (AccessList) Less(a, b Access) int { return cmp.Compare(a.Host, b.Host) }
|
||||
func (a AccessList) Sort() { slices.SortStableFunc(a, a.Less) }
|
||||
func (a AccessList) Len() int { return len(a) }
|
||||
func (a AccessList) Fields() string {
|
||||
return "Host\t User\t Approval ID\t IP\t Status"
|
||||
}
|
||||
func (a AccessList) Values() []string {
|
||||
vals := make([]string, len(a))
|
||||
for i, v := range a {
|
||||
vals[i] = fmt.Sprintf("%s\t %s\t %s\t %s\t %s",
|
||||
v.Host,
|
||||
v.User,
|
||||
v.AID,
|
||||
v.IP,
|
||||
v.Status,
|
||||
)
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
func NewAccessList(m types.SSHMap) (a AccessList) {
|
||||
for k, v := range m {
|
||||
a = append(a, Access{
|
||||
Host: v.Host,
|
||||
User: v.User,
|
||||
AID: k,
|
||||
IP: v.IP,
|
||||
Status: v.Status,
|
||||
})
|
||||
}
|
||||
a.Sort()
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue