Skip to content

Commit

Permalink
[ADD] version is now in faraday/__init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
EricHorvat committed Apr 16, 2019
1 parent ed869eb commit 438d0cb
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.egg-info
dist
build
.eggs
eggs
parts
var
Expand Down
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
recursive-include ./server/www *
recursive-include ./faraday/server/www *
include ./VERSION
include ./requirements_server.txt
include ./config/default.xml
include ./faraday/config/default.xml
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

1 change: 1 addition & 0 deletions faraday/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/)
# See the file 'doc/LICENSE' for the license information

__version__ = '3.7.0'
8 changes: 2 additions & 6 deletions faraday/client/persistence/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import requests

from faraday import __version__ as f_version
from faraday.client.persistence.server.utils import force_unique
from faraday.client.persistence.server.server_io_exceptions import (WrongObjectSignature,
CantCommunicateWithServerError,
Expand Down Expand Up @@ -1551,12 +1552,7 @@ def check_faraday_version():

faraday_directory = os.path.dirname(os.path.realpath('faraday.py'))

file_path = os.path.join(faraday_directory, 'VERSION')

with open(file_path, 'r') as version_file:
version = version_file.read().strip()

if info is not None and version != info['Version']:
if info is not None and f_version != info['Version']:
raise RuntimeError('Client and server versions do not match')

def check_server_url(url_to_test):
Expand Down
10 changes: 2 additions & 8 deletions faraday/client/start_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
CONST_FARADAY_ZSHRC,
CONST_ZSH_PATH,
CONST_FARADAY_ZSH_FARADAY,
CONST_VERSION_FILE,
CONST_REQUIREMENTS_FILE,
CONST_FARADAY_FOLDER_LIST,
)
from faraday.utils import dependencies
from faraday.utils.logs import getLogger, setUpLogger
from faraday.utils.user_input import query_yes_no

from faraday import __version__ as f_version
from faraday.client.persistence.server import server
from faraday.client.persistence.server.server import is_authenticated, login_user, get_user_info

Expand Down Expand Up @@ -60,7 +60,6 @@
FARADAY_USER_ZSH_PATH = os.path.join(FARADAY_USER_HOME, CONST_ZSH_PATH)
FARADAY_BASE_ZSH = os.path.join(FARADAY_CLIENT_BASE, CONST_FARADAY_ZSH_FARADAY)

FARADAY_VERSION_FILE = os.path.join(FARADAY_BASE, CONST_VERSION_FILE)
FARADAY_REQUIREMENTS_FILE = os.path.join(FARADAY_BASE, CONST_REQUIREMENTS_FILE)

REQUESTS_CA_BUNDLE_VAR = "REQUESTS_CA_BUNDLE"
Expand Down Expand Up @@ -172,9 +171,6 @@ def getParserArgs():
parser.add_argument('--keep-old', action='store_true', help='Keep old object in CLI mode if Faraday find a conflict')
parser.add_argument('--keep-new', action='store_true', help='Keep new object in CLI mode if Faraday find a conflict (DEFAULT ACTION)')

f = open(FARADAY_VERSION_FILE)
f_version = f.read().strip()

parser.add_argument('-v', '--version', action='version',
version='Faraday v{version}'.format(version=f_version))

Expand Down Expand Up @@ -410,13 +406,11 @@ def checkUpdates():
uri = getInstanceConfiguration().getUpdatesUri()
resp = u"OK"
try:
f = open(FARADAY_VERSION_FILE)

getInstanceConfiguration().setVersion(f.read().strip())
getInstanceConfiguration().setVersion(f_version)
getInstanceConfiguration().setAppname("Faraday - Penetration Test IDE Community")
parameter = {"version": getInstanceConfiguration().getVersion()}

f.close()
resp = requests.get(uri, params=parameter, timeout=1, verify=True)
resp = resp.text.strip()
except Exception as e:
Expand Down
1 change: 0 additions & 1 deletion faraday/config/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import os

CONST_VERSION_FILE = 'VERSION'
CONST_REQUIREMENTS_FILE = 'requirements.txt'
CONST_FARADAY_HOME_PATH = os.path.expanduser('~/.faraday')
CONST_FARADAY_PLUGINS_PATH = 'plugins'
Expand Down
10 changes: 3 additions & 7 deletions faraday/server/api/modules/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@

import flask
from flask import Blueprint

from faraday import __version__ as f_version
from faraday.server.config import gen_web_config


info_api = Blueprint('info_api', __name__)

@info_api.route('/v2/info', methods=['GET'])
def show_info():
faraday_directory = os.path.dirname(os.path.realpath('faraday.py'))

file_path = os.path.join(faraday_directory, 'VERSION')

with open(file_path, 'r') as version_file:
version = version_file.read().strip()

response = flask.jsonify({'Faraday Server': 'Running', 'Version': version})
response = flask.jsonify({'Faraday Server': 'Running', 'Version': f_version})
response.status_code = 200

return response
Expand Down
3 changes: 1 addition & 2 deletions faraday/server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

LOGGING_LEVEL = INFO

FARADAY_BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
FARADAY_BASE = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
FARADAY_SERVER_SESSIONS_DIR = os.path.join(CONSTANTS.CONST_FARADAY_HOME_PATH, 'session')
if not os.path.exists(CONSTANTS.CONST_FARADAY_HOME_PATH):
os.mkdir(CONSTANTS.CONST_FARADAY_HOME_PATH)
Expand All @@ -31,7 +31,6 @@
CONSTANTS.CONST_FARADAY_HOME_PATH, 'faraday-server-port-{0}.pid')
REQUIREMENTS_FILE = os.path.join(FARADAY_BASE, 'requirements_server.txt')
DEFAULT_CONFIG_FILE = os.path.join(FARADAY_BASE, 'server/default.ini')
VERSION_FILE = os.path.join(FARADAY_BASE, CONSTANTS.CONST_VERSION_FILE)
REPORTS_VIEWS_DIR = os.path.join(FARADAY_BASE, 'views/reports')
LOCAL_CONFIG_FILE = os.path.expanduser(
os.path.join(CONSTANTS.CONST_FARADAY_HOME_PATH, 'config/server.ini'))
Expand Down
3 changes: 1 addition & 2 deletions faraday/start_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def main():
parser.add_argument('--websocket_port', help='Overides server.ini websocket port configuration')
parser.add_argument('--bind_address', help='Overides server.ini bind_address configuration')

f = open(faraday.server.config.VERSION_FILE)
f_version = f.read().strip()
f_version = faraday.__version__

parser.add_argument('-v', '--version', action='version',
version='Faraday v{version}'.format(version=f_version))
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
test = pytest

[tool:pytest]
collect_ignore = ["_install/"]
collect_ignore = ["_install/"]
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
# and accepts an argument to specify the text encoding
# Python 3 only projects can skip this import
from io import open
from re import search

here = path.abspath(path.dirname(__file__))

# Get the long description from the README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

with open('faraday/__init__.py', 'rt', encoding='utf8') as f:
version = search(r'__version__ = \'(.*?)\'', f.read()).group(1)

# Taken from https://stackoverflow.com/questions/14399534/reference-requirements-txt-for-the-install-requires-kwarg-in-setuptools-setup-py/14399775#14399775
with open('requirements_server.txt') as fp:
required = fp.read().splitlines()
Expand Down Expand Up @@ -53,7 +57,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='3.7.0', # Required
version=version, # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down
3 changes: 2 additions & 1 deletion test_cases/test_api_vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
VulnerabilityView
)
from faraday.server.schemas import NullToBlankString
from faraday.server.config import FARADAY_BASE
from test_cases import factories
from test_api_workspaced_base import (
ReadOnlyAPITests
Expand Down Expand Up @@ -404,7 +405,7 @@ def test_get_attachments_by_vuln(self, test_client, session, workspace):
session.add(vuln)
session.commit()

with open('test_cases/data/faraday.png', 'r') as file_obj:
with open(os.path.join(FARADAY_BASE,'test_cases/data/faraday.png'), 'r') as file_obj:
new_file = FaradayUploadedFile(file_obj.read())

new_attach = File(object_type='vulnerability', object_id=vuln.id, name='Faraday', filename='faraday.png',
Expand Down
10 changes: 5 additions & 5 deletions test_cases/test_config_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
except ImportError:
import xml.etree.ElementTree as ET

import os

from faraday import __version__ as faraday_version
from faraday.server.config import FARADAY_BASE


def test_matching_versions():
with open(FARADAY_BASE + '/VERSION', 'r') as output:
version_file = output.read().strip()

version_default = parse_element_from_xml('version')

assert version_file == version_default
assert faraday_version == version_default


def parse_element_from_xml(tag_name):
with open(FARADAY_BASE + '/faraday/config/default.xml', 'r') as output:
with open(os.path.join(FARADAY_BASE, '/config/default.xml'), 'r') as output:
default_data = output.read()
tree = ET.fromstring(default_data)
default_element = tree.find(tag_name).text
Expand Down
9 changes: 4 additions & 5 deletions test_cases/test_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import os
import re

from faraday import __version__
from faraday.server.config import FARADAY_BASE

from faraday.server.config import (
copy_default_config_to_local,
gen_web_config
Expand Down Expand Up @@ -74,9 +77,5 @@ def test_copy_default_config_to_local_does_not_exist(copyfile, makedirs):
def isPEP440(arg):
return not _regex.match(arg) is None


def test_exists_and_content():
f = open("VERSION", "r")
line1 = f.readline().rstrip()
assert f.read() == ''
assert isPEP440(line1)
assert isPEP440(__version__)

0 comments on commit 438d0cb

Please sign in to comment.