def Run(self, args): service = tags.TagValuesService() messages = tags.TagMessages() if args.RESOURCE_NAME.find('tagValues/') == 0: tag_value = args.RESOURCE_NAME else: tag_value = tag_utils.GetTagValueFromNamespacedName( args.RESOURCE_NAME).name get_iam_policy_req = ( messages.CloudresourcemanagerTagValuesGetIamPolicyRequest( resource=tag_value)) policy = service.GetIamPolicy(get_iam_policy_req) condition = iam_util.ValidateAndExtractConditionMutexRole(args) iam_util.AddBindingToIamPolicyWithCondition(messages.Binding, messages.Expr, policy, args.member, args.role, condition) set_iam_policy_request = messages.SetIamPolicyRequest(policy=policy) request = messages.CloudresourcemanagerTagValuesSetIamPolicyRequest( resource=tag_value, setIamPolicyRequest=set_iam_policy_request) result = service.SetIamPolicy(request) iam_util.LogSetIamPolicy(tag_value, 'TagValue') return result
def Run(self, args): messages = tags.TagMessages() if args.tag_value.find("tagValues/") == 0: tag_value = args.tag_value else: tag_value = tag_utils.GetTagValueFromNamespacedName( args.tag_value).name binding_name = "/".join( ["tagBindings", quote(args.parent, safe=""), tag_value]) del_req = messages.CloudresourcemanagerTagBindingsDeleteRequest( name=binding_name) location = args.location if args.IsSpecified("location") else None with endpoints.CrmEndpointOverrides(location): service = tags.TagBindingsService() op = service.Delete(del_req) if args.async_ or op.done: return op else: return operations.WaitForOperation( op, "Waiting for TagBinding for resource [{}] and tag value [{}] to be " "deleted with [{}]".format(args.parent, args.tag_value, op.name), service=service)
def Run(self, args): messages = tags.TagMessages() if args.tag_value.find("tagValues/") == 0: tag_value = args.tag_value else: tag_value = tag_utils.GetTagValueFromNamespacedName( args.tag_value).name tag_binding = messages.TagBinding(parent=args.parent, tagValue=tag_value) create_req = messages.CloudresourcemanagerTagBindingsCreateRequest( tagBinding=tag_binding) location = args.location if args.IsSpecified("location") else None with endpoints.CrmEndpointOverrides(location): service = tags.TagBindingsService() op = service.Create(create_req) if args.async_ or op.done: return op else: return operations.WaitForOperation( op, "Waiting for TagBinding for parent [{}] and tag value [{}] to be " "created with [{}]".format(args.parent, args.tag_value, op.name), service=service)
def Run(self, args): service = tags.TagValuesService() messages = tags.TagMessages() if args.RESOURCE_NAME.find('tagValues/') == 0: tag_value = args.RESOURCE_NAME else: tag_value = tag_utils.GetTagValueFromNamespacedName( args.RESOURCE_NAME).name get_request = messages.CloudresourcemanagerTagValuesGetRequest( name=tag_value) return service.Get(get_request)
def GetSecureTags(secure_tags): """Returns a list of secure tags, translating namespaced tags if needed. Args: secure_tags: array of secure tag values with either namespaced name or name. Returns: List of secure tags with format tagValues/[0-9]+ """ ret_secure_tags = [] for tag in secure_tags: if tag.startswith('tagValues/'): ret_secure_tags.append(tag) else: ret_secure_tags.append( tag_utils.GetTagValueFromNamespacedName(tag).name) return ret_secure_tags
def GetResourceManagerTags(resource_manager_tags): """Returns a map of resource manager tags, translating namespaced tags if needed. Args: resource_manager_tags: Map of resource manager tag key value pairs with either namespaced name or name. Returns: Map of resource manager tags with format tagKeys/[0-9]+, tagValues/[0-9]+ """ ret_resource_manager_tags = {} for key, value in resource_manager_tags.items(): if not key.startswith('tagKeys/'): key = tag_utils.GetTagKeyFromNamespacedName(key).name if not value.startswith('tagValues/'): value = tag_utils.GetTagValueFromNamespacedName(value).name ret_resource_manager_tags[key] = value return ret_resource_manager_tags
def Run(self, args): service = tags.TagValuesService() messages = tags.TagMessages() if args.RESOURCE_NAME.find('tagValues/') == 0: tag_value = args.RESOURCE_NAME else: tag_value = tag_utils.GetTagValueFromNamespacedName( args.RESOURCE_NAME).name policy = iam_util.ParsePolicyFile(args.POLICY_FILE, messages.Policy) policy.version = iam_util.MAX_LIBRARY_IAM_SUPPORTED_VERSION set_iam_policy_request = messages.SetIamPolicyRequest(policy=policy) request = messages.CloudresourcemanagerTagValuesSetIamPolicyRequest( resource=tag_value, setIamPolicyRequest=set_iam_policy_request) result = service.SetIamPolicy(request) iam_util.LogSetIamPolicy(tag_value, 'TagValue') return result
def Run(self, args): service = tags.TagValuesService() messages = tags.TagMessages() if args.RESOURCE_NAME.find('tagValues/') == 0: tag_value = args.RESOURCE_NAME else: tag_value = tag_utils.GetTagValueFromNamespacedName( args.RESOURCE_NAME).name delete_request = messages.CloudresourcemanagerTagValuesDeleteRequest( name=tag_value) op = service.Delete(delete_request) if args.async_: return op return operations.WaitForOperation( op, 'Waiting for TagValue [{}] to be deleted'.format(tag_value), service=service)
def TranslateSecureTagsForFirewallPolicy(client, secure_tags): """Returns a list of firewall policy rule secure tags, translating namespaced tags if needed. Args: client: compute client secure_tags: array of secure tag values Returns: List of firewall policy rule secure tags """ ret_secure_tags = [] for tag in secure_tags: if tag.startswith('tagValues/'): ret_secure_tags.append( client.messages.FirewallPolicyRuleSecureTag(name=tag)) else: ret_secure_tags.append( client.messages.FirewallPolicyRuleSecureTag( name=tag_utils.GetTagValueFromNamespacedName(tag).name)) return ret_secure_tags
def Run(self, args): service = tags.TagValuesService() messages = tags.TagMessages() if args.RESOURCE_NAME.find('tagValues/') == 0: tag_value = tag_utils.GetResourceFromNamespacedName( args.RESOURCE_NAME, 'tagValues') else: tag_value = tag_utils.GetTagValueFromNamespacedName( args.RESOURCE_NAME) tag_value.description = args.description update_request = messages.CloudresourcemanagerTagValuesPatchRequest( name=tag_value.name, tagValue=tag_value, updateMask='description') op = service.Patch(update_request) if args.async_: return op return operations.WaitForOperation( op, 'Waiting for TagValue [{}] to be updated'.format(tag_value.name), service=service)