aap-utils 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aap_utils/cli.py CHANGED
@@ -1,36 +1,70 @@
1
1
  import os
2
+ import re
3
+ import requests
4
+
5
+ API_URL = "http://commit-svc.aiplatform/publish"
2
6
 
3
7
  def extract_default_image():
4
- """Extracts the image name from KERNEL_IMAGE if available."""
8
+ """Extracts the image name from KERNEL_IMAGE if available and formats it."""
5
9
  kernel_image = os.getenv("KERNEL_IMAGE", "admin/base_kernel_gpu@sha256:3024")
6
- return kernel_image.split("/")[1].split("@")[0] # Extract "base_kernel_gpu"
10
+ image_name = kernel_image.split("/")[1].split("@")[0] # Extract "base_kernel_gpu"
11
+ return format_name(image_name)
12
+
13
+ def format_name(name):
14
+ """Ensure the name is lowercase and contains only valid characters."""
15
+ return re.sub(r'[^a-z0-9_]', '_', name.lower())
7
16
 
8
17
  def validate_image_name(image_name):
9
- """Validate image name format."""
10
- return bool(image_name and image_name.strip())
18
+ """Validate image name format: lowercase, only alphanumeric and underscores."""
19
+ return bool(re.fullmatch(r'[a-z0-9_]+', image_name))
11
20
 
12
21
  def validate_tags(tags):
13
- """Ensure tags are non-empty and separated by semicolon."""
14
- tag_list = [tag.strip() for tag in tags.split(";") if tag.strip()]
15
- return len(tag_list) > 0
22
+ """Ensure tags are non-empty, lowercase, contain only valid characters, and no spaces."""
23
+ tag_list = [format_name(tag.strip()) for tag in tags.split(";") if tag.strip()]
24
+ return all(re.fullmatch(r'[a-z0-9_]+', tag) for tag in tag_list) and len(tag_list) > 0
25
+
26
+ def get_username():
27
+ """Retrieve the username from the environment variable KERNEL_AP_USER or prompt for it."""
28
+ username = os.getenv("KERNEL_AP_USER")
29
+ if not username:
30
+ username = input("Enter username (KERNEL_AP_USER not set): ").strip()
31
+ return format_name(username)
16
32
 
17
33
  def publish_env():
18
- """Handles the 'aap_utils publish env' command."""
34
+ """Handles the 'aap_utils publish env' command and sends a POST request."""
35
+ username = get_username()
19
36
  default_image = extract_default_image()
20
37
 
21
38
  while True:
22
39
  image_name = input(f"Enter image name [{default_image}]: ").strip() or default_image
40
+ image_name = format_name(image_name)
23
41
  if validate_image_name(image_name):
24
42
  break
25
- print("Invalid image name. Please try again.")
43
+ print("Invalid image name. Use only lowercase letters, numbers, or underscores (_).")
26
44
 
27
45
  while True:
28
46
  tags = input("Enter tags (separated by ';'): ").strip()
29
- if validate_tags(tags):
47
+ formatted_tags = [format_name(tag) for tag in tags.split(";") if tag.strip()]
48
+ if validate_tags(";".join(formatted_tags)):
30
49
  break
31
- print("Invalid tags. Please enter at least one tag, separated by ';'.")
50
+ print("Invalid tags. Each tag must be lowercase, contain only letters, numbers, or underscores (_), and no spaces.")
51
+
52
+ data = {
53
+ "username": username,
54
+ "imagename": image_name,
55
+ "tags": formatted_tags
56
+ }
57
+
58
+ print(f"Publishing environment: {data}")
32
59
 
33
- print(f"Publishing environment with Image: {image_name}, Tags: {tags}")
60
+ try:
61
+ response = requests.post(API_URL, json=data)
62
+ if response.status_code == 200:
63
+ print("✅ Successfully published the environment!")
64
+ else:
65
+ print(f"❌ Failed to publish. Server responded with: {response.status_code}, {response.text}")
66
+ except requests.RequestException as e:
67
+ print(f"❌ Error connecting to the server: {e}")
34
68
 
35
69
  def main():
36
70
  import sys
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aap_utils
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A Python library for registering an IP address for AAP
5
5
  Author: Minh Dang
6
6
  Author-email: danghoangminh86@gmail.com
@@ -0,0 +1,8 @@
1
+ aap_utils/__init__.py,sha256=g6G3i3a5ANDJWqFX2oPsLpP93aTaoTj0gkMQzeqQIJw,172
2
+ aap_utils/cli.py,sha256=ifnQcXX6KbzL-Dm9v-SoLVl_63uXsW70Juq6qeWQhMo,2905
3
+ aap_utils/register.py,sha256=J9tukByU1mcy4SoaJOoGY8jjzL9JMuNTZGtCBSwwon0,3823
4
+ aap_utils-0.2.1.dist-info/METADATA,sha256=boJ_XinydvKnjW3oOZTsEYfA9KOFp6kphvNyGCou6fw,346
5
+ aap_utils-0.2.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ aap_utils-0.2.1.dist-info/entry_points.txt,sha256=K-h2toLoqFxAg4Bx2r7FWggKgYnAX9zp9s4Ms4r-d6s,49
7
+ aap_utils-0.2.1.dist-info/top_level.txt,sha256=Qt5xmL8_0_jhMl9uA3lg-xnvs4nCEyVj1tBE4vnp36M,10
8
+ aap_utils-0.2.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- aap_utils/__init__.py,sha256=g6G3i3a5ANDJWqFX2oPsLpP93aTaoTj0gkMQzeqQIJw,172
2
- aap_utils/cli.py,sha256=TSh2o6CpkiVodF4t88RA3LrAj_aymmb8szl5t7CWMT4,1410
3
- aap_utils/register.py,sha256=J9tukByU1mcy4SoaJOoGY8jjzL9JMuNTZGtCBSwwon0,3823
4
- aap_utils-0.2.0.dist-info/METADATA,sha256=SOAQ8YL8coe3-28zEDp7izDbgB5UcLd7GeLSEBnoLFo,346
5
- aap_utils-0.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- aap_utils-0.2.0.dist-info/entry_points.txt,sha256=K-h2toLoqFxAg4Bx2r7FWggKgYnAX9zp9s4Ms4r-d6s,49
7
- aap_utils-0.2.0.dist-info/top_level.txt,sha256=Qt5xmL8_0_jhMl9uA3lg-xnvs4nCEyVj1tBE4vnp36M,10
8
- aap_utils-0.2.0.dist-info/RECORD,,