def Run(self, args): """Run 'runtime-configs variables set'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The new variable. Raises: HttpException: An http error response was received while executing api request. """ variable_client = util.VariableClient() messages = util.Messages() var_resource = util.ParseVariableName(args.name, args) try: variable_client.Delete( messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest( name=var_resource.RelativeName(), recursive=args.recursive, )) log.DeletedResource(var_resource) except apitools_exceptions.HttpNotFoundError: # Raise this failure if the user requested it. if args.fail_if_absent: raise
def testParseVariableNameMultiSegment(self): args = argparse.Namespace(config_name='foo') resource = util.ParseVariableName('bar/bar2', args) self.assertEqual(resource.projectsId, 'test-project') self.assertEqual(resource.configsId, 'foo') self.assertEqual(resource.variablesId, 'bar/bar2') self.assertEqual(resource.Name(), 'bar/bar2')
def testParseVariableNameHttp(self): args = argparse.Namespace() url = ( 'https://runtimeconfig.googleapis.com/v1beta1/projects/other-proj' '/configs/other-config/variables/other-var/var2') resource = util.ParseVariableName(url, args) self.assertEqual(resource.projectsId, 'other-proj') self.assertEqual(resource.configsId, 'other-config') self.assertEqual(resource.variablesId, 'other-var/var2') self.assertEqual(resource.Name(), 'other-var/var2')
def Run(self, args): """Run a command that watches a variable. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The WatchVariable response. Raises: HttpException: An http error response was received while executing api request. """ # Disable retries and configure the timeout. variable_client = util.VariableClient(num_retries=0, timeout=args.max_wait) messages = util.Messages() var_resource = util.ParseVariableName(args.name, args) if args.newer_than: newer_than = times.FormatDateTime(args.newer_than) else: newer_than = None with progress_tracker.ProgressTracker( 'Waiting for variable [{0}] to change'.format( var_resource.Name())): try: return util.FormatVariable( variable_client.Watch( messages. RuntimeconfigProjectsConfigsVariablesWatchRequest( name=var_resource.RelativeName(), watchVariableRequest=messages.WatchVariableRequest( newerThan=newer_than, )))) except apitools_exceptions.HttpError as error: # For deadline exceeded or bad gateway errors, # we return a status code of 2. # In some cases, the GFE will timeout before the backend # responds with a 504 Gateway Timeout (DEADLINE_EXCEEDED). # In that scenario, GFE responds first with a 502 BAD GATEWAY error. if util.IsDeadlineExceededError( error) or util.IsBadGatewayError(error): _RaiseTimeout() raise except socket.error as error: if util.IsSocketTimeout(error): _RaiseTimeout() raise
def Run(self, args): """Run 'runtime-configs variables set'. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The new variable. Raises: HttpException: An http error response was received while executing api request. """ var_resource = util.ParseVariableName(args.name, args) if args.value is None: log.status.Print( 'No value argument specified; reading value from stdin.') value = sys.stdin.read() else: value = args.value if args.fail_if_absent: # Update case return self._Update(args, var_resource, value) else: # Either create or create-or-update try: return self._Create(args, var_resource, value) except apitools_exceptions.HttpError as error: # If --fail-if-present was not specified, and we got an # Already Exists error, try updating instead. if not args.fail_if_present and util.IsAlreadyExistsError( error): return self._Update(args, var_resource, value) # If --fail-if-present was specified, or some other error # occurred, re-raise the error. raise
def Run(self, args): """Run a command that retrieves a variable. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: The requested variable. Raises: HttpException: An http error response was received while executing api request. """ variable_client = util.VariableClient() messages = util.Messages() var_resource = util.ParseVariableName(args.name, args) return variable_client.Get( messages.RuntimeconfigProjectsConfigsVariablesGetRequest( name=var_resource.RelativeName(), ))