yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/tag_base.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package aliyun
    16  
    17  import (
    18  	"strings"
    19  
    20  	"yunion.io/x/pkg/errors"
    21  
    22  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    23  	"yunion.io/x/cloudmux/pkg/multicloud"
    24  )
    25  
    26  type AliyunTags struct {
    27  	Tags struct {
    28  		Tag []multicloud.STag
    29  
    30  		// Kafka
    31  		TagVO []multicloud.STag `json:"TagVO" yunion-deprecated-by:"Tag"`
    32  	}
    33  }
    34  
    35  func (self *AliyunTags) GetTags() (map[string]string, error) {
    36  	ret := map[string]string{}
    37  	for _, tag := range self.Tags.Tag {
    38  		if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") ||
    39  			strings.HasSuffix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") ||
    40  			strings.HasSuffix(tag.Key, "ack.aliyun.com") { // k8s
    41  			continue
    42  		}
    43  		if len(tag.TagKey) > 0 {
    44  			ret[tag.TagKey] = tag.TagValue
    45  		} else if len(tag.Key) > 0 {
    46  			ret[tag.Key] = tag.Value
    47  		}
    48  	}
    49  
    50  	return ret, nil
    51  }
    52  
    53  func (self *AliyunTags) GetSysTags() map[string]string {
    54  	ret := map[string]string{}
    55  	for _, tag := range self.Tags.Tag {
    56  		if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") ||
    57  			strings.HasPrefix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") ||
    58  			strings.HasPrefix(tag.Key, "ack.aliyun.com") { // k8s
    59  			if len(tag.TagKey) > 0 {
    60  				ret[tag.TagKey] = tag.TagValue
    61  			} else if len(tag.Key) > 0 {
    62  				ret[tag.Key] = tag.Value
    63  			}
    64  		}
    65  	}
    66  	return ret
    67  }
    68  
    69  func (self *AliyunTags) SetTags(tags map[string]string, replace bool) error {
    70  	return errors.Wrap(cloudprovider.ErrNotImplemented, "SetTags")
    71  }
    72  
    73  type SAliyunTag struct {
    74  	ResourceId   string
    75  	ResourceType string
    76  	TagKey       string
    77  	TagValue     string
    78  }