def Run(self, args): """Get the (effective) resource settings. If --effective is not specified, it is a regular resource setting and it is retrieved using GetValue. If --effective is specified, it is an effective setting and it is retrieved using LookupEffectiveValue. Args: args: argparse.Namespace, An object that contains the values for the arguments specified in the Args method. Returns: The retrieved settings. """ settings_service = api_utils.GetServiceFromArgs(args) setting_name = '{}/value'.format(utils.GetSettingsPathFromArgs(args)) if args.effective: get_request = api_utils.GetLookupEffectiveValueRequestFromArgs( args, setting_name) return settings_service.LookupEffectiveValue(get_request) get_request = api_utils.GetGetValueRequestFromArgs(args, setting_name) setting_value = settings_service.GetValue(get_request) return setting_value
def Run(self, args): """Get the resource settings. Args: args: argparse.Namespace, An object that contains the values for the arguments specified in the Args method. Returns: The retrieved settings. """ settings_service = api_utils.GetServiceFromArgs(args) setting_name = '{}/value'.format(utils.GetSettingsPathFromArgs(args)) get_request = api_utils.GetGetValueRequestFromArgs(args, setting_name) setting_value = settings_service.GetValue(get_request) return setting_value
def Run(self, args): """Unset the resource settings. Args: args: argparse.Namespace, An object that contains the values for the arguments specified in the Args method. Returns: The deleted settings. """ settings_service = api_utils.GetServiceFromArgs(args) setting_path = utils.GetSettingsPathFromArgs(args) etag = input.etag if hasattr(input, 'etag') else None delete_request = api_utils.GetPatchRequestFromArgs( args, setting_path, None, etag) setting_value = settings_service.Patch(delete_request) return setting_value
def Run(self, args): """Creates or updates a setting from a JSON or YAML file. Args: args: argparse.Namespace, An object that contains the values for the arguments specified in the Args method. Returns: The created or updated setting. """ settings_service = api_utils.GetServiceFromArgs(args) value_service = api_utils.GetValueServiceFromArgs(args) settings_message = service.ResourceSettingsMessages() input_setting = utils.GetMessageFromFile( args.value_file, settings_message.GoogleCloudResourcesettingsV1alpha1SettingValue) if not input_setting.name: raise exceptions.InvalidInputError( 'Name field not present in the resource setting.') setting_name = '{}/value'.format(utils.GetSettingsPathFromArgs(args)) get_request = api_utils.GetGetValueRequestFromArgs(args, setting_name) try: setting_value = settings_service.GetValue(get_request) except api_exceptions.HttpNotFoundError: create_request = api_utils.GetCreateRequestFromArgs( args, input_setting) create_response = value_service.Create(create_request) return create_response if setting_value == input_setting: return setting_value update_request = api_utils.GetUpdateValueRequestFromArgs( args, input_setting) update_response = settings_service.UpdateValue(update_request) return update_response
def Run(self, args): """Get the (effective) resource settings. If --effective is not specified, it is a regular resource setting and it is retrieved using GetValue. If --effective is specified, it is an effective setting and it is retrieved using LookupEffectiveValue. Args: args: argparse.Namespace, An object that contains the values for the arguments specified in the Args method. Returns: The retrieved settings. """ settings_service = api_utils.GetServiceFromArgs(args) setting_name = utils.GetSettingNameFromArgs(args) setting_path = utils.GetSettingsPathFromArgs(args) if args.effective: get_request = api_utils.GetRequestFromArgs(args, setting_path, True) else: get_request = api_utils.GetRequestFromArgs(args, setting_path, False) try: setting_value = settings_service.Get(get_request) except apitools_exceptions.HttpNotFoundError as e: raise exceptions.HttpException( e, error_format='The setting `' + setting_name + '` has not been set for this resource. Please ' + 'set the setting first or show the flag `--effective` to lookup the effective setting instead.' ) return setting_value