Ejemplo n.º 1
0
def ensure_workers(cfn,
                   config,
                   server_ip,
                   current_count,
                   lower_count=-1,
                   upper_count=-1,
                   force_update=False):
  "Ensures that the build workers conform to spec."
  if server_ip == "NULL":
    if upper_count == 0:
      return service.Response.UpToDate
    return service.Response.WaitingForPrecondition
  auth_info = auth.get_authenticator(config).get_server_auth_info()
  return service.ensure(
      cfn,
      stack_name=config["stacks"]["workers"],
      template_body=template('worker.yaml'),
      parameters={
          "StackName": config["stacks"]["infra"],
          "ServerIP": server_ip,
          "WorkerImage": config["worker_image"],
          "LogsRegion": config["awslogs_region"],
          "LogsGroup": config["awslogs_group"],
          "TrustCertCollection": auth_info["ca_crt"],
          "ClientPrivateKey": auth_info["client_pkcs8_key"],
          "WorkerCertChain": auth_info["client_crt"],
      },
      current_count=current_count,
      lower_count=lower_count,
      upper_count=upper_count,
      force_update=force_update)
Ejemplo n.º 2
0
def ensure_servers(cfn,
                   config,
                   current_count,
                   lower_count=-1,
                   upper_count=-1,
                   force_update=False):
  """Ensure that the build servers conform to spec."""
  auth_info = auth.get_authenticator(config).get_server_auth_info()
  return service.ensure(
      cfn,
      stack_name=config["stacks"]["server"],
      template_body=template('server.yaml'),
      parameters={
          "StackName": config["stacks"]["infra"],
          "ServerImage": config["server_image"],
          "LogsRegion": config["awslogs_region"],
          "LogsGroup": config["awslogs_group"],
          "CertChain": auth_info["server_crt"],
          "PrivateKey": auth_info["server_pkcs8_key"],
          "ClientCertChain": auth_info["ca_crt"],
      },
      current_count=current_count,
      lower_count=lower_count,
      upper_count=upper_count,
      force_update=force_update)
Ejemplo n.º 3
0
 def monorail_get_auth_http(self):
     auth_config = auth.extract_auth_config_from_options(self.options)
     authenticator = auth.get_authenticator(auth_config)
     # Manually use a long timeout (10m); for some users who have a
     # long history on the issue tracker, whatever the default timeout
     # is is reached.
     return authenticator.authorize(httplib2.Http(timeout=600))
Ejemplo n.º 4
0
 def foursquare_user(self):
     """
     Returns a pysq.apiv2.User instance for this user.
     """
     authenticator = get_authenticator(self.access_token)
     finder = psq.UserFinder(authenticator)
     return finder.findUser('self')
Ejemplo n.º 5
0
    def get(self, request):
        if request.user.is_authenticated():
            return HttpResponseRedirect(reverse('compare'))

        auth = get_authenticator()
        uri = auth.authorize_uri()
        return HttpResponseRedirect(uri)
Ejemplo n.º 6
0
def do_connect(config,
               status,
               worker_count,
               force_update=False,
               auth_info=None,
               cfn=None):
  """Gets connection info to the remote build system and ensures a minimal
  service level.
  """
  cfn = cfn or boto3.client('cloudformation', region_name=config["region"])

  ans = {
      "status": {},
  }
  ans["status"].update(attr.asdict(status))

  ans["status"]["server_status"] = str(
      ensure_servers(
          cfn,
          config,
          current_count=status.running_servers,
          lower_count=1,
          upper_count=1,
          force_update=force_update))
  ans["status"]["workers_status"] = str(
      ensure_workers(
          cfn,
          config,
          server_ip=status.server_ip,
          current_count=status.running_workers,
          lower_count=worker_count,
          force_update=force_update))

  ans["auth_info"] = auth_info or auth.get_authenticator(config).get_auth_info()

  return ans