
"""Helper functions for working with the Machine Provider."""

import logging

from components import net
from components import utils


MACHINE_PROVIDER_API_URL = 'https://machine-provider.appspot.com/_ah/api'

CATALOG_BASE_URL = '%s/catalog/v1' % MACHINE_PROVIDER_API_URL
MACHINE_PROVIDER_BASE_URL = '%s/machine_provider/v1' % MACHINE_PROVIDER_API_URL
MACHINE_PROVIDER_SCOPES = (
    'https://www.googleapis.com/auth/userinfo.email',
)


def add_machines(requests):
  """Add machines to the Machine Provider's Catalog.

  Args:
    requests: A list of rpc_messages.CatalogMachineAdditionRequest instances.
  """
  logging.info('Sending batched add_machines request')
  return net.json_request(
      '%s/add_machines' % CATALOG_BASE_URL,
      method='POST',
      payload=utils.to_json_encodable({'requests': requests}),
      scopes=MACHINE_PROVIDER_SCOPES,
  )


"""Helper functions for working with the Machine Provider."""

import logging

from google.appengine.ext import ndb

from components import net
from components import utils
from components.datastore_utils import config


MACHINE_PROVIDER_SCOPES = (
    'https://www.googleapis.com/auth/userinfo.email',
)


class MachineProviderConfiguration(config.GlobalConfig):
  """Configuration for talking to the Machine Provider."""
  # URL of the Machine Provider instance to use.
  instance_url = ndb.StringProperty(required=True)

  @classmethod
  def get_instance_url(cls):
    """Returns the URL of the Machine Provider instance."""
    return cls.cached().instance_url

  def set_defaults(self):
    """Sets default values used to initialize the config."""
    self.instance_url = 'https://machine-provider.appspot.com'


def add_machines(requests):
  """Add machines to the Machine Provider's Catalog.

  Args:
    requests: A list of rpc_messages.CatalogMachineAdditionRequest instances.
  """
  logging.info('Sending batched add_machines request')
  return net.json_request(
      '%s/_ah/api/catalog/v1/add_machines' %
          MachineProviderConfiguration.get_instance_url(),
      method='POST',
      payload=utils.to_json_encodable({'requests': requests}),
      scopes=MACHINE_PROVIDER_SCOPES,
 )

Allow users of the Machine Provider to specify the dev instance for API calls
Allow users of the Machine Provider to specify the dev instance for API calls

BUG=489837

Review URL: https://codereview.chromium.org/1572793002

  
  """Helper functions for working with the Machine Provider."""
  
  import logging
  
+ from google.appengine.ext import ndb
+ 
  from components import net
  from components import utils
+ from components.datastore_utils import config
  
  
- MACHINE_PROVIDER_API_URL = 'https://machine-provider.appspot.com/_ah/api'
- 
- CATALOG_BASE_URL = '%s/catalog/v1' % MACHINE_PROVIDER_API_URL
- MACHINE_PROVIDER_BASE_URL = '%s/machine_provider/v1' % MACHINE_PROVIDER_API_URL
  MACHINE_PROVIDER_SCOPES = (
      'https://www.googleapis.com/auth/userinfo.email',
  )
+ 
+ 
+ class MachineProviderConfiguration(config.GlobalConfig):
+   """Configuration for talking to the Machine Provider."""
+   # URL of the Machine Provider instance to use.
+   instance_url = ndb.StringProperty(required=True)
+ 
+   @classmethod
+   def get_instance_url(cls):
+     """Returns the URL of the Machine Provider instance."""
+     return cls.cached().instance_url
+ 
+   def set_defaults(self):
+     """Sets default values used to initialize the config."""
+     self.instance_url = 'https://machine-provider.appspot.com'
  
  
  def add_machines(requests):
    """Add machines to the Machine Provider's Catalog.
  
    Args:
      requests: A list of rpc_messages.CatalogMachineAdditionRequest instances.
    """
    logging.info('Sending batched add_machines request')
    return net.json_request(
-       '%s/add_machines' % CATALOG_BASE_URL,
+       '%s/_ah/api/catalog/v1/add_machines' %
+           MachineProviderConfiguration.get_instance_url(),
        method='POST',
        payload=utils.to_json_encodable({'requests': requests}),
        scopes=MACHINE_PROVIDER_SCOPES,
-   )
+  )
  
Allow users of the Machine Provider to specify the dev instance for API calls
## Code Before:

"""Helper functions for working with the Machine Provider."""

import logging

from components import net
from components import utils


MACHINE_PROVIDER_API_URL = 'https://machine-provider.appspot.com/_ah/api'

CATALOG_BASE_URL = '%s/catalog/v1' % MACHINE_PROVIDER_API_URL
MACHINE_PROVIDER_BASE_URL = '%s/machine_provider/v1' % MACHINE_PROVIDER_API_URL
MACHINE_PROVIDER_SCOPES = (
    'https://www.googleapis.com/auth/userinfo.email',
)


def add_machines(requests):
  """Add machines to the Machine Provider's Catalog.

  Args:
    requests: A list of rpc_messages.CatalogMachineAdditionRequest instances.
  """
  logging.info('Sending batched add_machines request')
  return net.json_request(
      '%s/add_machines' % CATALOG_BASE_URL,
      method='POST',
      payload=utils.to_json_encodable({'requests': requests}),
      scopes=MACHINE_PROVIDER_SCOPES,
  )

## Instruction:
Allow users of the Machine Provider to specify the dev instance for API calls
## Code After:

"""Helper functions for working with the Machine Provider."""

import logging

from google.appengine.ext import ndb

from components import net
from components import utils
from components.datastore_utils import config


MACHINE_PROVIDER_SCOPES = (
    'https://www.googleapis.com/auth/userinfo.email',
)


class MachineProviderConfiguration(config.GlobalConfig):
  """Configuration for talking to the Machine Provider."""
  # URL of the Machine Provider instance to use.
  instance_url = ndb.StringProperty(required=True)

  @classmethod
  def get_instance_url(cls):
    """Returns the URL of the Machine Provider instance."""
    return cls.cached().instance_url

  def set_defaults(self):
    """Sets default values used to initialize the config."""
    self.instance_url = 'https://machine-provider.appspot.com'


def add_machines(requests):
  """Add machines to the Machine Provider's Catalog.

  Args:
    requests: A list of rpc_messages.CatalogMachineAdditionRequest instances.
  """
  logging.info('Sending batched add_machines request')
  return net.json_request(
      '%s/_ah/api/catalog/v1/add_machines' %
          MachineProviderConfiguration.get_instance_url(),
      method='POST',
      payload=utils.to_json_encodable({'requests': requests}),
      scopes=MACHINE_PROVIDER_SCOPES,
 )
