// PgAuthMemberByMemberRoleid retrieves a row from 'pg_catalog.pg_auth_members' as a PgAuthMember.
//
// Generated from index 'pg_auth_members_member_role_index'.
966761
func PgAuthMemberByMemberRoleid(db XODB, member pgtypes.Oid, roleid pgtypes.Oid) (*PgAuthMember, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`tableoid, cmax, xmax, cmin, xmin, ctid, roleid, member, grantor, admin_option ` +
		`FROM pg_catalog.pg_auth_members ` +
		`WHERE member = $1 AND roleid = $2`

	// run query
	XOLog(sqlstr, member, roleid)
	pam := PgAuthMember{}

	err = db.QueryRow(sqlstr, member, roleid).Scan(&pam.Tableoid, &pam.Cmax, &pam.Xmax, &pam.Cmin, &pam.Xmin, &pam.Ctid, &pam.Roleid, &pam.Member, &pam.Grantor, &pam.AdminOption)
	if err != nil {
		return nil, err
	}

	return &pam, nil
}
264904
func (s *Service) SourceRoleID(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
	srcID, ts, err := s.sourcesSeries(ctx, w, r)
	if err != nil {
		return
	}

	roles, ok := s.hasRoles(ctx, ts)
	if !ok {
		Error(w, http.StatusNotFound, fmt.Sprintf("Source %d does not have role capability", srcID), s.Logger)
		return
	}

	rid := httprouter.GetParamFromContext(ctx, "rid")
	role, err := roles.Get(ctx, rid)
	if err != nil {
		Error(w, http.StatusBadRequest, err.Error(), s.Logger)
		return
	}
	rr := newSourceRoleResponse(srcID, role)
	encodeJSON(w, http.StatusOK, rr, s.Logger)
}
38796
func MembershipByCert(consenters map[uint64]*etcdraft.Consenter) map[string]uint64 {
	set := map[string]uint64{}
	for nodeID, c := range consenters {
		set[string(c.ClientTlsCert)] = nodeID
	}
	return set
}
1199511
func (t TeamSigChainState) GetUserRoleAtSeqno(user keybase1.UserVersion, seqno keybase1.Seqno) (keybase1.TeamRole, error) {
	role := keybase1.TeamRole_NONE
	if seqno <= 0 {
		return role, fmt.Errorf("seqno %v is less than 1", seqno)
	}
	for _, point := range t.inner.UserLog[user] {
		if point.SigMeta.SigChainLocation.Seqno > seqno {
			return role, nil
		}
		role = point.Role
	}
	return role, nil
}
793265
func (c oauthClient) Membership(membershipID uint) (wl.Membership, error) {
	if membershipID == 0 {
		return wl.Membership{}, errors.New("membershipID must be > 0")
	}

	url := fmt.Sprintf(
		"%s/memberships/%d",
		c.apiURL,
		membershipID,
	)

	req, err := c.newGetRequest(url)
	if err != nil {
		return wl.Membership{}, err
	}

	resp, err := c.do(req)
	if err != nil {
		return wl.Membership{}, err
	}

	if resp.StatusCode != http.StatusOK {
		return wl.Membership{}, fmt.Errorf("Unexpected response code %d - expected %d", resp.StatusCode, http.StatusOK)
	}

	membership := wl.Membership{}
	err = json.NewDecoder(resp.Body).Decode(&membership)
	if err != nil {
		return wl.Membership{}, err
	}

	return membership, nil
}
388636
func (api *API) ListRoleUsers(role_id string) ([]Identity, error) {
	result := []Identity{}
	url := createUrl(api, rolePathSegment, role_id, "users")
	err := api.Client.Get(url, &result, http.StatusOK)
	if err != nil {
		return nil, err
	}
	return result, nil
}
440110
func PgAuthidByOid(db XODB, oid pgtypes.Oid) (*PgAuthid, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`tableoid, cmax, xmax, cmin, xmin, oid, ctid, rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, rolvaliduntil ` +
		`FROM pg_catalog.pg_authid ` +
		`WHERE oid = $1`

	// run query
	XOLog(sqlstr, oid)
	pa := PgAuthid{}

	err = db.QueryRow(sqlstr, oid).Scan(&pa.Tableoid, &pa.Cmax, &pa.Xmax, &pa.Cmin, &pa.Xmin, &pa.Oid, &pa.Ctid, &pa.Rolname, &pa.Rolsuper, &pa.Rolinherit, &pa.Rolcreaterole, &pa.Rolcreatedb, &pa.Rolcanlogin, &pa.Rolreplication, &pa.Rolbypassrls, &pa.Rolconnlimit, &pa.Rolpassword, &pa.Rolvaliduntil)
	if err != nil {
		return nil, err
	}

	return &pa, nil
}
1327928
func RoleForCertAuthority(ca CertAuthority) Role {
	return &RoleV3{
		Kind:    KindRole,
		Version: V3,
		Metadata: Metadata{
			Name:      RoleNameForCertAuthority(ca.GetClusterName()),
			Namespace: defaults.Namespace,
		},
		Spec: RoleSpecV3{
			Options: RoleOptions{
				MaxSessionTTL: NewDuration(defaults.MaxCertDuration),
			},
			Allow: RoleConditions{
				Namespaces: []string{defaults.Namespace},
				NodeLabels: Labels{Wildcard: []string{Wildcard}},
				Rules:      CopyRulesSlice(DefaultCertAuthorityRules),
			},
		},
	}
}
112801
func (tx *AddMemberTx) AddMemberByUsername(ctx context.Context, username string, role keybase1.TeamRole) (err error) {
	team := tx.team
	g := team.G()
	m := libkb.NewMetaContext(ctx, g)

	defer m.Trace(fmt.Sprintf("AddMemberTx.AddMemberByUsername(%s,%v) to team %q", username, role, team.Name()), func() error { return err })()

	upak, err := engine.ResolveAndCheck(m, username, true /* useTracking */)
	if err != nil {
		return err
	}
	_, err = tx.addMemberByUPKV2(ctx, upak, role)
	return err
}
552462
func TokenAuthorizedWhereID(a *Authorization, docID ID) func(DocumentIndex, DocumentDecorator) ([]ID, error) {
	return func(idx DocumentIndex, _ DocumentDecorator) ([]ID, error) {
		if !a.IsActive() {
			return nil, &Error{
				Code: EUnauthorized,
				Msg:  "authorizer cannot access documents",
			}
		}

		oids, err := idx.GetDocumentsAccessors(docID)
		if err != nil {
			return nil, err
		}
		orgs := map[ID]bool{}
		for _, oid := range oids {
			orgs[oid] = true
		}

		for _, p := range a.Permissions {
			// If the authz has a direct permission to access the resource
			if p.Resource.Type == DocumentsResourceType && p.Resource.ID != nil && docID == *p.Resource.ID {
				return []ID{docID}, nil
			}
			// If the authz has a direct permission to access the class of resources
			if p.Resource.Type == DocumentsResourceType && p.Resource.ID == nil && p.Resource.OrgID == nil {
				return []ID{docID}, nil
			}

			if p.Resource.Type == DocumentsResourceType && p.Resource.OrgID != nil && orgs[*p.Resource.OrgID] {
				return []ID{docID}, nil
			}
		}

		return nil, &Error{
			Code: EUnauthorized,
			Msg:  "authorization cannot access document",
		}
	}
}
922951
func (s *Session) GuildMemberEdit(guildID, userID string, roles []string) (err error) {

	data := struct {
		Roles []string `json:"roles"`
	}{roles}

	_, err = s.RequestWithBucketID("PATCH", EndpointGuildMember(guildID, userID), data, EndpointGuildMember(guildID, ""))
	if err != nil {
		return
	}

	return
}
235349
func UserHasRole(res *Response, role string) bool {
	user := res.Envelope.User
	for _, r := range user.Roles {
		if r == role {
			return true
		}
	}

	return false
}
388793
func (b *BigIP) PoolMembers(name string) (*PoolMembers, error) {
	var poolMembers PoolMembers
	err, _ := b.getForEntity(&poolMembers, uriLtm, uriPool, name, uriPoolMember)
	if err != nil {
		return nil, err
	}

	return &poolMembers, nil
}
295496
func (s *Role) SetRoleId(v string) *Role {
	s.RoleId = &v
	return s
}
1287533
func (p *RoleServiceClient) GetMembers(role string) (r []string, err error) {
	if err = p.sendGetMembers(role); err != nil {
		return
	}
	return p.recvGetMembers()
}
1169750
func AuthGroupPermissionByID(db XODB, id int) (*AuthGroupPermission, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`id, group_id, permission_id ` +
		`FROM public.auth_group_permissions ` +
		`WHERE id = $1`

	// run query
	XOLog(sqlstr, id)
	agp := AuthGroupPermission{
		_exists: true,
	}

	err = db.QueryRow(sqlstr, id).Scan(&agp.ID, &agp.GroupID, &agp.PermissionID)
	if err != nil {
		return nil, err
	}

	return &agp, nil
}
654930
func (c *Card) AddMemberID(memberID string) (member []*Member, err error) {
	path := fmt.Sprintf("cards/%s/idMembers", c.ID)
	err = c.client.Post(path, Arguments{"value": memberID}, &member)
	return member, err
}