def post(user): apptoken_data = request.get_json() app = apptoken_data["app"].strip() if len(app) < 5: raise BadRequest(description="'app' length must be 5 at least.") token = token_urlsafe(32) hashed_token = sha512(token.encode('ascii')).hexdigest() apptoken = AppToken(app=app, owner_id=user.id, token=hashed_token) db.session.add(apptoken) db.session.commit() result = AppToken.query.get(apptoken.id) result_data = apptoken_schema.dump(result) result_data["token"] = token return result_data, 201, { 'Location': f'{request.base_url}/apptokens/{apptoken.id}', }
def get(self): user = users.get_current_user() if user: oauth_token = self.request.get("oauth_token") def get_new_fs_and_credentials(): oauth_token, oauth_secret = constants.get_oauth_strings() credentials = foursquare.OAuthCredentials(oauth_token, oauth_secret) fs = foursquare.Foursquare(credentials) return fs, credentials if oauth_token: old_userinfos = UserInfo.all().filter('user ='******'token =', oauth_token).get() try: user_token = fs.access_token(oauth.OAuthToken(apptoken.token, apptoken.secret)) credentials.set_access_token(user_token) userinfo = UserInfo(user = user, token = credentials.access_token.key, secret = credentials.access_token.secret, is_ready=False, is_authorized=True, last_checkin=0, last_updated=datetime.now(), color_scheme='fire', level_max=int(constants.level_const), checkin_count=0, venue_count=0) except DownloadError, err: if str(err).find('ApplicationError: 5') >= 0: pass # if something bad happens on OAuth, then it currently just redirects to the signup page #TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code else: raise err try: fetch_foursquare_data.update_user_info(userinfo) fetch_foursquare_data.fetch_and_store_checkins(userinfo, limit=10) taskqueue.add(url='/fetch_foursquare_data/all_for_user/%s' % userinfo.key()) except foursquare.FoursquareRemoteException, err: if str(err).find('403 Forbidden') >= 0: pass # if a user tries to sign up while my app is blocked, then it currently just redirects to the signup page #TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code else: raise err except DownloadError: pass #TODO make this better, but I'd rather throw the user back to the main page to try again than show the user an error.
def __init__(self, db): self.validation_rule1 = AvailableOptionValidationRule( type=ValidationRuleEnum.min, arg="1", ) self.validation_rule2 = AvailableOptionValidationRule( type=ValidationRuleEnum.max, arg="42", ) self.validation_rule1bis = AvailableOptionValidationRule( type=ValidationRuleEnum.min, arg="1", ) self.validation_rule2bis = AvailableOptionValidationRule( type=ValidationRuleEnum.max, arg="42", ) self.validation_rule3 = AvailableOptionValidationRule( type=ValidationRuleEnum.regex, arg="^[a-z0-9][-a-z0-9]*[a-z0-9]$", ) self.validation_rule4 = AvailableOptionValidationRule( type=ValidationRuleEnum.eq, arg="foobar", ) self.validation_rule5 = AvailableOptionValidationRule( type=ValidationRuleEnum.neq, arg="barfoo", ) self.validation_rule6 = AvailableOptionValidationRule( type=ValidationRuleEnum.format, arg="json", ) self.validation_rule7 = AvailableOptionValidationRule( type=ValidationRuleEnum.into, arg="[a, b, c]", ) self.available_opt1 = AvailableOption( access_level=RoleEnum.user, tag="Apache", field_name="vhost.conf", value_type=OptionValueTypeEnum.base64, field_description="Apache2 vhost configuration file.", default_value="", ) self.available_opt2 = AvailableOption( access_level=RoleEnum.user, tag="PHP", field_name="worker", value_type=OptionValueTypeEnum.integer, field_description="PHP worker count.", default_value="6", validation_rules=[ self.validation_rule1, self.validation_rule2, ], ) self.available_opt2bis = AvailableOption( access_level=RoleEnum.user, tag="PHP", field_name="test_min_max", value_type=OptionValueTypeEnum.integer, field_description="Test min and max option rules", default_value="6", validation_rules=[ self.validation_rule1bis, self.validation_rule2bis, ], ) self.available_opt3 = AvailableOption( access_level=RoleEnum.user, tag="SQL", field_name="my.cnf", value_type=OptionValueTypeEnum.base64, field_description="MySQL configuration file.", ) self.available_opt4 = AvailableOption( access_level=RoleEnum.admin, tag="PHP", field_name="test_regex", value_type=OptionValueTypeEnum.string, field_description="Test regex option rule", validation_rules=[ self.validation_rule3, ] ) self.available_opt5 = AvailableOption( access_level=RoleEnum.admin, tag="PHP", field_name="test_eq", value_type=OptionValueTypeEnum.string, field_description="Test eq option rule", validation_rules=[ self.validation_rule4, ] ) self.available_opt6 = AvailableOption( access_level=RoleEnum.admin, tag="PHP", field_name="test_neq", value_type=OptionValueTypeEnum.string, field_description="Test neq option rule", validation_rules=[ self.validation_rule5, ] ) self.available_opt7 = AvailableOption( access_level=RoleEnum.admin, tag="PHP", field_name="test_format", value_type=OptionValueTypeEnum.string, field_description="Test format option rule", validation_rules=[ self.validation_rule6, ] ) self.available_opt8 = AvailableOption( access_level=RoleEnum.admin, tag="PHP", field_name="test_into", value_type=OptionValueTypeEnum.string, field_description="Test into option rule", validation_rules=[ self.validation_rule7, ] ) self.runtime1 = Runtime( name="apache-2.4 php-7.2.x", description="Stack web classique Apache 2.4 + PHP 7.2.x", fam="Apache PHP", runtime_type=RuntimeTypeEnum.webapp, available_opts=[ self.available_opt1, self.available_opt2, ], ) self.runtime2 = Runtime( name="MariaDB 10.1", description="SQL server", fam="SQL", runtime_type=RuntimeTypeEnum.addon, available_opts=[ self.available_opt3, ], uri_template='{"pattern": "mysql://{udbname}:{password}@' 'host:port/{udbname}",' '"variables": [{"length": 16, "name": "udbname", ' '"src": "capsule", "unique": true, "set_name": true},' '{"length": 32, "name": "password", ' '"set_name": false, "src": "random", ' '"unique": false}]}', ) self.runtime3 = Runtime( name="MariaDB 12.1", description="SQL server", fam="SQL", runtime_type=RuntimeTypeEnum.addon, ) self.runtime4 = Runtime( name="apache-3.1 php-9.3.x", description="Stack web futuriste Apache 3.1 + PHP 9.3.x", fam="Apache PHP", runtime_type=RuntimeTypeEnum.webapp, available_opts=[ self.available_opt2bis, self.available_opt4, self.available_opt5, self.available_opt6, self.available_opt7, self.available_opt8, ], ) self.fqdn1 = FQDN( name="main.fqdn.ac-versailles.fr", alias=False, ) self.fqdn2 = FQDN( name="secondary.fqdn.ac-versailles.fr", alias=True, ) self.option1 = Option( field_name="worker", tag="PHP", value="42", value_type='integer', ) self.cron1 = Cron( command="rm -rf *", hour="*/6", minute="15", month="*", ) self.webapp1 = WebApp( env='{"HTTP_PROXY": "http://*****:*****@doe", ) self.sshkey2 = SSHKey( public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC/YCx71smBufMXF" "thQQsjSW18adRCpI5L+I8z4qtx+8SQeTSFWZF/E9QSgG6UoajwzCb" "5oQM/+M9Hmel1rSUUfjGx8HQV4smVbCRTgRGDJTpFhbvoeO0AC6YJ" "6n/eBzu0zKVlW0UqMqJU1cQLWgnFfSDURmzLHlnPn467uXPx5Pw==" " jane@doe", ) self.sshkey3 = SSHKey( public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDCVu8lOZxm+7fjM" "QpdNuU2HinAhWmmEtYcX9wxCcBs14GmDrDSOhZB61bq9vdzkSlV0W" "st711mUlEZlXh/999NL7iAy6COKYxsEmRgbCU+9k8rBsSTDcXS6MW" "+aJI4vnqMgVSGwBDgxZs4X2mthYhCitgbk9D3WbstAinUkhEtzQ==" " phpseclib-generated-key" ) token = "KDCte1raIV-ItPQf-sf_tapY4q-kLmvlcJ9yUKPlqbo" hashed_token = sha512(token.encode('ascii')).hexdigest() self.apptoken1 = AppToken( app="My super app", token=hashed_token) # Users. self.admin_user = User( name="admin_user", role=RoleEnum.admin) self.superadmin_user = User( name="superadmin_user", role=RoleEnum.superadmin) self.fake_user = User( name="fake_user", role=RoleEnum.user) self.user1 = User( name="user1", role=RoleEnum.user) self.user2 = User( name="user2", role=RoleEnum.user) self.user3 = User( name="user3", role=RoleEnum.user) self.user1.public_keys.append(self.sshkey1) self.user2.public_keys.append(self.sshkey2) self.user3.apptokens.append(self.apptoken1) self.capsule1 = Capsule( name="test-default-capsule", owners=[ self.user1, self.user2, ], webapp=self.webapp1, addons=[ self.addon1, ], authorized_keys=[ self.sshkey2, self.sshkey3, ], fqdns=[ self.fqdn1, self.fqdn2, ], force_redirect_https=True, enable_https=True, ) array_obj = [] for name, value in vars(self).items(): array_obj.append(value) db.session.add_all(array_obj) db.session.commit() # Just handy in test functions. self.users = [ self.admin_user, self.superadmin_user, self.fake_user, self.user1, self.user2, self.user3, ] self.runtimes = [ self.runtime1, self.runtime2, self.runtime3, self.runtime4, ]
fetch_foursquare_data.fetch_and_store_checkins(userinfo, limit=10) taskqueue.add(url='/fetch_foursquare_data/all_for_user/%s' % userinfo.key()) except foursquare.FoursquareRemoteException, err: if str(err).find('403 Forbidden') >= 0: pass # if a user tries to sign up while my app is blocked, then it currently just redirects to the signup page #TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code else: raise err except DownloadError: pass #TODO make this better, but I'd rather throw the user back to the main page to try again than show the user an error. self.redirect("/") else: fs, credentials = get_new_fs_and_credentials() app_token = fs.request_token() auth_url = fs.authorize(app_token) new_apptoken = AppToken(token = app_token.key, secret = app_token.secret) new_apptoken.put() self.redirect(auth_url) else: self.redirect(users.create_login_url(self.request.uri)) class StaticMapHandler(webapp.RequestHandler): def get(self): path = environ['PATH_INFO'] if path.endswith('.png'): raw = path[:-4] # strip extension try: assert raw.count('/') == 2, "%d /'s" % raw.count('/') foo, bar, map_key = raw.split('/') except AssertionError, err: logging.error(err.args[0])