def __init__(self, option, name=None, parent=None, user=None): StatsGroup.__init__(self, option, name, parent, user) self._session = None # Make sure there is an url provided config = dict(Config().section(option)) if "url" not in config: raise ReportError( "No Confluence url set in the [{0}] section".format(option)) self.url = config["url"].rstrip("/") # Optional authentication url if "auth_url" in config: self.auth_url = config["auth_url"] else: self.auth_url = self.url + "/step-auth-gss" # Authentication type if "auth_type" in config: if config["auth_type"] not in AUTH_TYPES: raise ReportError( "Unsupported authentication type: {0}".format( config["auth_type"])) self.auth_type = config["auth_type"] else: self.auth_type = "gss" # Authentication credentials if self.auth_type == "basic": if "auth_username" not in config: raise ReportError( "`auth_username` not set in the [{0}] section".format( option)) self.auth_username = config["auth_username"] if "auth_password" not in config: raise ReportError( "`auth_password` not set in the [{0}] section".format( option)) self.auth_password = config["auth_password"] else: if "auth_username" in config: raise ReportError( "`auth_username` is only valid for basic authentication" + " (section [{0}])".format(option)) if "auth_password" in config: raise ReportError( "`auth_password` is only valid for basic authentication" + " (section [{0}])".format(option)) # SSL verification if "ssl_verify" in config: try: self.ssl_verify = distutils.util.strtobool( config["ssl_verify"]) except Exception as error: raise ReportError( "Error when parsing 'ssl_verify': {0}".format(error)) else: self.ssl_verify = SSL_VERIFY self.login = config.get("login", None) # Check for custom prefix self.prefix = config["prefix"] if "prefix" in config else None # Create the list of stats self.stats = [ PageCreated(option=option + "-pages", parent=self, name="Pages created in {}".format(option)), CommentAdded(option=option + "-comments", parent=self, name="Comments added in {}".format(option)), ]
def __init__(self, option, name=None, parent=None, user=None): StatsGroup.__init__(self, option, name, parent, user) self._session = None # Make sure there is an url provided config = dict(Config().section(option)) if "url" not in config: raise ReportError( "No Jira url set in the [{0}] section".format(option)) self.url = config["url"].rstrip("/") # Optional authentication url if "auth_url" in config: self.auth_url = config["auth_url"] else: self.auth_url = self.url + "/step-auth-gss" # Authentication type if "auth_type" in config: if config["auth_type"] not in AUTH_TYPES: raise ReportError( "Unsupported authentication type: {0}".format( config["auth_type"])) self.auth_type = config["auth_type"] else: self.auth_type = "gss" # Authentication credentials if self.auth_type == "basic": if "auth_username" not in config: raise ReportError( "`auth_username` not set in the [{0}] section".format( option)) self.auth_username = config["auth_username"] if "auth_password" in config: self.auth_password = config["auth_password"] elif "auth_password_file" in config: file_path = os.path.expanduser(config["auth_password_file"]) with open(file_path) as password_file: self.auth_password = password_file.read().strip() else: raise ReportError( "`auth_password` or `auth_password_file` must be set " "in the [{0}] section".format(option)) else: if "auth_username" in config: raise ReportError( "`auth_username` is only valid for basic authentication" + " (section [{0}])".format(option)) if "auth_password" in config or "auth_password_file" in config: raise ReportError( "`auth_password` and `auth_password_file` are only valid " "for basic authentication (section [{0}])".format(option)) # SSL verification if "ssl_verify" in config: try: self.ssl_verify = distutils.util.strtobool( config["ssl_verify"]) except Exception as error: raise ReportError( "Error when parsing 'ssl_verify': {0}".format(error)) else: self.ssl_verify = SSL_VERIFY # Make sure we have project set self.project = config.get("project", None) if "use_scriptrunner" in config: self.use_scriptrunner = distutils.util.strtobool( config["use_scriptrunner"]) else: self.use_scriptrunner = True if not self.use_scriptrunner and not self.project: raise ReportError( "When scriptrunner is disabled with 'use_scriptrunner=False', " "'project' has to be defined for each JIRA section.") self.login = config.get("login", None) # Check for custom prefix self.prefix = config["prefix"] if "prefix" in config else None # Create the list of stats self.stats = [ JiraCreated(option=option + "-created", parent=self, name="Issues created in {0}".format(option)), JiraUpdated(option=option + "-updated", parent=self, name="Issues updated in {0}".format(option)), JiraResolved(option=option + "-resolved", parent=self, name="Issues resolved in {0}".format(option)), ]