-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
更新 README 文件和添加示例数据 - 更新 README.md,简化了 `change-format/` 目录的描述 - 新增 features/change-format/sourcejson.txt 文件,包含示例 JSON 数据
- Loading branch information
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"date":"2024-06-24","total_active_users":24,"total_engaged_users":20,"copilot_ide_code_completions":{"total_engaged_users":20,"languages":[{"name":"python","total_engaged_users":10},{"name":"ruby","total_engaged_users":10}],"editors":[{"name":"vscode","total_engaged_users":13,"models":[{"name":"default","is_custom_model":false,"custom_model_training_date":null,"total_engaged_users":13,"languages":[{"name":"python","total_engaged_users":6,"total_code_suggestions":249,"total_code_acceptances":123,"total_code_lines_suggested":225,"total_code_lines_accepted":135},{"name":"ruby","total_engaged_users":7,"total_code_suggestions":496,"total_code_acceptances":253,"total_code_lines_suggested":520,"total_code_lines_accepted":270}]}]},{"name":"neovim","total_engaged_users":7,"models":[{"name":"a-custom-model","is_custom_model":true,"custom_model_training_date":"2024-02-01","languages":[{"name":"typescript","total_engaged_users":3,"total_code_suggestions":112,"total_code_acceptances":56,"total_code_lines_suggested":143,"total_code_lines_accepted":61},{"name":"go","total_engaged_users":4,"total_code_suggestions":132,"total_code_acceptances":67,"total_code_lines_suggested":154,"total_code_lines_accepted":72}]}]}]},"copilot_ide_chat":{"total_engaged_users":13,"editors":[{"name":"vscode","total_engaged_users":13,"models":[{"name":"default","is_custom_model":false,"custom_model_training_date":null,"total_engaged_users":12,"total_chats":45,"total_chat_insertion_events":12,"total_chat_copy_events":16},{"name":"a-custom-model","is_custom_model":true,"custom_model_training_date":"2024-02-01","total_engaged_users":1,"total_chats":10,"total_chat_insertion_events":11,"total_chat_copy_events":3}]}]},"copilot_dotcom_chat":{"total_engaged_users":14,"models":[{"name":"default","is_custom_model":false,"custom_model_training_date":null,"total_engaged_users":14,"total_chats":38}]},"copilot_dotcom_pull_requests":{"total_engaged_users":12,"repositories":[{"name":"demo/repo1","total_engaged_users":8,"models":[{"name":"default","is_custom_model":false,"custom_model_training_date":null,"total_pr_summaries_created":6,"total_engaged_users":8}]},{"name":"demo/repo2","total_engaged_users":4,"models":[{"name":"a-custom-model","is_custom_model":true,"custom_model_training_date":"2024-02-01","total_pr_summaries_created":10,"total_engaged_users":4}]}]}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import msal | ||
import requests | ||
|
||
def get_access_token(client_id, client_secret, tenant_id): | ||
authority = f"https://login.microsoftonline.com/{tenant_id}" | ||
app = msal.ConfidentialClientApplication(client_id, authority=authority, client_credential=client_secret) | ||
scope = ["https://graph.microsoft.com/.default"] | ||
result = app.acquire_token_for_client(scopes=scope) | ||
return result['access_token'] | ||
|
||
# add_user function to create a new user in Azure AD | ||
# headers: The headers containing the access token for the request. | ||
# user_data: the user data which is used to describe the new user. | ||
# based on https://learn.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0&tabs=http User.ReadWrite.All, Directory.ReadWrite.All is required to get the token | ||
def add_user(headers, user_data): | ||
response = requests.post('https://graph.microsoft.com/v1.0/users', headers=headers, json=user_data) | ||
|
||
if response.status_code == 201: | ||
print("User created successfully.") | ||
else: | ||
print(f"Error: {response.status_code}") | ||
print(response.json()) | ||
|
||
# access_token: The access token for the request. | ||
# user_list: The list of users to add. | ||
# password_list: The list of passwords for the user. | ||
def add_users(access_token, user_list, password_list): | ||
headers = { | ||
'Authorization': 'Bearer ' + access_token, | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
for user, password in zip(user_list, password_list): | ||
# user's format is like [email protected] | ||
username = user.split('@')[0] | ||
user_data = { | ||
"accountEnabled": True, | ||
"displayName": username, | ||
"mailNickname": username, | ||
"userPrincipalName": user, | ||
"passwordProfile": { | ||
"forceChangePasswordNextSignIn": False, | ||
"password": password | ||
} | ||
} | ||
add_user(headers, user_data) | ||
|
||
# function to create a group in Azure AD | ||
# access_token: The access token for the request. | ||
# group_name: The name of the group to create. | ||
# based on https://learn.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0&tabs=http , Group.ReadWrite.All is required to get the token | ||
def add_group(access_token, group_name): | ||
headers = { | ||
'Authorization': 'Bearer ' + access_token, | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
group_data = { | ||
"displayName": group_name, | ||
"mailEnabled": False, | ||
"mailNickname": group_name, | ||
"securityEnabled": True | ||
} | ||
|
||
response = requests.post('https://graph.microsoft.com/v1.0/groups', headers=headers, json=group_data) | ||
|
||
if response.status_code == 201: | ||
print("Group created successfully.") | ||
else: | ||
print(f"Error: {response.status_code}") | ||
print(response.json()) | ||
|
||
# read user list from file | ||
# each line is a user and password pair separated by tab key | ||
def read_user_list(): | ||
with open('users.txt', 'r') as f: | ||
lines = f.read().splitlines() | ||
|
||
# userlist is the first part of each line before tab key | ||
userlist = [line.split('\t')[0] for line in lines] | ||
return userlist | ||
|
||
# read password list from file | ||
# each line is a user and password pair separated by tab key | ||
def read_password_list(): | ||
with open('users.txt', 'r') as f: | ||
lines = f.read().splitlines() | ||
|
||
# passwordlist is the second part of each line after tab key | ||
passwordlist = [line.split('\t')[1] for line in lines] | ||
return passwordlist | ||
|
||
# Example usage | ||
CLIENT_ID = '<client_id>' | ||
CLIENT_SECRET = '<client_secret>' | ||
TENANT_ID = '<tenant_id>' | ||
|
||
|
||
|
||
users = read_user_list() | ||
passwords = read_password_list() | ||
access_token = get_access_token(CLIENT_ID, CLIENT_SECRET, TENANT_ID) | ||
add_users(access_token, users, passwords) |