Beispiel #1
0
def set_region():
  if 'region_select' in request.args and request.args['region_select'] in WG.handlers:
    try:
      #Check that the new region will actually work...
      validate_glacier(WG.app.config["AWS_ACCESS_KEY"],WG.app.config["AWS_SECRET_ACCESS_KEY"],request.args['region_select'])
      #Store it in the cookies
      session['region'] = request.args['region_select']
    except:
      print "Unable to switch to region %s"%request.args['region_select']
  return redirect(url_for('main'))
Beispiel #2
0
  def validate(self):
    rv = Form.validate(self)
    if not rv:
      return False
    self.errors['meta_sql']=[]
    self.errors['meta_amazon']=[]
    self.errors['meta_glacier']=[]

    #Try and connect to the database using the given parameters
    try:
      #Fall back on existing value on empty password field
      password = None if self.SQL_PASSWORD.data=='' else self.SQL_PASSWORD.data
      if password is None and WG.app.config["SQL_PASSWORD"]!='':
        password=WG.app.config["SQL_PASSWORD"]
      key=build_db_key(self.SQL_DIALECT.data,self.SQL_DATABASE_NAME.data,self.SQL_HOSTNAME.data,self.SQL_USERNAME.data,password,self.SQL_DRIVER.data,self.SQL_PORT.data)
      validate_db(key)
      WG.app.config["SQLALCHEMY_DATABASE_URI"]=key
      WG.db.create_all()
      WG.validated_db=True
    except:
      WG.validated_db=False
      self.errors['meta_sql'].append("Can't connect to SQL database")
      return False
    #Amazon connection
    try:
      aws_key = self.AWS_ACCESS_KEY.data if self.AWS_ACCESS_KEY.data!='' else WG.app.config.get('AWS_ACCESS_KEY','')
      aws_secret_key = self.AWS_SECRET_ACCESS_KEY.data if self.AWS_SECRET_ACCESS_KEY.data!='' else WG.app.config.get('AWS_SECRET_ACCESS_KEY','')
      validate_glacier(aws_key,aws_secret_key,self.DEFAULT_REGION.data)
      #Fall back on existing value on empty fields
      WG.app.config['AWS_ACCESS_KEY']=aws_key
      WG.app.config['AWS_SECRET_ACCESS_KEY']=aws_secret_key
      init_handlers_from_config()
      WG.validated_glacier=True
    except:
      self.errors['meta_amazon'].append("Can't connect to Amazon")
      WG.validated_glacier=False
      return False
    try:
      #Check directory is writeable
      tmp=tempfile.NamedTemporaryFile(dir=self.TEMP_FOLDER.data,delete=True)
      tmp.write("Hello world")
      tmp.close()
    except:
      self.errors['meta_glacier'].append("Directory is not writeable.")
      return False
    return True
Beispiel #3
0
def validate_connection():
    """
  The whole app is useless unless we have a database 
  to store things and a valid connection to Amazon
  Glacier.  So check that we do and redirect to 
  settings page if we don't.
  """
    #Make sure we have set a region
    if 'region' not in session:
        session['region'] = get_set_region()
    #Are we at a url where we don't need to check things?
    if WG.app.config.get("VERBOSE", False):
        print "Connecting to endpoint %s" % request.endpoint
    if request.endpoint != 'help' and request.endpoint != 'settings' and request.endpoint != 'static':
        #If everything has passed before, assume it will again
        #Is the db connection OK?
        if not WG.validated_db:
            try:
                key = build_db_key(WG.app.config["SQL_DIALECT"],
                                   WG.app.config["SQL_DATABASE_NAME"],
                                   WG.app.config["SQL_HOSTNAME"],
                                   WG.app.config["SQL_USERNAME"],
                                   WG.app.config["SQL_PASSWORD"],
                                   WG.app.config["SQL_DRIVER"],
                                   WG.app.config["SQL_PORT"])
                validate_db(key)
                WG.app.config["SQLALCHEMY_DATABASE_URI"] = key
                WG.db.create_all()
                WG.validated_db = True
            except:
                print "Can't connect to database."
                WG.validated_db = False
                return redirect(url_for('settings'))
        #Is the Amazon Glacier config okay?
        if not WG.validated_glacier:
            try:
                validate_glacier(WG.app.config["AWS_ACCESS_KEY"],
                                 WG.app.config["AWS_SECRET_ACCESS_KEY"],
                                 WG.app.config.get("DEFAULT_REGION"))
                init_handlers_from_config()
                WG.validated_glacier = True
            except:
                print "Can't connect to Glacier."
                WG.validated_glacier = False
                return redirect(url_for('settings'))
Beispiel #4
0
def validate_connection():
  """
  The whole app is useless unless we have a database 
  to store things and a valid connection to Amazon
  Glacier.  So check that we do and redirect to 
  settings page if we don't.
  """
  #Make sure we have set a region
  if 'region' not in session:
    session['region'] = get_set_region()
  #Are we at a url where we don't need to check things?
  if WG.app.config.get("VERBOSE",False):
    print "Connecting to endpoint %s"%request.endpoint
  if request.endpoint!='help' and request.endpoint!='settings' and request.endpoint!='static':
    #If everything has passed before, assume it will again
    #Is the db connection OK?
    if not WG.validated_db:
      try: 
        key=build_db_key(WG.app.config["SQL_DIALECT"],WG.app.config["SQL_DATABASE_NAME"],WG.app.config["SQL_HOSTNAME"],WG.app.config["SQL_USERNAME"],WG.app.config["SQL_PASSWORD"],WG.app.config["SQL_DRIVER"],WG.app.config["SQL_PORT"])
        validate_db(key)
        WG.app.config["SQLALCHEMY_DATABASE_URI"]=key
        WG.db.create_all()
        WG.validated_db=True
      except:
        print "Can't connect to database."
        WG.validated_db=False
        return redirect(url_for('settings'))
    #Is the Amazon Glacier config okay?
    if not WG.validated_glacier:
      try:
        validate_glacier(WG.app.config["AWS_ACCESS_KEY"],WG.app.config["AWS_SECRET_ACCESS_KEY"],WG.app.config.get("DEFAULT_REGION"))
        init_handlers_from_config()
        WG.validated_glacier=True
      except:
        print "Can't connect to Glacier."
        WG.validated_glacier=False
        return redirect(url_for('settings'))