How to use the gitlabform.gitlab.core.NotFoundException function in gitlabform

To help you get started, we’ve selected a few gitlabform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github egnyte / gitlabform / gitlabform / gitlabform / core.py View on Github external
for tag in sorted(configuration['tags']):
            try:
                if configuration['tags'][tag]['protected']:
                    create_access_level = configuration['tags'][tag]['create_access_level'] if \
                        'create_access_level' in configuration['tags'][tag] else None
                    logging.debug("Setting tag '%s' as *protected*", tag)
                    try:
                        # try to unprotect first
                        self.gl.unprotect_tag(project_and_group, tag)
                    except NotFoundException:
                        pass
                    self.gl.protect_tag(project_and_group, tag, create_access_level)
                else:
                    logging.debug("Setting tag '%s' as *unprotected*", tag)
                    self.gl.unprotect_tag(project_and_group, tag)
            except NotFoundException:
                logging.warning("! Tag '%s' not found when trying to set it as protected/unprotected", tag)
                if self.args.strict:
                    exit(3)
github egnyte / gitlabform / gitlabform / gitlab / core.py View on Github external
def _get_user_id(self, username):
        users = self._make_requests_to_api("users?username=%s", username, 'GET')

        # this API endpoint is for lookup, not search, so 'username' has to be full and exact username
        # also it's not possible to get more than 1 user as a result

        if len(users) == 0:
            raise NotFoundException("No users found when searching for username '%s'" % username)

        return users[0]['id']
github egnyte / gitlabform / gitlabform / gitlab / groups.py View on Github external
def get_group_settings(self, project_and_group_name):
        try:
            return self._make_requests_to_api("groups/%s", project_and_group_name)
        except NotFoundException:
            return dict()
github egnyte / gitlabform / gitlabform / gitlab / core.py View on Github external
def _make_request_to_api(self, path_as_format_string, args, method, data, expected_codes, json):
        if data and json:
            raise Exception("You need to pass either data or json, not both!")

        url = self.url + "/api/v4/" + self._format_with_url_encoding(path_as_format_string, args)
        logging.debug("url = %s , method = %s , data = %s", url, method, data)
        headers = {'PRIVATE-TOKEN': self.token}
        if data:
            response = self.session.request(method, url, headers=headers, data=data, timeout=10)
        elif json:
            response = self.session.request(method, url, headers=headers, json=json, timeout=10)
        else:
            response = self.session.request(method, url, headers=headers, timeout=10)
        logging.debug("response code=%s" % response.status_code)
        if response.status_code == 404:
            raise NotFoundException("Resource path='%s' not found!" % url)
        elif response.status_code == 204:
            # code calling this function assumes that it can do response.json() so fake it to return empty dict
            response.json = lambda: {}
            return response
        elif not self._is_expected_code(response.status_code, expected_codes):
            e = UnexpectedResponseException(
                "Request url='%s', method=%s, data='%s' failed "
                "- expected code(s) %s, got code %s & body: '%s'" %
                (url, method, data,
                 self._expected_code_to_str(expected_codes), response.status_code, response.content))
            e.status_code = response.status_code
            raise e
        else:
            return response
github egnyte / gitlabform / gitlabform / gitlab / projects.py View on Github external
def get_project_push_rules(self, project_and_group_name):
        try:
            return self._make_requests_to_api("projects/%s/push_rule", project_and_group_name)
        except NotFoundException:
            return dict()