尊龙凯时人生就是博

gitlabÔõôÅúÁ¿ÐÞ¸ÄÓû§ÃûºÍÃÜÂë

ÈôÊÇÄúÊÇÒ»¼ÒÆóÒµ£¬Äú¿ÉÄÜÐèÒªÖÎÀí¶à¸ögitlabÕË»§£¬¶øÕâЩÕÊ»§µÄÓû§ÃûºÍÃÜÂëÐèÒª°´ÆÚ¸ü¸ÄÒÔÈ·±£Çå¾²ÐÔ¡£Õâʱ£¬ÅúÁ¿ÐÞ¸ÄgitlabÓû§ÃûºÍÃÜÂë¾ÍÏÔµÃÓÈΪÖ÷Òª¡£

ÏÂÃ棬ÎÒ½«ÏòÄúÏÈÈÝÔõÑùʹÓþ籾ÅúÁ¿ÐÞ¸ÄGitLabÓû§ÃûºÍÃÜÂë¡£

°ì·¨Ò»£º½¨ÉèGitLab APIÁîÅÆ

Ê×ÏÈ£¬ÄúÐèÒª½¨ÉèGitLabµÄAPIÁîÅƲŻª»á¼ûGitLabµÄAPI¡£Òª½¨ÉèAPIÁîÅÆ£¬Çëƾ֤ÒÔÏ°취²Ù×÷£º

ÔÚGitLabÖУ¬µ¥»÷Í·Ïñ»òͼ±ê£¬È»ºóÑ¡Ôñ¡°Settings¡±¡£

ÕÒµ½×ó²àµÄ¡°Access Tokens¡±Ñ¡Ï£¬µ¥»÷½¨ÉèСÎÒ˽ÈË»á¼ûÁîÅÆ¡£

ÔÚ¡°Scopes¡±ÏÂÃæÑ¡Ôñ¡°API¡±APIȨÏÞ£¬È»ºóµ¥»÷¡°Create Personal Access Token¡±°´Å¥¡£GitLab½«ÌìÉúÒ»¸öеÄAPIÁîÅÆ£¬²¢ÇÒÖ»»á·ºÆðÒ»´Î¡£

Çë×¢ÖØ£¬API»á¼ûÁîÅƽ«±»ÊÓΪÉí·ÝÑé֤ƾ֤£¬Òò´ËÇëÎñ±ØÉúÑÄËüÃÇ£¬²¢Í×ÉƱ£¹Ü¡£

°ì·¨¶þ£º½¨ÉèPython¾ç±¾

ÏÖÔÚÄúÐèҪʹÓÃPython±àдһ¸ö¾ç±¾£¬ÒÔÔÚGitLabÉÏÅúÁ¿¸ü¸ÄÓû§ÃûºÍÃÜÂë¡£ÒÔÏÂÊÇPython¾ç±¾µÄ´úÂëʾÀý£º

#!/usr/bin/env python
import requests
import json

# ÉèÖÃAPI»á¼ûÁîÅÆ£¬API¶ËµãºÍÒª¸ü¸ÄµÄÓû§ÃûºÍÃÜÂë
GITLAB_API_ENDPOINT = "https://gitlab.com/api/v4"
GITLAB_API_TOKEN = "YOUR_GITLAB_API_TOKEN"
USERNAMES_TO_UPDATE = ["john.doe", "jane.doe"]
NEW_PASSWORD = "newpassword"

# ÈÏÖ¤
headers = {"PRIVATE-TOKEN": GITLAB_API_TOKEN}

# Ñ­»·´¦Àíÿ¸öÓû§
for username in USERNAMES_TO_UPDATE:
    # »ñÈ¡¸ø¶¨Óû§µÄÄ¿½ñÐÅÏ¢
    response = requests.get(
        f"{GITLAB_API_ENDPOINT}/users?username={username}",
        headers=headers,
    )
    user_data = response.json()[0]
    user_id = user_data["id"]
    user_name = user_data["name"]
    user_email = user_data["email"]

    # ¸üиø¶¨Óû§µÄÃÜÂë
    password_update_response = requests.put(
        f"{GITLAB_API_ENDPOINT}/users/{user_id}",
        headers=headers,
        data={
            "password": NEW_PASSWORD
        },
    )

    # ´òӡЧ¹û
    print(f"Óû§ {user_name} ({user_email}) µÄÃÜÂëÒѸüС£")

µÇ¼ºó¸´ÖÆ

Õâ¸ö´úÂëÊǽÏÁ¿¼òÆӵģ¬»ù±¾µÄÍ·ÄÔ¾ÍÊÇÓÃrequests¿âŲÓÃGitLabµÄAPI£¬»ñÈ¡Óû§Êý¾Ý²¢¸üÐÂÓû§Êý¾ÝµÄÃÜÂ롣ΪÁËʹ¾ç±¾Ë³Ó¦ÄúµÄÌض¨ÇéÐΣ¬ÄúÐèÒªÌæ»»ÒÔϳ£Á¿£º

GITLAB_API_TOKEN£ºÄú½¨ÉèµÄGitLab API»á¼ûÁîÅÆ¡£

USERNAMES_TO_UPDATE£ºÄúÒª¸ü¸ÄËüÃǵÄÓû§µÄÓû§ÃûÁбí¡£

NEW_PASSWORD£ºÄúҪΪÕâЩÓû§ÉèÖõÄÐÂÃÜÂë¡£

×îºó£¬½«¾ç±¾ÉúÑÄΪÀýÈçupdate_gitlab_passwords.py¡£

°ì·¨Èý£ºÔËÐо籾

ÏÖÔÚ£¬Äú¿ÉÒÔʹÓÃÏÂÁîÐÐÔËÐо籾¡£Äú¿ÉÒÔÔÚÖն˻òÏÂÁîÌáÐÑ·ûÖÐÖ´ÐÐÒÔÏÂÏÂÁ

python update_gitlab_passwords.py

µÇ¼ºó¸´ÖÆ

Äú»¹¿ÉÒÔÔÚCron×÷ÒµÖÐ×Ô¶¯ÔËÐо籾£¬ÒԱ㰴ÆÚ¸ü¸ÄGitLabÓû§ÃûºÍÃÜÂë¡£

×ܽá

ÏÖÔÚÄúÒѾ­ÏàʶÁËÔõÑùʹÓÃPython¾ç±¾ÅúÁ¿¸üÐÂGitLabµÄÓû§ÃûºÍÃÜÂë¡£Çë¼Ç×Å£¬ÕâЩAPIÁîÅƽ«±»ÊÓΪÉí·ÝÑé֤ƾ֤£¬ÇëÎñ±Ø±£»¤ËüÃÇ£¬²¢½ö½«ËüÃÇÓÃÓÚÇå¾²µÄ·½·¨¡£

ÒÔÉϾÍÊÇgitlabÔõôÅúÁ¿ÐÞ¸ÄÓû§ÃûºÍÃÜÂëµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ