This is a refactor of samhofi.us/x/keybase/v2 that takes advantage of the libkeybase performance improvements.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.6 KiB

package keybase
import (
"encoding/json"
"fmt"
"os/exec"
)
// teamAPIOut sends JSON requests to the team API and returns its response.
func teamAPIOut(keybasePath string, w TeamAPI) (TeamAPI, error) {
jsonBytes, _ := json.Marshal(w)
cmd := exec.Command(keybasePath, "team", "api", "-m", string(jsonBytes))
cmdOut, err := cmd.Output()
if err != nil {
return TeamAPI{}, err
}
var r TeamAPI
json.Unmarshal(cmdOut, &r)
return r, nil
}
5 years ago
// AddUser adds members to a team by username
func (t Team) AddUser(user, role string) (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "add-members"
m.Params.Options.Team = t.Name
m.Params.Options.Usernames = []usernames{
{
Username: user,
Role: role,
},
}
r, err := teamAPIOut(t.keybase.Path, m)
if err == nil {
r, err = t.MemberList()
}
return r, err
}
// MemberList returns a list of a team's members
func (t Team) MemberList() (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "list-team-memberships"
m.Params.Options.Team = t.Name
5 years ago
r, err := teamAPIOut(t.keybase.Path, m)
return r, err
}
// CreateSubteam creates a subteam
func (t Team) CreateSubteam(name string) (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "create-team"
m.Params.Options.Team = fmt.Sprintf("%s.%s", t.Name, name)
r, err := teamAPIOut(t.keybase.Path, m)
return r, err
}
5 years ago
// CreateTeam creates a new team
func (k *Keybase) CreateTeam(name string) (TeamAPI, error) {
m := TeamAPI{
Params: &tParams{},
}
m.Method = "create-team"
m.Params.Options.Team = name
r, err := teamAPIOut(k.Path, m)
return r, err
}