private async void GetOneSshKeyButton_Click(object sender, RoutedEventArgs e) { try { this.AddLogMessage("load ssh-key"); string sshKeyId = await this.ShowInputAsync( "SSH-Key-ID", "enter the SSH-Key id"); long id = Convert.ToInt64(sshKeyId); lkcode.hetznercloudapi.Api.SshKey sshKey = await lkcode.hetznercloudapi.Api.SshKey.GetAsync(id); List <lkcode.hetznercloudapi.Api.SshKey> sshKeyList = new List <lkcode.hetznercloudapi.Api.SshKey>(); sshKeyList.Add(sshKey); this.SshKeysDataGrid.ItemsSource = null; this.SshKeysDataGrid.ItemsSource = sshKeyList; this.AddLogMessage(string.Format("loaded ssh-key with id {0} and name '{1}'", sshKey.Id, sshKey.Name)); } catch (Exception err) { this.AddLogMessage(string.Format("error: {0}", err.Message)); } }
/// <summary> /// Returns all ssh-keys in a list. /// </summary> /// <returns></returns> public static async Task <List <SshKey> > GetAsync(int page = 1) { if ((_maxPages > 0 && (page <= 0 || page > _maxPages))) { throw new InvalidPageException("invalid page number (" + page + "). valid values between 1 and " + _maxPages + ""); } List <SshKey> sshKeyList = new List <SshKey>(); string url = string.Format("/ssh_keys"); if (page > 1) { url += "?page=" + page.ToString(); } string responseContent = await ApiCore.SendRequest(url); Objects.SshKey.Get.Response response = JsonConvert.DeserializeObject <Objects.SshKey.Get.Response>(responseContent); // load meta CurrentPage = response.meta.pagination.page; float pagesDValue = ((float)response.meta.pagination.total_entries / (float)response.meta.pagination.per_page); MaxPages = (int)Math.Ceiling(pagesDValue); foreach (Objects.SshKey.Universal.SshKey responseSshKey in response.ssh_keys) { SshKey sshKey = GetSshKeyFromResponseData(responseSshKey); sshKeyList.Add(sshKey); } return(sshKeyList); }
/// <summary> /// /// </summary> /// <param name="responseData"></param> /// <returns></returns> private static SshKey GetSshKeyFromResponseData(Objects.SshKey.Universal.SshKey responseData) { SshKey sshKey = new SshKey(); sshKey.Id = responseData.id; sshKey.Name = responseData.name; sshKey.Fingerprint = responseData.fingerprint; sshKey.PublicKey = responseData.public_key; return(sshKey); }
/// <summary> /// Return a ssh-key by the given id. /// </summary> /// <returns></returns> public static async Task <SshKey> GetAsync(long id) { SshKey sshKey = new SshKey(); string url = string.Format("/ssh_keys/{0}", id); string responseContent = await ApiCore.SendRequest(url); Objects.SshKey.GetOne.Response response = JsonConvert.DeserializeObject <Objects.SshKey.GetOne.Response>(responseContent); sshKey = GetSshKeyFromResponseData(response.ssh_key); return(sshKey); }