nebu 0.1.88__py3-none-any.whl → 0.1.93__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.
@@ -3,6 +3,7 @@ from typing import Dict, List, Optional
3
3
  import requests
4
4
 
5
5
  from nebu.config import GlobalConfig
6
+ from nebu.logging import logger
6
7
  from nebu.namespaces.models import (
7
8
  V1Namespace,
8
9
  V1NamespaceMetaRequest,
@@ -22,6 +23,7 @@ class Namespace:
22
23
  labels: Optional[Dict[str, str]] = None,
23
24
  owner: Optional[str] = None,
24
25
  config: Optional[GlobalConfig] = None,
26
+ api_key: Optional[str] = None,
25
27
  ):
26
28
  self.config = config or GlobalConfig.read()
27
29
  if not self.config:
@@ -30,7 +32,7 @@ class Namespace:
30
32
  if not current_server:
31
33
  raise ValueError("No server config found")
32
34
  self.current_server = current_server
33
- self.api_key = current_server.api_key
35
+ self.api_key = api_key or current_server.api_key
34
36
  self.nebu_host = current_server.server
35
37
  self.name = name
36
38
  self.labels = labels
@@ -43,7 +45,7 @@ class Namespace:
43
45
  )
44
46
  response.raise_for_status()
45
47
  resp_json = response.json()
46
- print(resp_json)
48
+ logger.debug(resp_json)
47
49
  existing_namespaces = V1Namespaces.model_validate(resp_json)
48
50
  self.namespace: Optional[V1Namespace] = next(
49
51
  (
@@ -56,7 +58,7 @@ class Namespace:
56
58
 
57
59
  # If not found, create
58
60
  if not self.namespace:
59
- print(f"Creating namespace {name}")
61
+ logger.info(f"Creating namespace {name}")
60
62
  # Create metadata and namespace request
61
63
  metadata = V1NamespaceMetaRequest(name=name, labels=labels, owner=owner)
62
64
 
@@ -71,20 +73,23 @@ class Namespace:
71
73
  )
72
74
  create_response.raise_for_status()
73
75
  self.namespace = V1Namespace.model_validate(create_response.json())
74
- print(f"Created Namespace {self.namespace.metadata.name}")
76
+ logger.info(f"Created Namespace {self.namespace.metadata.name}")
75
77
  else:
76
- print(f"Found Namespace {self.namespace.metadata.name}, no update needed")
78
+ logger.info(
79
+ f"Found Namespace {self.namespace.metadata.name}, no update needed"
80
+ )
77
81
 
78
82
  @classmethod
79
83
  def load(
80
84
  cls,
81
85
  name: str,
82
86
  config: Optional[GlobalConfig] = None,
87
+ api_key: Optional[str] = None,
83
88
  ):
84
89
  """
85
90
  Get a Namespace from the remote server.
86
91
  """
87
- namespaces = cls.get(name=name, config=config)
92
+ namespaces = cls.get(name=name, config=config, api_key=api_key)
88
93
  if not namespaces:
89
94
  raise ValueError("Namespace not found")
90
95
  namespace_v1 = namespaces[0]
@@ -97,7 +102,7 @@ class Namespace:
97
102
  out.current_server = out.config.get_current_server_config()
98
103
  if not out.current_server:
99
104
  raise ValueError("No server config found")
100
- out.api_key = out.current_server.api_key
105
+ out.api_key = api_key or out.current_server.api_key
101
106
  out.nebu_host = out.current_server.server
102
107
  out.namespaces_url = f"{out.nebu_host}/v1/namespaces"
103
108
  out.name = name
@@ -109,6 +114,7 @@ class Namespace:
109
114
  cls,
110
115
  name: Optional[str] = None,
111
116
  config: Optional[GlobalConfig] = None,
117
+ api_key: Optional[str] = None,
112
118
  ) -> List[V1Namespace]:
113
119
  """
114
120
  Get a list of Namespaces that optionally match the name filter.
@@ -119,11 +125,12 @@ class Namespace:
119
125
  current_server = config.get_current_server_config()
120
126
  if not current_server:
121
127
  raise ValueError("No server config found")
128
+ api_key = api_key or current_server.api_key
122
129
  namespaces_url = f"{current_server.server}/v1/namespaces"
123
130
 
124
131
  response = requests.get(
125
132
  namespaces_url,
126
- headers={"Authorization": f"Bearer {current_server.api_key}"},
133
+ headers={"Authorization": f"Bearer {api_key}"},
127
134
  )
128
135
  response.raise_for_status()
129
136