Commit 6b38eeab authored by Alejandro Alvarez Ayllon's avatar Alejandro Alvarez Ayllon
Browse files

FTS-321: CLI local defaults for endpoint and cert

parent eb534b4b
......@@ -19,6 +19,7 @@ from ConfigParser import SafeConfigParser
from optparse import OptionParser, IndentedHelpFormatter
import logging
import os
import socket
import sys
from fts3.rest.client import Context
......@@ -53,6 +54,13 @@ class _Formatter(IndentedHelpFormatter):
return '\n' + '\n'.join(lines) + '\n\n'
def _get_local_endpoint():
"""
Generate an endpoint using the machine hostname
"""
return "https://%s:8446" % socket.getfqdn()
class Base(object):
def __init__(self, extra_args=None, description=None, example=None):
......@@ -110,7 +118,7 @@ class Base(object):
def __call__(self, argv=sys.argv[1:]):
(self.options, self.args) = self.opt_parser.parse_args(argv)
if self.options.endpoint is None:
self.opt_parser.error('Need an endpoint')
self.options.endpoint = _get_local_endpoint()
if self.options.verbose:
self.logger.setLevel(logging.DEBUG)
self.validate()
......
......@@ -87,6 +87,9 @@ class Context(object):
elif 'X509_USER_CERT' in os.environ:
ucert = os.environ['X509_USER_CERT']
ukey = os.environ.get('X509_USER_KEY', ucert)
elif os.path.exists('/etc/grid-security/hostcert.pem') and os.path.exists('/etc/grid-security/hostkey.pem'):
ucert = '/etc/grid-security/hostcert.pem'
ukey = '/etc/grid-security/hostkey.pem'
if ucert and ukey:
self.x509_list = _get_x509_list(ucert)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment