[SUCS Devel] [Git][sucs/gitlab-ldap-sync][master] Add support for gitlab token via envar

Imran Hussain (@imranh) gitlab at projects.sucs.org
Sat Jan 1 12:03:41 GMT 2022



Imran Hussain pushed to branch master at sucs / gitlab-ldap-sync


Commits:
72987e05 by Imran Hussain at 2022-01-01T12:02:06+00:00
Add support for gitlab token via envar

- - - - -


2 changed files:

- .gitlab-ci.yml
- sync.py


Changes:

=====================================
.gitlab-ci.yml
=====================================
@@ -1,10 +1,9 @@
+image: debian:stable
+
 stages:
   - test
   - run
 
-
-#before_script:
-
 python-syntax-check:
   stage: test
   script:
@@ -14,6 +13,8 @@ python-syntax-check:
 
 #run-live:
 #  stage: run
+#  variables:
+#    GITLAB_TOKEN: $GITLABCI_VARIABLE
 #  script:
 #   - apt update
 #   - apt install -y python3 python3-ldap python3-requests python3-yaml


=====================================
sync.py
=====================================
@@ -1,4 +1,5 @@
 import yaml
+import os
 import requests
 #import json
 import ldap
@@ -11,6 +12,13 @@ with open("config.yml", 'r') as ymlfile:
 #print(cfg["gitlab"])
 #print(cfg["gitlab"]["url"])
 
+if cfg["gitlab"]["token"] == None:
+    if not os.environ.get("GITLAB_TOKEN"):
+        print("No Gitlab token provided via config.yml or environment variable 'GITLAB_TOKEN'")
+        exit(1)
+    elif os.environ.get("GITLAB_TOKEN"):
+        cfg["gitlab"]["token"] = os.environ.get("GITLAB_TOKEN")
+
 ldap_connect = ldap.initialize(cfg["ldap"]["url"])
 
 # reconsile gitlab admins



View it on GitLab: https://projects.sucs.org/sucs/gitlab-ldap-sync/-/commit/72987e05201306f9c92633004e6fc26f79807057

-- 
View it on GitLab: https://projects.sucs.org/sucs/gitlab-ldap-sync/-/commit/72987e05201306f9c92633004e6fc26f79807057
You're receiving this email because of your account on projects.sucs.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20220101/da1b83cf/attachment-0001.html>


More information about the Devel mailing list