def apps(parser, options, args): """Application related command""" if options.delete: return http.request('/v1/applications/%s' % options.delete, method='DELETE') return http.request('/v1/applications')
def add_key(parser, options, args): """Add a public key to pytheon account""" if args: filename = args[0] filename = os.path.expandvars(os.path.expanduser(filename)) if not os.path.isfile(filename): log.error("File %s not found." % filename) else: filename = os.path.expanduser("~/.ssh/id_rsa.pub") if not os.path.isfile(filename): filename = os.path.expanduser("~/.ssh/id_dsa.pub") if not os.path.isfile(filename): parser.error("Default key files ~/.ssh/id_rsa.pub and" "~/.ssh/id_dsa.pub were not found. Please specify key filename") raw_data = '' with open(filename, 'r') as key_file: raw_data = key_file.read(30000) if not raw_data: log.error("Could not read file %s. Please check file permissions" % filename) return if not raw_data.startswith("ssh-"): log.error("File %s does not seems to be a public key. " "Please make sure it is not your private key" % filename) return params = dict(raw_data=raw_data) if options.name: params.update(dict(name=options.name)) return http.request('/v1/account/keys', **params)
def register(parser, options, args): """register on pytheon""" if options.key and options.reset: parser.error("You can't reset a password with a confirmation key") config = utils.user_config() if options.username: config.pytheon.username = options.username config.write() if not config.pytheon.username: parser.error('Please specify a valid email') if options.key: return http.request('/v1/set_password/%s' % options.key.strip('/'), auth=False, password=utils.get_input('Password', password=True)) elif options.reset: return http.request('/v1/reset_password/', auth=False, email=options.username) else: return http.request('/v1/register', auth=False, email=options.username)
def addons(parser, options, args, config): """Addon management""" path = '/v1/applications/%s/addons' % config.deploy.project_name if options.all: return http.request('/v1/addons') elif options.add: try: id, plan = options.add.split(':') except ValueError: parser.error('Please specify a addon:plan') return http.request(path, method='POST', id=id, plan=plan) elif options.upgrade: try: id, plan = options.upgrade.split(':') except ValueError: parser.error('Please specify a addon:plan') return http.request('%s/%s' % (path, id), method='POST', plan=plan) elif options.delete: return http.request('%s/%s' % (path, options.delete), method='DELETE') # FIXME else: return http.request(path)
def create(parser, options, args): """create your pytheon project""" binary = utils.vcs_binary() global_config = utils.user_config() if not os.path.isfile(global_config._filename): global_config.pytheon = dict( username=options.username or utils.get_input('Username'), ) global_config.write() rc = global_config.pytheon config = utils.project_config(filename=options.buildout) if not os.path.isfile(config._filename): if not options.project_name: options.project_name = utils.get_input('Project name', default=os.path.basename(os.getcwd())) config.deploy = dict( version='1', use='gunicorn', project_name=options.project_name, ) if options.project_name: config.deploy.project_name = options.project_name config.write() kw = dict(username=rc.username, project_name=config.deploy.project_name) if binary == 'git': remote = os.environ.get('PYTHEON_REMOTE', '[email protected]:%(project_name)s.git').rstrip('/') remote = remote % kw utils.call(binary, 'remote', 'add', 'pytheon', remote, silent=True) else: remote = os.environ.get('PYTHEON_REMOTE', '[email protected]/%(project_name)s').rstrip('/') remote = remote % kw filename = '.hg/hgrc' config = Config.from_file(filename) config.paths.pytheon = remote config.write() commit(binary, config._filename) return http.request('/v1/applications', name=config.deploy.project_name)