// ResourceTags returns tags to set on an infrastructure resource
// for the specified Juju environment.
174006
func ResourceTags(modelTag names.ModelTag, controllerTag names.ControllerTag, taggers ...ResourceTagger) map[string]string {
	allTags := make(map[string]string)
	for _, tagger := range taggers {
		tags, ok := tagger.ResourceTags()
		if !ok {
			continue
		}
		for k, v := range tags {
			allTags[k] = v
		}
	}
	allTags[JujuModel] = modelTag.Id()
	allTags[JujuController] = controllerTag.Id()
	return allTags
}
979242
func (m *KopsModelContext) CloudTags(name string, shared bool) map[string]string {
	tags := make(map[string]string)

	switch kops.CloudProviderID(m.Cluster.Spec.CloudProvider) {
	case kops.CloudProviderAWS:
		if shared {
			// If the resource is shared, we don't try to set the Name - we presume that is managed externally
			glog.V(4).Infof("Skipping Name tag for shared resource")
		} else {
			if name != "" {
				tags["Name"] = name
			}
		}

		// Kubernetes 1.6 introduced the shared ownership tag; that replaces TagClusterName
		setLegacyTag := true
		if m.IsKubernetesGTE("1.6") {
			// For the moment, we only skip the legacy tag for shared resources
			// (other people may be using it)
			if shared {
				glog.V(4).Infof("Skipping %q tag for shared resource", awsup.TagClusterName)
				setLegacyTag = false
			}
		}
		if setLegacyTag {
			tags[awsup.TagClusterName] = m.Cluster.ObjectMeta.Name
		}

		if shared {
			tags["kubernetes.io/cluster/"+m.Cluster.ObjectMeta.Name] = "shared"
		} else {
			tags["kubernetes.io/cluster/"+m.Cluster.ObjectMeta.Name] = "owned"
		}

	}
	return tags
}
263106
func (c *aliCloudImplementation) RemoveTags(resourceId string, resourceType string, tags map[string]string) error {
	if len(tags) == 0 {
		return nil
	}
	if resourceId == "" {
		return errors.New("resourceId not provided to RemoveTags")
	}
	if resourceType == "" {
		return errors.New("resourceType not provided to RemoveTags")
	}

	request := &ecs.RemoveTagsArgs{
		ResourceId:   resourceId,
		ResourceType: ecs.TagResourceType(resourceType), //image, instance, snapshot or disk
		RegionId:     common.Region(c.Region()),
		Tag:          tags,
	}
	err := c.EcsClient().RemoveTags(request)
	if err != nil {
		return fmt.Errorf("error removing tags on %v: %v", resourceId, err)
	}

	return nil
}
676096
func getTags(addr *url.URL, server_name string) map[string]string {
	h := addr.Host
	host, port, err := net.SplitHostPort(h)
	if err != nil {
		host = addr.Host
		if addr.Scheme == "http" {
			port = "80"
		} else if addr.Scheme == "https" {
			port = "443"
		} else {
			port = ""
		}
	}
	return map[string]string{"server": host, "port": port, "server_name": server_name}
}
1227221
func (c *awsCloudImplementation) GetTags(resourceID string) (map[string]string, error) {
	return getTags(c, resourceID)
}
782348
func Tags(b *pb.Build) strpair.Map {
	m := make(strpair.Map, len(b.Tags))
	for _, t := range b.Tags {
		m.Add(t.Key, t.Value)
	}
	return m
}
1221522
func (s *RepositoriesService) ListTags(ctx context.Context, owner string, repo string, opt *ListOptions) ([]*RepositoryTag, *Response, error) {
	u := fmt.Sprintf("repos/%v/%v/tags", owner, repo)
	u, err := addOptions(u, opt)
	if err != nil {
		return nil, nil, err
	}

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	var tags []*RepositoryTag
	resp, err := s.client.Do(ctx, req, &tags)
	if err != nil {
		return nil, resp, err
	}

	return tags, resp, nil
}
1293811
func (s *ListTagsForResourcesOutput) SetResourceTagSets(v []*ResourceTagSet) *ListTagsForResourcesOutput {
	s.ResourceTagSets = v
	return s
}
1191105
func (c *Client) ListTags(p *ListTagsParameter) ([]*Tag, error) {
	obj, err := c.Request("listTags", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.([]*Tag), err
}
781011
func setTagsSSM(conn *ssm.SSM, d *schema.ResourceData, id, resourceType string) error {
	if d.HasChange("tags") {
		oraw, nraw := d.GetChange("tags")
		o := oraw.(map[string]interface{})
		n := nraw.(map[string]interface{})
		create, remove := diffTagsSSM(tagsFromMapSSM(o), tagsFromMapSSM(n))

		// Set tags
		if len(remove) > 0 {
			log.Printf("[DEBUG] Removing tags: %#v", remove)
			k := make([]*string, len(remove))
			for i, t := range remove {
				k[i] = t.Key
			}

			_, err := conn.RemoveTagsFromResource(&ssm.RemoveTagsFromResourceInput{
				ResourceId:   aws.String(id),
				ResourceType: aws.String(resourceType),
				TagKeys:      k,
			})
			if err != nil {
				return err
			}
		}
		if len(create) > 0 {
			log.Printf("[DEBUG] Creating tags: %#v", create)
			_, err := conn.AddTagsToResource(&ssm.AddTagsToResourceInput{
				ResourceId:   aws.String(id),
				ResourceType: aws.String(resourceType),
				Tags:         create,
			})
			if err != nil {
				return err
			}
		}
	}

	return nil
}
786205
func (s *ListTagsOutput) SetResourceTagList(v []*ResourceTag) *ListTagsOutput {
	s.ResourceTagList = v
	return s
}
263036
func (i *item) Tags() (map[string]interface{}, error) {
	i.tagsOnce.Do(func() {
		params := &s3.GetObjectTaggingInput{
			Bucket: aws.String(i.container.name),
			Key:    aws.String(i.ID()),
		}

		res, err := i.client.GetObjectTagging(params)
		if err != nil {
			if strings.Contains(err.Error(), "NoSuchKey") {
				i.tagsErr = stow.ErrNotFound
				return
			}
			i.tagsErr = errors.Wrap(err, "getObjectTagging")
			return
		}

		i.tags = make(map[string]interface{})
		for _, t := range res.TagSet {
			i.tags[*t.Key] = *t.Value
		}
	})

	return i.tags, i.tagsErr
}
1081373
func yamlTags(t reflect.Type) map[string]int {
	if t.Kind() != reflect.Struct {
		panic(errors.Errorf("cannot get yaml tags on type %s", t))
	}
	tags := make(map[string]int)
	for i := 0; i < t.NumField(); i++ {
		f := t.Field(i)
		if f.Type != reflect.TypeOf("") {
			continue
		}
		if tag := f.Tag.Get("yaml"); tag != "" {
			if i := strings.Index(tag, ","); i >= 0 {
				tag = tag[0:i]
			}
			if tag == "-" {
				continue
			}
			if tag != "" {
				f.Name = tag
			}
		}
		tags[f.Name] = i
	}
	return tags
}
959876
func (blog *BLog) Tags() map[string]string {
	blog.lock.RLock()
	defer blog.lock.RUnlock()
	return blog.tags
}
1012730
func (writer *SocketWriter) Tags() map[string]string {
	writer.lock.RLock()
	defer writer.lock.RUnlock()
	return writer.tags
}
531713
func (c CloudstackClient) CreateTags(options *CreateTags) (CreateTagsResponse, error) {
	var resp CreateTagsResponse
	params := url.Values{}

	params.Set("resourceids", strings.Join(options.Resourceids, ","))
	params.Set("resourcetype", options.Resourcetype)
	for j, tag := range options.Tags {
		params.Set("tags["+strconv.Itoa(j+1)+"].key", tag.Key)
		params.Set("tags["+strconv.Itoa(j+1)+"].value", tag.Value)
	}

	if options.Customer != "" {
		params.Set("customer", options.Customer)
	}

	response, err := NewRequest(c, "createTags", params)
	if err != nil {
		return resp, err
	}

	resp = response.(CreateTagsResponse)
	return resp, err
}
624523
func InstanceTags(modelUUID, controllerUUID string, tagger tags.ResourceTagger, jobs []multiwatcher.MachineJob) map[string]string {
	instanceTags := tags.ResourceTags(
		names.NewModelTag(modelUUID),
		names.NewControllerTag(controllerUUID),
		tagger,
	)
	if multiwatcher.AnyJobNeedsState(jobs...) {
		instanceTags[tags.JujuIsController] = "true"
	}
	return instanceTags
}