// Grant privilege async Task GrantPrivilege() { try { var user = SelectedUser; if (user == null) { return; } grantPrivilegeDialog.InfluxDbClient = InfluxDbClient; await grantPrivilegeDialog.BindToUser(user); if (grantPrivilegeDialog.ShowDialog() == DialogResult.OK) { // Get the selected database and privilege to grant var username = grantPrivilegeDialog.User.Name; var database = grantPrivilegeDialog.SelectedDatabase; var privilege = grantPrivilegeDialog.SelectedPrivilege; // Ensure a database was selected if (string.IsNullOrWhiteSpace(database)) { AppForm.DisplayError("You must supply a database to grant a privilege for."); return; } // Otherwise if "None" was selected (shouldn't be possible), there's nothing to grant... else if (privilege == InfluxDbPrivileges.None) { return; } // Grant the privilege var response = await InfluxDbClient.GrantPrivilegeAsync(username, privilege, database); // Refresh the window if (response.Success) { await ExecuteRequestAsync(); } else { AppForm.DisplayError(response.Body); } // Update interface buttons UpdateUIState(); } } catch (Exception ex) { AppForm.DisplayException(ex); } }
// Edit privilege async Task EditPrivilege() { try { var user = SelectedUser; if (user == null) { return; } var grant = SelectedPrivilegeGrant; if (grant == null) { return; } // Bind to data editPrivilegeDialog.BindToGrant(user.Name, grant); if (editPrivilegeDialog.ShowDialog() == DialogResult.OK) { // Get the selected database and privilege to grant var username = editPrivilegeDialog.Username; var database = editPrivilegeDialog.Database; var privilege = editPrivilegeDialog.SelectedPrivilege; // Ensure a database was selected if (string.IsNullOrWhiteSpace(database)) { AppForm.DisplayError("You must supply a database to update a privilege for."); return; } InfluxDbApiResponse response = null; // If "None" was selected then we actually need to revoke the existing privilege if (privilege == InfluxDbPrivileges.None) { response = await InfluxDbClient.RevokePrivilegeAsync(username, grant.Privilege, database); } // Otherwise just grant the new privilege else { response = await InfluxDbClient.GrantPrivilegeAsync(username, privilege, database); } // Refresh the window if (response.Success) { await ExecuteRequestAsync(); } else { AppForm.DisplayError(response.Body); } // Update interface buttons UpdateUIState(); } } catch (Exception ex) { AppForm.DisplayException(ex); } }