// CreateLabelMapping creates a new mapping between a resource and a label.
195335
func (c *Client) CreateLabelMapping(ctx context.Context, m *influxdb.LabelMapping) error {
	_, err := c.FindLabelByID(ctx, m.LabelID)
	if err != nil {
		return &influxdb.Error{
			Err: err,
			Op:  getOp(influxdb.OpCreateLabel),
		}
	}

	err = c.db.Update(func(tx *bolt.Tx) error {
		return c.putLabelMapping(ctx, tx, m)
	})

	if err != nil {
		return &influxdb.Error{
			Err: err,
			Op:  getOp(influxdb.OpCreateLabel),
		}
	}

	return nil
}
1140327
func LabelFilter(key, value string) map[string][]string {
	return map[string][]string{
		"label": {fmt.Sprintf("%s=%s", key, value)},
	}
}
53307
func NewLabels(labels ...*Label) error {
	_, err := x.Insert(labels)
	return err
}
911688
func newLabelResponse(l *plat.Label) *labelResponse {
	return &labelResponse{
		Links: map[string]string{
			"resource": fmt.Sprintf("/api/v2/%ss/%s", "dashboard", l.ResourceID),
		},
		Label: *l,
	}
}
636443
func (s *Service) createOrgDependentMappings(ctx context.Context, tx Tx, m *influxdb.UserResourceMapping) error {
	span, ctx := tracing.StartSpanFromContext(ctx)
	defer span.Finish()

	bf := influxdb.BucketFilter{OrganizationID: &m.ResourceID}
	bs, err := s.findBuckets(ctx, tx, bf)
	if err != nil {
		return err
	}
	for _, b := range bs {
		m := &influxdb.UserResourceMapping{
			ResourceType: influxdb.BucketsResourceType,
			ResourceID:   b.ID,
			UserType:     m.UserType,
			UserID:       m.UserID,
		}
		if err := s.createUserResourceMapping(ctx, tx, m); err != nil {
			return err
		}
		// TODO(desa): add support for all other resource types.
	}

	return nil
}
946405
func (r *Request) QueryOptionLabel(key string, labels map[string]string) *Request {
	if r.err != nil {
		return r
	}
	if b, err := json.Marshal(labels); err != nil {
		r.err = err
	} else {
		if r.params == nil {
			r.params = make(url.Values)
		}
		r.params.Add(string(key), string(b))
	}
	return r
}
232185
func CreateMap(values ...interface{}) (map[string]interface{}, error) {
	if len(values)%2 != 0 {
		return nil, errors.New("invalid map call")
	}
	dict := make(map[string]interface{}, len(values)/2)
	for i := 0; i < len(values); i += 2 {
		key, ok := values[i].(string)
		if !ok {
			return nil, errors.New("map keys must be strings")
		}
		dict[key] = values[i+1]
	}
	return dict, nil
}
1175228
func (s *Service) CreateLabelMapping(ctx context.Context, m *influxdb.LabelMapping) error {
	return s.kv.Update(ctx, func(tx Tx) error {
		return s.createLabelMapping(ctx, tx, m)
	})
}
434897
func newPodLabels(pod *v1.Pod) map[string]string {
	labels := map[string]string{}

	// Get labels from v1.Pod
	for k, v := range pod.Labels {
		labels[k] = v
	}

	labels[types.KubernetesPodNameLabel] = pod.Name
	labels[types.KubernetesPodNamespaceLabel] = pod.Namespace
	labels[types.KubernetesPodUIDLabel] = string(pod.UID)

	return labels
}
1015753
func (s *Service) CreateLabel(ctx context.Context, l *influxdb.Label) error {
	l.ID = s.IDGenerator.ID()
	s.labelKV.Store(l.ID, *l)
	return nil
}
1371879
func (c *Client) EndpointLabelsGet(id string) (*models.LabelConfiguration, error) {
	params := endpoint.NewGetEndpointIDLabelsParams().WithID(id).WithTimeout(api.ClientTimeout)
	resp, err := c.Endpoint.GetEndpointIDLabels(params)
	if err != nil {
		return nil, Hint(err)
	}
	return resp.Payload, nil
}
243084
func (s *UserResourceMappingService) CreateUserResourceMapping(ctx context.Context, m *platform.UserResourceMapping) error {
	return s.CreateMappingFn(ctx, m)
}
1242765
func (s *Service) DeleteLabelMapping(ctx context.Context, m *influxdb.LabelMapping) error {
	s.labelMappingKV.Delete(encodeLabelMappingKey(m))
	return nil
}
698059
func NewLabelService() *LabelService {
	return &LabelService{
		FindLabelsFn: func(context.Context, platform.LabelFilter) ([]*platform.Label, error) {
			return nil, nil
		},
		CreateLabelFn: func(context.Context, *platform.Label) error { return nil },
		UpdateLabelFn: func(context.Context, *platform.Label, platform.LabelUpdate) (*platform.Label, error) { return nil, nil },
		DeleteLabelFn: func(context.Context, platform.Label) error { return nil },
	}
}
1341602
func (r *Application) AddLabel(name, value string) *Application {
	if r.Labels == nil {
		r.EmptyLabels()
	}
	(*r.Labels)[name] = value

	return r
}
230760
func NewLabelsFromModel(base []string) Labels {
	lbls := make(Labels, len(base))
	for _, v := range base {
		if lbl := ParseLabel(v); lbl.Key != "" {
			lbls[lbl.Key] = lbl
		}
	}

	return lbls
}
224659
func (client DefaultClient) CreateMapping(projectID, componentID, versionID string) (Mapping, error) {
	pId, err := strconv.Atoi(projectID)
	if err != nil {
		return Mapping{}, err
	}
	cId, err := strconv.Atoi(componentID)
	if err != nil {
		return Mapping{}, err
	}
	vId, err := strconv.Atoi(versionID)
	if err != nil {
		return Mapping{}, err
	}

	data, err := json.Marshal(&Mapping{ProjectID: pId, ComponentID: cId, VersionID: vId, Released: false})
	if err != nil {
		return Mapping{}, err
	}

	req, err := http.NewRequest("POST", fmt.Sprintf("%s/rest/com.deniz.jira.mapping/latest/", client.baseURL), bytes.NewBuffer(data))
	if err != nil {
		return Mapping{}, err
	}
	req.Header.Set("Content-type", "application/json")
	req.SetBasicAuth(client.username, client.password)

	response, err := client.httpClient.Do(req)
	if err != nil {
		return Mapping{}, err
	}
	defer response.Body.Close()

	data, err = ioutil.ReadAll(response.Body)
	if err != nil {
		return Mapping{}, err
	}

	if response.StatusCode != http.StatusCreated {
		logger.Printf("JIRA response: %s\n", string(data))
		return Mapping{}, fmt.Errorf("error creating mapped version.  Status code: %d.\n", response.StatusCode)
	}

	if location, err := response.Location(); err != nil {
		log.Printf("create-mapping response has no Location header.  Unable to acquire created mapping ID\n")
		return Mapping{}, nil
	} else {
		h := location.String()
		id, err := strconv.Atoi(h[strings.LastIndex(h, "/")+1:])
		if err != nil {
			log.Printf("create-mapping response Location header %s has unparseable non-integer urlPrefix/N mapping ID\n", h)
			return Mapping{}, nil
		}
		return Mapping{ID: id}, nil
	}

}