| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e9b1583 commit 0732826
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,8 +70,11 @@ parameters. You can override the values in each GitLab server section. | |||
| 70 | 70 | - Integer | |
| 71 | 71 | - Number of seconds to wait for an answer before failing. | |
| 72 | 72 | ||
| 73 | - You must define the ``url`` and ``private_token`` in each GitLab server | ||
| 74 | - section. | ||
| 73 | + You must define the ``url`` in each GitLab server section. | ||
| 74 | + | ||
| 75 | + Only one of ``private_token`` or ``oauth_token`` should be defined. If neither | ||
| 76 | + are defined an anonymous request will be sent to the Gitlab server, with very | ||
| 77 | + limited permissions. | ||
| 75 | 78 | ||
| 76 | 79 | .. list-table:: GitLab server options | |
| 77 | 80 | :header-rows: 1 | |
@@ -83,6 +86,9 @@ section. | |||
| 83 | 86 | * - ``private_token`` | |
| 84 | 87 | - Your user token. Login/password is not supported. Refer to `the official | |
| 85 | 88 | documentation`__ to learn how to obtain a token. | |
| 89 | + * - ``oauth_token`` | ||
| 90 | + - An Oauth token for authentication. The Gitlab server must be configured | ||
| 91 | + to support this authentication method. | ||
| 86 | 92 | * - ``api_version`` | |
| 87 | 93 | - GitLab API version to use (``3`` or ``4``). Defaults to ``3`` for now, | |
| 88 | 94 | but will switch to ``4`` eventually. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,7 +182,8 @@ def from_config(gitlab_id=None, config_files=None): | |||
| 182 | 182 | """ | |
| 183 | 183 | config = gitlab.config.GitlabConfigParser(gitlab_id=gitlab_id, | |
| 184 | 184 | config_files=config_files) | |
| 185 | - return Gitlab(config.url, private_token=config.token, | ||
| 185 | + return Gitlab(config.url, private_token=config.private_token, | ||
| 186 | + oauth_token=config.oauth_token, | ||
| 186 | 187 | ssl_verify=config.ssl_verify, timeout=config.timeout, | |
| 187 | 188 | http_username=config.http_username, | |
| 188 | 189 | http_password=config.http_password, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,7 +86,7 @@ def _get_base_parser(): | |||
| 86 | 86 | help="Verbose mode (legacy format only)", | |
| 87 | 87 | action="store_true") | |
| 88 | 88 | parser.add_argument("-d", "--debug", | |
| 89 | - help="Debug mode (display HTTP requests", | ||
| 89 | + help="Debug mode (display HTTP requests)", | ||
| 90 | 90 | action="store_true") | |
| 91 | 91 | parser.add_argument("-c", "--config-file", action='append', | |
| 92 | 92 | help=("Configuration file to use. Can be used " | |
@@ -147,7 +147,8 @@ def main(): | |||
| 147 | 147 | ||
| 148 | 148 | try: | |
| 149 | 149 | gl = gitlab.Gitlab.from_config(gitlab_id, config_files) | |
| 150 | - gl.auth() | ||
| 150 | + if gl.private_token or gl.oauth_token: | ||
| 151 | + gl.auth() | ||
| 151 | 152 | except Exception as e: | |
| 152 | 153 | die(str(e)) | |
| 153 | 154 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,6 @@ def __init__(self, gitlab_id=None, config_files=None): | |||
| 53 | 53 | ||
| 54 | 54 | try: | |
| 55 | 55 | self.url = self._config.get(self.gitlab_id, 'url') | |
| 56 | - self.token = self._config.get(self.gitlab_id, 'private_token') | ||
| 57 | 56 | except Exception: | |
| 58 | 57 | raise GitlabDataError("Impossible to get gitlab informations from " | |
| 59 | 58 | "configuration (%s)" % self.gitlab_id) | |
@@ -96,6 +95,29 @@ def __init__(self, gitlab_id=None, config_files=None): | |||
| 96 | 95 | except Exception: | |
| 97 | 96 | pass | |
| 98 | 97 | ||
| 98 | + self.private_token = None | ||
| 99 | + try: | ||
| 100 | + self.private_token = self._config.get(self.gitlab_id, | ||
| 101 | + 'private_token') | ||
| 102 | + except Exception: | ||
| 103 | + pass | ||
| 104 | + | ||
| 105 | + self.oauth_token = None | ||
| 106 | + try: | ||
| 107 | + self.oauth_token = self._config.get(self.gitlab_id, 'oauth_token') | ||
| 108 | + except Exception: | ||
| 109 | + pass | ||
| 110 | + | ||
| 111 | + self.http_username = None | ||
| 112 | + self.http_password = None | ||
| 113 | + try: | ||
| 114 | + self.http_username = self._config.get(self.gitlab_id, | ||
| 115 | + 'http_username') | ||
| 116 | + self.http_password = self._config.get(self.gitlab_id, | ||
| 117 | + 'http_password') | ||
| 118 | + except Exception: | ||
| 119 | + pass | ||
| 120 | + | ||
| 99 | 121 | self.http_username = None | |
| 100 | 122 | self.http_password = None | |
| 101 | 123 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,10 @@ | |||
| 45 | 45 | url = https://three.url | |
| 46 | 46 | private_token = MNOPQR | |
| 47 | 47 | ssl_verify = /path/to/CA/bundle.crt | |
| 48 | + | ||
| 49 | + [four] | ||
| 50 | + url = https://four.url | ||
| 51 | + oauth_token = STUV | ||
| 48 | 52 | """ | |
| 49 | 53 | ||
| 50 | 54 | no_default_config = u"""[global] | |
@@ -85,8 +89,7 @@ def test_invalid_data(self, m_open): | |||
| 85 | 89 | fd = six.StringIO(missing_attr_config) | |
| 86 | 90 | fd.close = mock.Mock(return_value=None) | |
| 87 | 91 | m_open.return_value = fd | |
| 88 | - self.assertRaises(config.GitlabDataError, config.GitlabConfigParser, | ||
| 89 | - gitlab_id='one') | ||
| 92 | + config.GitlabConfigParser('one') | ||
| 90 | 93 | self.assertRaises(config.GitlabDataError, config.GitlabConfigParser, | |
| 91 | 94 | gitlab_id='two') | |
| 92 | 95 | self.assertRaises(config.GitlabDataError, config.GitlabConfigParser, | |
@@ -101,7 +104,8 @@ def test_valid_data(self, m_open): | |||
| 101 | 104 | cp = config.GitlabConfigParser() | |
| 102 | 105 | self.assertEqual("one", cp.gitlab_id) | |
| 103 | 106 | self.assertEqual("http://one.url", cp.url) | |
| 104 | - self.assertEqual("ABCDEF", cp.token) | ||
| 107 | + self.assertEqual("ABCDEF", cp.private_token) | ||
| 108 | + self.assertEqual(None, cp.oauth_token) | ||
| 105 | 109 | self.assertEqual(2, cp.timeout) | |
| 106 | 110 | self.assertEqual(True, cp.ssl_verify) | |
| 107 | 111 | ||
@@ -111,7 +115,8 @@ def test_valid_data(self, m_open): | |||
| 111 | 115 | cp = config.GitlabConfigParser(gitlab_id="two") | |
| 112 | 116 | self.assertEqual("two", cp.gitlab_id) | |
| 113 | 117 | self.assertEqual("https://two.url", cp.url) | |
| 114 | - self.assertEqual("GHIJKL", cp.token) | ||
| 118 | + self.assertEqual("GHIJKL", cp.private_token) | ||
| 119 | + self.assertEqual(None, cp.oauth_token) | ||
| 115 | 120 | self.assertEqual(10, cp.timeout) | |
| 116 | 121 | self.assertEqual(False, cp.ssl_verify) | |
| 117 | 122 | ||
@@ -121,6 +126,18 @@ def test_valid_data(self, m_open): | |||
| 121 | 126 | cp = config.GitlabConfigParser(gitlab_id="three") | |
| 122 | 127 | self.assertEqual("three", cp.gitlab_id) | |
| 123 | 128 | self.assertEqual("https://three.url", cp.url) | |
| 124 | - self.assertEqual("MNOPQR", cp.token) | ||
| 129 | + self.assertEqual("MNOPQR", cp.private_token) | ||
| 130 | + self.assertEqual(None, cp.oauth_token) | ||
| 125 | 131 | self.assertEqual(2, cp.timeout) | |
| 126 | 132 | self.assertEqual("/path/to/CA/bundle.crt", cp.ssl_verify) | |
| 133 | + | ||
| 134 | + fd = six.StringIO(valid_config) | ||
| 135 | + fd.close = mock.Mock(return_value=None) | ||
| 136 | + m_open.return_value = fd | ||
| 137 | + cp = config.GitlabConfigParser(gitlab_id="four") | ||
| 138 | + self.assertEqual("four", cp.gitlab_id) | ||
| 139 | + self.assertEqual("https://four.url", cp.url) | ||
| 140 | + self.assertEqual(None, cp.private_token) | ||
| 141 | + self.assertEqual("STUV", cp.oauth_token) | ||
| 142 | + self.assertEqual(2, cp.timeout) | ||
| 143 | + self.assertEqual(True, cp.ssl_verify) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments