check_aliyun_namespace/
check_aliyun_namespace.rs1use docker_image_pusher::{AuthConfig, error::Result, registry::RegistryClientBuilder};
6
7#[tokio::main]
8async fn main() -> Result<()> {
9 println!("🔍 Aliyun Registry Namespace Checker");
10 println!("=====================================");
11
12 let aliyun_registry = "registry.cn-beijing.aliyuncs.com";
14 let aliyun_username = "canny_best@163.com";
15 let aliyun_password = "ra201222";
16
17 let namespace = "canny_best";
19 let repository = "canny_best/test-repo";
20
21 println!("📊 Configuration:");
22 println!(" Registry: {}", aliyun_registry);
23 println!(" Username: {}", aliyun_username);
24 println!(" Namespace: {}", namespace);
25 println!(" Repository: {}", repository);
26 println!();
27
28 println!("🌐 Building Registry Client...");
30 let client = RegistryClientBuilder::new(format!("https://{}", aliyun_registry))
31 .with_timeout(3600)
32 .with_skip_tls(false)
33 .with_verbose(true)
34 .build()?;
35
36 println!("🔗 Testing registry connectivity...");
38 match client.test_connectivity().await {
39 Ok(_) => println!("✅ Registry is accessible"),
40 Err(e) => {
41 println!("⚠️ Registry connectivity test failed: {}", e);
42 println!(" This may be normal for some registries");
43 }
44 }
45
46 println!("🔐 Authenticating...");
48 let auth_config = AuthConfig::new(aliyun_username.to_string(), aliyun_password.to_string());
49
50 match client.authenticate(&auth_config).await {
51 Ok(Some(token)) => {
52 println!("✅ Authentication successful (token received)");
53
54 println!("📦 Checking repository access...");
56 match client.list_tags(repository, &Some(token.clone())).await {
57 Ok(tags) => {
58 println!("✅ Repository {} is accessible", repository);
59 println!("🏷️ Available tags: {:?}", tags);
60 }
61 Err(e) => {
62 println!("❌ Repository {} is not accessible: {}", repository, e);
63
64 println!("\n💡 To fix this issue:");
65 println!(" 1. Login to Aliyun Console: https://cr.console.aliyun.com/");
66 println!(" 2. Create namespace '{}' if it doesn't exist", namespace);
67 println!(
68 " 3. Create repository '{}' in the namespace",
69 repository.split('/').nth(1).unwrap_or("unknown")
70 );
71 println!(" 4. Ensure your account has push/pull permissions");
72
73 return Ok(());
74 }
75 }
76
77 println!("🔐 Testing repository-specific authentication...");
79 match client
80 .authenticate_for_repository(&auth_config, repository)
81 .await
82 {
83 Ok(Some(repo_token)) => {
84 println!("✅ Repository-specific authentication successful");
85
86 println!("🔍 Testing image existence check...");
88 match client
89 .check_image_exists(repository, "non-existent-tag", &Some(repo_token))
90 .await
91 {
92 Ok(exists) => {
93 if exists {
94 println!("⚠️ Image unexpectedly exists");
95 } else {
96 println!(
97 "✅ Image existence check works (image doesn't exist as expected)"
98 );
99 }
100 }
101 Err(e) => {
102 println!("⚠️ Image existence check failed: {}", e);
103 }
104 }
105 }
106 Ok(None) => {
107 println!("✅ Repository-specific authentication successful (no token)");
108 }
109 Err(e) => {
110 println!("❌ Repository-specific authentication failed: {}", e);
111 }
112 }
113 }
114 Ok(None) => {
115 println!("✅ Authentication successful (no token required)");
116 }
117 Err(e) => {
118 println!("❌ Authentication failed: {}", e);
119 println!("\n💡 Please check:");
120 println!(" - Username: {}", aliyun_username);
121 println!(" - Password is correct");
122 println!(" - Account has access to Aliyun Container Registry");
123 return Ok(());
124 }
125 }
126
127 println!("\n🎉 All checks completed!");
128 println!(
129 " Repository {} appears to be ready for push operations",
130 repository
131 );
132
133 Ok(())
134}