예제 #1
0
def init_jama_client():
    # do we have credentials in the config?
    credentials_dict = {}
    if 'CREDENTIALS' in config:
        credentials_dict = config['CREDENTIALS']
    try:
        instance_url = get_instance_url(credentials_dict)
        oauth = get_oauth(credentials_dict)
        username = get_username(credentials_dict)
        password = get_password(credentials_dict)
        jama_client = JamaClient(instance_url,
                                 credentials=(username, password),
                                 oauth=oauth)
        jama_client.get_available_endpoints()
        return jama_client
    except APIException:
        # we cant do things without the API so lets kick out of the execution.
        print(
            'Error: invalid Jama credentials, check they are valid in the config.ini file.'
        )
    except:
        print('Failed to authenticate to <' +
              get_instance_url(credentials_dict) + '>')

    response = input(
        '\nWould you like to manually enter server credentials?\n')
    response = response.lower()
    if response == 'y' or response == 'yes' or response == 'true':
        config['CREDENTIALS'] = {}
        return init_jama_client()
    else:
        sys.exit()
    def get_client(self):
        """This method does the following:
            1) Reads in the values in the Client Settings panel
            2) Validates the fields.  i.e. trim whitespace; add https:// to url fields missing it.
            3) Create a JamaClient instance and attempt to make a connection to it.
            4) Returns the new JamaClient. or None if
        """
        try:
            # Read values
            url = self.url_field.value.get().strip().lower()
            # Get those pesky backslashes out
            while url.endswith('/') and url != 'https://' and url != 'http://':
                url = url[0:len(url) - 1]
            # If http or https method not specified in the url then add it now.
            if not (url.startswith('https://') or url.startswith('http://')):
                url = 'https://' + url
            self.url_field.value.set(url)

            if self.auth_mode_field.auth_mode.get() == AuthModeSelector.AUTH_MODE_BASIC:
                use_oauth = False
            else:
                use_oauth = True
            username = self.username_field.value.get().strip()
            password = self.password_field.value.get().strip()
            # Create the client
            jama_client = JamaClient(url, credentials=(username, password), oauth=use_oauth)
            # Attempt a connection
            jama_client.get_available_endpoints()
            # No Exception?  ok it will probably work; return the client.
            return jama_client

        except Exception as e:
            messagebox.showerror("Unable to connect", "Please check your client settings.")
            print(e)
            raise e
예제 #3
0
def init_jama_client():
    # do we have credentials in the config?
    credentials_dict = {}
    if 'CREDENTIALS' in config:
        credentials_dict = config['CREDENTIALS']
    try:
        instance_url = get_instance_url(credentials_dict)
        oauth = get_oauth(credentials_dict)
        username = get_username(credentials_dict)
        password = get_password(credentials_dict)
        jama_client = JamaClient(instance_url, credentials=(username, password), oauth=oauth)
        jama_client.get_available_endpoints()
        return jama_client
    except APIException:
        # we cant do things without the API so lets kick out of the execution.
        print('Error: invalid Jama credentials, check they are valid in the config.ini file.')
    except:
        print('Failed to authenticate to <' + get_instance_url(credentials_dict) + '>')

    sys.exit()
예제 #4
0
def init_jama_client():
    while True:
        # See if this set of credentials works.
        try:
            instance_url = validate_base_url(config.base_url)
            oauth = config.oauth
            if not oauth:
                username = config.username
                password = config.password
            else:
                username = config.client_id
                password = config.client_secret

            # Try to make the client
            jama_client = JamaClient(instance_url,
                                     credentials=(username, password),
                                     oauth=oauth)
            jama_client.get_available_endpoints()
            return jama_client
        # Catch any exception from the API
        except APIException as e:
            # we cant do things without the API so lets kick out of the execution.
            util_logger.warning(
                'Error: invalid Jama credentials, check they are valid in the config.py file.'
            )

        # Catch unexpected things here
        except Exception as e:
            util_logger.warning('Failed to authenticate to <' +
                                config.base_url + '> Error: ' + str(e))

        response = input(
            '\nWould you like to manually enter server credentials?[y/n]: ')
        response = response.lower()
        if response == 'y' or response == 'yes' or response == 'true':
            prompt_credentials()
        else:
            sys.exit()