Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Configure JupyterHub for GitLab intergration."""
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
from oauthenticator.gitlab import GitLabOAuthenticator
#: Use GitLab OAuth Server for authentication.
c.JupyterHub.authenticator_class = GitLabOAuthenticator
#: Automatically begin the login process without showing the button.
c.Authenticator.auto_login = True
#: Enable named-servers
c.JupyterHub.allow_named_servers = True
#: Enable persisting encrypted auth_state using JUPYTERHUB_CRYPT_KEY.
c.Authenticator.enable_auth_state = True
#: TODO Url for the database. e.g. `sqlite:///jupyterhub.sqlite`
#c.JupyterHub.db_url = 'sqlite:///jupyterhub.sqlite'
#: TODO Upgrade the database automatically on start.
#c.JupyterHub.upgrade_db = False
url = "%s/projects/%s/members/%s%d" % (GITLAB_API, project, self.member_api_variant, user_id)
req = HTTPRequest(url, method="GET", headers=headers)
resp = await http_client.fetch(req, raise_error=False)
if resp.body:
resp_json = json.loads(resp.body.decode('utf8', 'replace'))
access_level = resp_json.get('access_level', 0)
# We only allow access level Developer and above
# Reference: https://docs.gitlab.com/ee/api/members.html
if resp.code == 200 and access_level >= 30:
return True
return False
class LocalGitLabOAuthenticator(LocalAuthenticator, GitLabOAuthenticator):
"""A version that mixes in local system user creation"""
pass