public async Task <DependencyVersion> GetLatestMetaDataAsync(RegistryDto registry, Dependency dependency) { RegistryClientConfiguration clientConfig = new RegistryClientConfiguration(new Uri(registry.Endpoint).GetComponents(UriComponents.HostAndPort, UriFormat.SafeUnescaped)); DependencyVersion version; if (!string.IsNullOrWhiteSpace(registry.Username) && !string.IsNullOrWhiteSpace(registry.Password)) { using (IRegistryClient client = clientConfig.CreateClient(new PasswordOAuthAuthenticationProvider(registry.Username, registry.Password))) { ListImageTagsResponse imageTags = await client.Tags.ListImageTagsAsync(dependency.Name, new ListImageTagsParameters()); version = new DependencyVersion { Dependency = dependency, DependencyId = dependency.Id, Version = imageTags.Tags.Last(), IsLatest = true }; } } else { using (IRegistryClient client = clientConfig.CreateClient()) { ListImageTagsResponse imageTags = await client.Tags.ListImageTagsAsync(dependency.Name, new ListImageTagsParameters()); version = new DependencyVersion { Dependency = dependency, DependencyId = dependency.Id, Version = imageTags.Tags.Last(), IsLatest = true }; } } return(version); }
private async Task ConnectAsync() { try { var configuration = new RegistryClientConfiguration(Registry); AuthenticationProvider authenticationProvider; if (IsAnonymous) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(Username, Password); } var client = configuration.CreateClient(authenticationProvider); await client.System.PingAsync(); var connection = new RegistryConnection(client, Registry, IsAnonymous, Username, Password); Connection = connection; //Save the connections! Save(); RequestClose(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "Unable to connect"); } }
protected override async void Ok() { var ex = await Executor.ExecuteAsync(async() => { var configuration = new RegistryClientConfiguration(new Uri(Endpoint)); AuthenticationProvider authenticationProvider; if (IsAnonymous) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(Username, Password); } var client = configuration.CreateClient(authenticationProvider); await client.System.PingAsync(); RegistryClient = client; }); if (ex == null) { base.Ok(); } }
public async Task BlobUploadOperationTest() { var config = new RegistryClientConfiguration(new Uri("http://172.16.0.175:3000")); var client = config.CreateClient(); using (var fs = File.OpenRead("")) { await client.BlobUploads.UploadBlobAsync("Test", (int)fs.Length, fs, ""); } }
private static async Task TestAsync() { //string url = "https://registry-1.docker.io/"; string url = "http://10.0.4.44:5000/"; var configuration = new RegistryClientConfiguration(new Uri(url)); using (var client = configuration.CreateClient()) { var bytes = File.ReadAllBytes(@"c:\layer.txt"); string sha256Hash; using (var sha = SHA256.Create()) { var hash = sha.ComputeHash(bytes); sha256Hash = $"sha256:{string.Join("", hash.Select(b => b.ToString("x")))}"; } using (var source = File.OpenRead(@"c:\layer.txt")) { // await client.BlobUploads.UploadBlobAsync("my-repo", (int)source.Length, source, sha256Hash); } ////Console.WriteLine("Ping..."); ////var tags = await client.Tags.ListImageTagsAsync("resin", new ListImageTagsParameters()); ////foreach (var tag in tags.Tags) ////{ //// Console.WriteLine(); ////} //var catalog = await client.Catalog.GetCatalogAsync(new CatalogParameters() //{ // Number = 10 //}); //var repositories = catalog.Repositories; //foreach (var repository in repositories) //{ // Console.WriteLine("-----------------------------------------------"); // Console.WriteLine(repository); // Console.WriteLine("-----------------------------------------------"); // var tags = await client.Tags.ListImageTagsAsync(repository, new ListImageTagsParameters()); // foreach (var tag in tags.Tags) // { // Console.WriteLine($" {tag}"); // } //} //if (string.IsNullOrWhiteSpace(repository)) //{ // Console.WriteLine("No repository found."); //} //else //{ // var tagsReponse = await client.Tags.ListImageTagsAsync(repository, new ListImageTagsParameters()); // var tag = tagsReponse.Tags.FirstOrDefault(); // if (string.IsNullOrWhiteSpace(tag)) // { // Console.WriteLine("No tags found."); // } // else // { // var manifestResult = await client.Manifest.GetManifestAsync(repository, tag); // Console.WriteLine(manifestResult.Manifest.GetType().Name); // var imageManifest = manifestResult.Manifest as ImageManifest2_1; // if (imageManifest != null) // { // var layer = imageManifest.FsLayers.First(); // var getBlobResponse = await client.Blobs.GetBlobAsync(repository, layer.BlobSum); // Console.WriteLine($"\t\tDigetst: {getBlobResponse.DockerContentDigest}"); // using (getBlobResponse.Stream) // using (Stream targetStream = File.OpenWrite(@"c:\test.layer")) // { // await getBlobResponse.Stream.CopyToAsync(targetStream); // } // } // } //} } }
private async void btnLogin_Click(object sender, EventArgs e) { Cursor PreviousCursor = this.Cursor; Cursor = Cursors.WaitCursor; Button Sender = sender as Button; GroupBox grp = default; ComboBox comboEndpoint = default; CheckBox chkAnonymous = default; TextBox txtUserName = default; TextBox txtPassword = default; if (Sender == btnBaseLogin) { grp = grpBaseRegistry; comboEndpoint = comboBaseRegistry; chkAnonymous = chkBaseAnonymous; txtUserName = txtBaseUserName; txtPassword = txtBasePassword; _baseRegistryClient = null; } else { grp = grpTargetRegistry; comboEndpoint = comboTargetRegistry; chkAnonymous = chkTargetAnonymous; txtUserName = txtTargetUserName; txtPassword = txtTargetPassword; _targetRegistryClient = null; } if (Sender.Text == "Logout") { foreach (var control in grp.Controls) { if (control.GetType() == typeof(ListBox)) { ((ListBox)control).Items.Clear(); } if (control.GetType() == typeof(TextBox)) { ((TextBox)control).Text = ""; } // ... } _baseRegistryClient = null; Sender.Text = "Login"; comboEndpoint.Focus(); } else { var configuration = new RegistryClientConfiguration(comboEndpoint.SelectedItem?.ToString() ?? comboEndpoint.Text); AuthenticationProvider authenticationProvider; if (chkAnonymous.Checked) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(txtUserName.Text, txtPassword.Text); } var client = configuration.CreateClient(authenticationProvider); try { await client.System.PingAsync(); } catch (UnauthorizedAccessException ex) { // authentication failed MessageBox.Show($"Authentication failed with {ex.Message}", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } catch (RegistryConnectionException ex) { // connection failed MessageBox.Show($"Unable to connect, exception {ex.Message})", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } Sender.Text = "Logout"; if (Sender == btnBaseLogin) { _baseRegistryClient = client; } else { _targetRegistryClient = client; } } Cursor = PreviousCursor; }
private async void btnLogin_Click(object sender, EventArgs e) { Cursor PreviousCursor = this.Cursor; Cursor = Cursors.WaitCursor; if ((sender as Button).Text == "Logout") { Text = $"Not connected"; foreach (var control in grpControls.Controls) { if (control.GetType() == typeof(ListBox)) { ((ListBox)control).Items.Clear(); } if (control.GetType() == typeof(TextBox)) { ((TextBox)control).Text = ""; } // ... } grpControls.Enabled = false; _registryClient = null; btnLogin.Text = "Login"; comboEndpoint.Focus(); } else { var configuration = new RegistryClientConfiguration(comboEndpoint.SelectedItem?.ToString() ?? comboEndpoint.Text); AuthenticationProvider authenticationProvider; if (chkAnonymous.Checked) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(txtUserName.Text, txtPassword.Text); } var client = configuration.CreateClient(authenticationProvider); try { await client.System.PingAsync(); } catch (UnauthorizedAccessException ex) { // authentication failed MessageBox.Show("Authentication failed", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } catch (RegistryConnectionException ex) { // connection failed MessageBox.Show("Unable to connect", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } Text = $"Connected to endpoint {comboEndpoint.SelectedItem.ToString()}"; grpControls.Enabled = true; btnLogin.Text = "Logout"; _registryClient = client; btnCatalog.Focus(); } Cursor = PreviousCursor; }