// adds a TUF Change template to the given roles
545372
func addChange(cl changelist.Changelist, c changelist.Change, roles ...data.RoleName) error {
	if len(roles) == 0 {
		roles = []data.RoleName{data.CanonicalTargetsRole}
	}

	var changes []changelist.Change
	for _, role := range roles {
		// Ensure we can only add targets to the CanonicalTargetsRole,
		// or a Delegation role (which is <CanonicalTargetsRole>/something else)
		if role != data.CanonicalTargetsRole && !data.IsDelegation(role) && !data.IsWildDelegation(role) {
			return data.ErrInvalidRole{
				Role:   role,
				Reason: "cannot add targets to this role",
			}
		}

		changes = append(changes, changelist.NewTUFChange(
			c.Action(),
			role,
			c.Type(),
			c.Path(),
			c.Content(),
		))
	}

	for _, c := range changes {
		if err := cl.Add(c); err != nil {
			return err
		}
	}
	return nil
}
43797
func (client *Client) UpdateTemplate(ctx context.Context, templateID string, newTemplate Template) error {
	// Create signature
	content := map[string]interface{}{
		"name":     newTemplate.Name,
		"template": newTemplate.Content,
	}

	return client.request(ctx, "PUT", "templates/"+templateID, content, nil)
}
1018552
func (rbac *RBAC) Add(r Role) (err error) {
	rbac.mutex.Lock()
	if _, ok := rbac.roles[r.ID()]; !ok {
		rbac.roles[r.ID()] = r
	} else {
		err = ErrRoleExist
	}
	rbac.mutex.Unlock()
	return
}
891836
func (c *roles) Update(role *v1beta1.Role) (result *v1beta1.Role, err error) {
	result = &v1beta1.Role{}
	err = c.client.Put().
		Namespace(c.ns).
		Resource("roles").
		Name(role.Name).
		Body(role).
		Do().
		Into(result)
	return
}
74127
func ValidTUFType(typ string, role RoleName) bool {
	if ValidRole(role) {
		// All targets delegation roles must have
		// the valid type is for targets.
		if role == "" {
			// role is unknown and does not map to
			// a type
			return false
		}
		if strings.HasPrefix(role.String(), CanonicalTargetsRole.String()+"/") {
			role = CanonicalTargetsRole
		}
	}
	// most people will just use the defaults so have this optimal check
	// first. Do comparison just in case there is some unknown vulnerability
	// if a key and value in the map differ.
	if v, ok := TUFTypes[role]; ok {
		return typ == v
	}
	return false
}
525731
func (a *AuthWithRoles) UpsertRole(role services.Role) error {
	if err := a.action(defaults.Namespace, services.KindRole, services.VerbCreate); err != nil {
		return trace.Wrap(err)
	}
	if err := a.action(defaults.Namespace, services.KindRole, services.VerbUpdate); err != nil {
		return trace.Wrap(err)
	}
	return a.authServer.UpsertRole(role)
}
426330
func (c *Client) UpdateTemplate(p *UpdateTemplateParameter) (*Template, error) {
	obj, err := c.Request("updateTemplate", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Template), err
}
550528
func (s *RolesStore) Add(ctx context.Context, u *chronograf.Role) (*chronograf.Role, error) {
	return s.AddF(ctx, u)
}
129769
func NewGroupChangeMemberRoleType(Description string) *GroupChangeMemberRoleType {
	s := new(GroupChangeMemberRoleType)
	s.Description = Description
	return s
}
184367
func (c *roleBindings) Update(roleBinding *authorization.RoleBinding) (result *authorization.RoleBinding, err error) {
	result = &authorization.RoleBinding{}
	err = c.client.Put().
		Namespace(c.ns).
		Resource("rolebindings").
		Name(roleBinding.Name).
		Body(roleBinding).
		Do().
		Into(result)
	return
}
191509
func (td TUFDelegation) ToNewRole(scope data.RoleName) (*data.Role, error) {
	name := scope
	if td.NewName != "" {
		name = td.NewName
	}
	return data.NewRole(name, td.NewThreshold, td.AddKeys.IDs(), td.AddPaths)
}
608963
func NewTemplatedConfigGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) TemplatedConfigGetter {
	return templatedConfigGetter{dependencies: dependencies, t: t, node: node}
}
741933
func rolesInPrefix(c context.Context, metas []*api.PrefixMetadata) ([]api.Role, error) {
	roles := roleSet()
	for _, meta := range metas {
		for _, acl := range meta.Acls {
			if _, ok := roles[acl.Role]; ok {
				continue // seen this role already
			}
			switch yes, err := isInACL(c, acl); {
			case err != nil:
				return nil, err
			case yes:
				// Add acl.Role and all roles implied by it to 'roles' set.
				for _, r := range impliedRoles[acl.Role] {
					roles[r] = struct{}{}
				}
			}
		}
	}

	// Arrange the result in the order of Role enum definition.
	out := make([]api.Role, 0, len(roles))
	for r := api.Role_READER; r <= api.Role_OWNER; r++ {
		if _, ok := roles[r]; ok {
			out = append(out, r)
		}
	}
	return out, nil
}
1231419
func (api *API) ModifyRolePermissions(role_id string, perm *Permissions) (*Role, error) {
	result := new(Role)
	url := createUrl(api, rolePathSegment, role_id, "permissions")
	err := api.Client.Put(url, &perm, &result, http.StatusOK)
	if err != nil {
		return nil, err
	}
	result.api = api
	return result, nil
}
581728
func (ti *TemplateInfo) Add(ts ...dm.Quest_TemplateSpec) {
	*ti = append(*ti, ts...)
	sort.Sort(*ti)
	*ti = (*ti)[:set.Uniq(*ti)]
}
395324
func (set RoleSet) CertificateFormat() string {
	var formats []string

	for _, role := range set {
		// get the certificate format for each individual role. if a role does not
		// have a certificate format (like implicit roles) skip over it
		certificateFormat := role.GetOptions().CertificateFormat
		if certificateFormat == "" {
			continue
		}

		formats = append(formats, certificateFormat)
	}

	// if no formats were found, return standard
	if len(formats) == 0 {
		return teleport.CertificateFormatStandard
	}

	// sort the slice so the most permissive is the first element
	sort.Slice(formats, func(i, j int) bool {
		return certificatePriority(formats[i]) < certificatePriority(formats[j])
	})

	return formats[0]
}
741860
func (rs *RoleService) Update(ctx context.Context, roleName string, role *Role) (
	r *Role, resp *APIResponse, err error) {

	r = &Role{}
	_, resp, err = rs.client.putAction(ctx, &APIClientRequest{
		APIVersion:   apiV1,
		Path:         fmt.Sprintf("admin/security/roles/%s", roleName),
		ResponseBody: r,
		RequestBody:  role,
	})

	return
}