Changeset 404 for binary-improvements2/WebServer/src/Commands/WebTokens.cs
- Timestamp:
- Feb 16, 2023, 3:50:53 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/Commands/WebTokens.cs
r402 r404 2 2 using System.Text.RegularExpressions; 3 3 using JetBrains.Annotations; 4 using Webserver.Permissions; 4 5 5 6 namespace Webserver.Commands { … … 19 20 return "Set/get webtoken permission levels. A level of 0 is maximum permission.\n" + 20 21 "Usage:\n" + 21 " webtokens add < username> <usertoken> <level>\n" +22 " webtokens remove < username>\n" +22 " webtokens add <tokenname> <tokensecret> <level>\n" + 23 " webtokens remove <tokenname>\n" + 23 24 " webtokens list"; 24 25 } … … 47 48 48 49 if (string.IsNullOrEmpty (_params [1])) { 49 SdtdConsole.Instance.Output ("Argument ' username' is empty.");50 SdtdConsole.Instance.Output ("Argument 'tokenname' is empty."); 50 51 return; 51 52 } … … 53 54 if (!validNameTokenMatcher.IsMatch (_params [1])) { 54 55 SdtdConsole.Instance.Output ( 55 "Argument ' username' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");56 "Argument 'tokenname' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 56 57 return; 57 58 } 58 59 59 60 if (string.IsNullOrEmpty (_params [2])) { 60 SdtdConsole.Instance.Output ("Argument ' usertoken' is empty.");61 SdtdConsole.Instance.Output ("Argument 'tokensecret' is empty."); 61 62 return; 62 63 } … … 64 65 if (!validNameTokenMatcher.IsMatch (_params [2])) { 65 66 SdtdConsole.Instance.Output ( 66 "Argument ' usertoken' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");67 "Argument 'tokensecret' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 67 68 return; 68 69 } … … 73 74 } 74 75 75 WebPermissions.Instance.AddAdmin (_params [1], _params [2], level);76 SdtdConsole.Instance.Output ($"Web user with name={_params [1]} and password={_params [2]} added with permission level of {level}.");76 AdminApiTokens.Instance.AddToken (_params [1], _params [2], level); 77 SdtdConsole.Instance.Output ($"Web API token with name={_params [1]} and secret={_params [2]} added with permission level of {level}."); 77 78 } 78 79 … … 84 85 85 86 if (string.IsNullOrEmpty (_params [1])) { 86 SdtdConsole.Instance.Output ("Argument ' username' is empty.");87 SdtdConsole.Instance.Output ("Argument 'tokenname' is empty."); 87 88 return; 88 89 } … … 90 91 if (!validNameTokenMatcher.IsMatch (_params [1])) { 91 92 SdtdConsole.Instance.Output ( 92 "Argument ' username' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_).");93 "Argument 'tokenname' may only contain characters (A-Z, a-z), digits (0-9) and underscores (_)."); 93 94 return; 94 95 } 95 96 96 WebPermissions.Instance.RemoveAdmin (_params [1]);97 SdtdConsole.Instance.Output ($"{_params [1]} removed from web userpermissions list.");97 AdminApiTokens.Instance.RemoveToken (_params [1]); 98 SdtdConsole.Instance.Output ($"{_params [1]} removed from web API token permissions list."); 98 99 } 99 100 100 101 private void ExecuteList () { 101 SdtdConsole.Instance.Output ("Defined web userpermissions:");102 SdtdConsole.Instance.Output (" Level: Name / Token");103 foreach ( WebPermissions.AdminToken at in WebPermissions.Instance.GetAdmins ()) {104 SdtdConsole.Instance.Output ($" {a t.permissionLevel,5}: {at.name} / {at.token}");102 SdtdConsole.Instance.Output ("Defined web API token permissions:"); 103 SdtdConsole.Instance.Output (" Level: Name / Secret"); 104 foreach ((string _, AdminApiTokens.ApiToken apiToken) in AdminApiTokens.Instance.GetTokens ()) { 105 SdtdConsole.Instance.Output ($" {apiToken.PermissionLevel,5}: {apiToken.Name} / {apiToken.Secret}"); 105 106 } 106 107 }
Note:
See TracChangeset
for help on using the changeset viewer.