Signed-off-by: Richard Marko rmarko@fedoraproject.org --- frontend/coprs_frontend/coprs/templates/api.html | 1 + python/copr/README.rst | 3 ++- python/copr/client/client.py | 14 +++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/templates/api.html b/frontend/coprs_frontend/coprs/templates/api.html index 9944d0e..9732c08 100644 --- a/frontend/coprs_frontend/coprs/templates/api.html +++ b/frontend/coprs_frontend/coprs/templates/api.html @@ -35,6 +35,7 @@ login = {{ g.user.api_login }} username = {{ g.user.name }} token = {{ g.user.api_token }} copr_url = {{ ('https://' + config['PUBLIC_COPR_HOSTNAME'])| fix_url_https_frontend}} +# insecure = no # set to yes to allow insecure connection # expiration date: {{ g.user.api_token_expiration }} </pre>
diff --git a/python/copr/README.rst b/python/copr/README.rst index 8b3f708..be42f9d 100644 --- a/python/copr/README.rst +++ b/python/copr/README.rst @@ -31,6 +31,7 @@ Usage: token="<token from /api>", username="<copr username>", copr_url="<url copr instance ; optional>" + insecure="<allow insecure connection; boolean optional>" )
Alternatively you could use configuration file: @@ -44,5 +45,5 @@ Alternatively you could use configuration file: username = <insert here your copr username> token = <insert here your API token> copr_url = <insert here copr url> - + insecure = <allow insecure connection; boolean optional>
diff --git a/python/copr/client/client.py b/python/copr/client/client.py index 63f1395..901c901 100644 --- a/python/copr/client/client.py +++ b/python/copr/client/client.py @@ -67,19 +67,22 @@ class CoprClient(UnicodeMixin): """
def __init__(self, username=None, login=None, token=None, copr_url=None, - no_config=False): + no_config=False, insecure=False): """ :param unicode username: username used by default for all requests :param unicode login: user login, used for identification :param unicode token: copr api token :param unicode copr_url: used as copr projects root :param bool no_config: helper flag to indicate that no config was provided + :param bool insecure: allow insecure connection (no SSL + certificate checking) """
self.token = token self.login = login self.username = username self.copr_url = copr_url or "http://copr.fedoraproject.org/" + self.insecure = insecure
self.no_config = no_config
@@ -111,7 +114,7 @@ class CoprClient(UnicodeMixin):
"""
- raw_config = configparser.ConfigParser() + raw_config = configparser.ConfigParser({"insecure": False}) if not filepath: filepath = os.path.join(os.path.expanduser("~"), ".config", "copr") config = {} @@ -124,7 +127,9 @@ class CoprClient(UnicodeMixin): raise CoprNoConfException() else: try: - for field in ["username", "login", "token", "copr_url"]: + for field in ["username", "login", "token", "copr_url", + "insecure"]: + if six.PY3: config[field] = raw_config["copr-cli"].get(field, None) else: @@ -170,6 +175,9 @@ class CoprClient(UnicodeMixin): kwargs["data"] = data if files is not None: kwargs["files"] = files + if self.insecure: + log.warn("Using insecure connection") + kwargs["verify"] = False
if method not in ["get", "post", "head", "delete", "put"]: raise Exception("Method {0} not allowed".format(method))
On 09/08/2015 12:54 PM, Richard Marko wrote:
Signed-off-by: Richard Marko rmarko@fedoraproject.org
frontend/coprs_frontend/coprs/templates/api.html | 1 + python/copr/README.rst | 3 ++- python/copr/client/client.py | 14 +++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/templates/api.html b/frontend/coprs_frontend/coprs/templates/api.html index 9944d0e..9732c08 100644 --- a/frontend/coprs_frontend/coprs/templates/api.html +++ b/frontend/coprs_frontend/coprs/templates/api.html @@ -35,6 +35,7 @@ login = {{ g.user.api_login }} username = {{ g.user.name }} token = {{ g.user.api_token }} copr_url = {{ ('https://' + config['PUBLIC_COPR_HOSTNAME'])| fix_url_https_frontend}} +# insecure = no # set to yes to allow insecure connection # expiration date: {{ g.user.api_token_expiration }} </pre>
diff --git a/python/copr/README.rst b/python/copr/README.rst index 8b3f708..be42f9d 100644 --- a/python/copr/README.rst +++ b/python/copr/README.rst @@ -31,6 +31,7 @@ Usage: token="<token from /api>", username="<copr username>", copr_url="<url copr instance ; optional>"
)insecure="<allow insecure connection; boolean optional>"
Alternatively you could use configuration file: @@ -44,5 +45,5 @@ Alternatively you could use configuration file: username = <insert here your copr username> token = <insert here your API token> copr_url = <insert here copr url>
- insecure = <allow insecure connection; boolean optional>
diff --git a/python/copr/client/client.py b/python/copr/client/client.py index 63f1395..901c901 100644 --- a/python/copr/client/client.py +++ b/python/copr/client/client.py @@ -67,19 +67,22 @@ class CoprClient(UnicodeMixin): """
def __init__(self, username=None, login=None, token=None, copr_url=None,
no_config=False):
no_config=False, insecure=False): """ :param unicode username: username used by default for all requests :param unicode login: user login, used for identification :param unicode token: copr api token :param unicode copr_url: used as copr projects root :param bool no_config: helper flag to indicate that no config was provided
:param bool insecure: allow insecure connection (no SSL
certificate checking) """ self.token = token self.login = login self.username = username self.copr_url = copr_url or "http://copr.fedoraproject.org/"
self.insecure = insecure self.no_config = no_config
@@ -111,7 +114,7 @@ class CoprClient(UnicodeMixin):
"""
raw_config = configparser.ConfigParser()
raw_config = configparser.ConfigParser({"insecure": False}) if not filepath: filepath = os.path.join(os.path.expanduser("~"), ".config", "copr") config = {}
@@ -124,7 +127,9 @@ class CoprClient(UnicodeMixin): raise CoprNoConfException() else: try:
for field in ["username", "login", "token", "copr_url"]:
for field in ["username", "login", "token", "copr_url",
"insecure"]:
if six.PY3: config[field] = raw_config["copr-cli"].get(field, None) else:
@@ -170,6 +175,9 @@ class CoprClient(UnicodeMixin): kwargs["data"] = data if files is not None: kwargs["files"] = files
if self.insecure:
log.warn("Using insecure connection")
kwargs["verify"] = False if method not in ["get", "post", "head", "delete", "put"]: raise Exception("Method {0} not allowed".format(method))
Ping.
copr-devel@lists.fedorahosted.org