// Ensure that a resource has the correct tags
// If it has no tags, we assume that this was a problem caused by an error in between creation and tagging,
// and we add the tags.  If it has a different cluster's tags, that is an error.
162873
func (t *awsTagging) readRepairClusterTags(client EC2, resourceID string, lifecycle ResourceLifecycle, additionalTags map[string]string, observedTags []*ec2.Tag) error {
	actualTagMap := make(map[string]string)
	for _, tag := range observedTags {
		actualTagMap[aws.StringValue(tag.Key)] = aws.StringValue(tag.Value)
	}

	expectedTags := t.buildTags(lifecycle, additionalTags)

	addTags := make(map[string]string)
	for k, expected := range expectedTags {
		actual := actualTagMap[k]
		if actual == expected {
			continue
		}
		if actual == "" {
			klog.Warningf("Resource %q was missing expected cluster tag %q.  Will add (with value %q)", resourceID, k, expected)
			addTags[k] = expected
		} else {
			return fmt.Errorf("resource %q has tag belonging to another cluster: %q=%q (expected %q)", resourceID, k, actual, expected)
		}
	}

	if len(addTags) == 0 {
		return nil
	}

	if err := t.createTags(client, resourceID, lifecycle, addTags); err != nil {
		return fmt.Errorf("error adding missing tags to resource %q: %q", resourceID, err)
	}

	return nil
}
911087
func CheckWithTag(organizer, project, now string) (string, error) {
	return Check(organizer, project, now, "tag_name")
}
1046464
func StorageTags(
	storageInstance state.StorageInstance,
	modelUUID, controllerUUID string,
	tagger tags.ResourceTagger,
) (map[string]string, error) {
	storageTags := tags.ResourceTags(
		names.NewModelTag(modelUUID),
		names.NewControllerTag(controllerUUID),
		tagger,
	)
	if storageInstance != nil {
		storageTags[tags.JujuStorageInstance] = storageInstance.Tag().Id()
		if owner, ok := storageInstance.Owner(); ok {
			storageTags[tags.JujuStorageOwner] = owner.Id()
		}
	}
	return storageTags, nil
}
1042384
func (s *ResourcetagsService) ListStorageTags(p *ListStorageTagsParams) (*ListStorageTagsResponse, error) {
	resp, err := s.cs.newRequest("listStorageTags", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ListStorageTagsResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
603047
func getTagsDX(conn *directconnect.DirectConnect, d *schema.ResourceData, arn string) error {
	resp, err := conn.DescribeTags(&directconnect.DescribeTagsInput{
		ResourceArns: aws.StringSlice([]string{arn}),
	})
	if err != nil {
		return err
	}

	var tags []*directconnect.Tag
	if len(resp.ResourceTags) == 1 && aws.StringValue(resp.ResourceTags[0].ResourceArn) == arn {
		tags = resp.ResourceTags[0].Tags
	}

	if err := d.Set("tags", tagsToMapDX(tags)); err != nil {
		return err
	}

	return nil
}
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
}
754752
func tagsFromMapElasticsearchService(m map[string]interface{}) []*elasticsearch.Tag {
	var result []*elasticsearch.Tag
	for k, v := range m {
		t := &elasticsearch.Tag{
			Key:   aws.String(k),
			Value: aws.String(v.(string)),
		}
		if !tagIgnoredElasticsearchService(t) {
			result = append(result, t)
		}
	}

	return result
}
837422
func tagsFromMapNeptune(m map[string]interface{}) []*neptune.Tag {
	result := make([]*neptune.Tag, 0, len(m))
	for k, v := range m {
		t := &neptune.Tag{
			Key:   aws.String(k),
			Value: aws.String(v.(string)),
		}
		if !tagIgnoredNeptune(t) {
			result = append(result, t)
		}
	}

	return result
}
577030
func (r *Registry) Tags(ctx context.Context, repository string) ([]string, error) {
	url := r.url("/v2/%s/tags/list", repository)
	r.Logf("registry.tags url=%s repository=%s", url, repository)

	var response tagsResponse
	if _, err := r.getJSON(ctx, url, &response); err != nil {
		return nil, err
	}

	return response.Tags, nil
}
397492
func intersectTags(tags []*ec2.Tag, desired map[string]string) map[string]string {
	if tags == nil {
		return nil
	}
	actual := make(map[string]string)
	for _, t := range tags {
		k := aws.StringValue(t.Key)
		v := aws.StringValue(t.Value)

		if _, found := desired[k]; found {
			actual[k] = v
		}
	}
	if len(actual) == 0 && desired == nil {
		// Avoid problems with comparison between nil & {}
		return nil
	}
	return actual
}
211741
func (s *ListTagsForResourceOutput) SetResourceTags(v []*Tag) *ListTagsForResourceOutput {
	s.ResourceTags = v
	return s
}
2918
func (c *Client) CreateTags(p *CreateTagsParameter) (*Result, error) {
	obj, err := c.Request("createTags", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Result), err
}
794654
func (r Resource) Required() string {
	required := []string{}

	for name, property := range r.Properties {
		if property.Required {
			required = append(required, `"`+name+`"`)
		}
	}

	// As Go doesn't provide ordering guarentees for maps, we should
	// sort the required property names by alphabetical order so that
	// they don't shuffle on every generation, and cause annoying commit diffs
	sort.Strings(required)

	return strings.Join(required, ", ")
}
889648
func (c *aliCloudImplementation) AddClusterTags(tags map[string]string) {

	if c.tags != nil && len(c.tags) != 0 && tags != nil {
		for k, v := range c.tags {
			tags[k] = v
		}
	}
}
654934
func HasSharedTag(description string, tags []*ec2.Tag, clusterName string) bool {
	tagKey := "kubernetes.io/cluster/" + clusterName

	var found *ec2.Tag
	for _, tag := range tags {
		if aws.StringValue(tag.Key) != tagKey {
			continue
		}

		found = tag
	}

	if found == nil {
		glog.Warningf("(new) cluster tag not found on %s", description)
		return false
	}

	tagValue := aws.StringValue(found.Value)
	switch tagValue {
	case "owned":
		return false
	case "shared":
		return true

	default:
		glog.Warningf("unknown cluster tag on %s: %q=%q", description, tagKey, tagValue)
		return false
	}
}
839390
func (k *kubernetesClient) EnsureCustomResourceDefinition(appName string, podSpec *caas.PodSpec) error {
	for name, crd := range podSpec.CustomResourceDefinitions {
		crd, err := k.ensureCustomResourceDefinitionTemplate(name, crd)
		if err != nil {
			return errors.Annotate(err, fmt.Sprintf("ensure custom resource definition %q", name))
		}
		logger.Debugf("ensured custom resource definition %q", crd.ObjectMeta.Name)
	}
	return nil
}
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
}