2020 PostgreSQLConnection ,
2121 S3Connection ,
2222)
23+ from ...cli .api import OpenHexaClient
24+
2325
2426class Country :
2527 """Represents a country with its code, name, alpha3 code and flag."""
@@ -32,6 +34,8 @@ def __init__(self, code: str, name: str, alpha3: str, flag: str):
3234
3335 def __repr__ (self ):
3436 return f"Country(code={ self .code } , name={ self .name } , alpha3={ self .alpha3 } , flag={ self .flag } )"
37+
38+
3539class WorkspaceConfigError (Exception ):
3640 """Raised whenever the system cannot find an environment variable required to configure the current workspace."""
3741
@@ -70,46 +74,13 @@ def slug(self) -> str:
7074 raise WorkspaceConfigError ("The workspace slug is not available in this environment." )
7175
7276 @property
73- def country (self ) -> Country :
74- """The country of the workspace."""
77+ def countries (self ) -> list [ Country ] :
78+ """The countries of the workspace."""
7579 try :
76- if self ._connected :
77- response = graphql (
78- """
79- query getWorkspaceCountry($slug: String!) {
80- workspace(slug: $slug) {
81- countries {
82- code
83- name
84- alpha3
85- flag
86- }
87- }
88- }
89- """ ,
90- {"slug" : self .slug },
91- )
92- countries = response ["workspace" ]["countries" ]
93- if not countries :
94- raise WorkspaceConfigError ("The workspace does not have a country configured." )
95- if len (response ["workspace" ]["countries" ]) > 1 :
96- warn (
97- "The workspace has multiple countries configured. The first one will be used." ,
98- UserWarning ,
99- stacklevel = 2 ,
100- )
101- # return the first country
102- first_country = response ["workspace" ]["countries" ][0 ]
103- return Country (
104- code = first_country ["code" ],
105- name = first_country ["name" ],
106- alpha3 = first_country ["alpha3" ],
107- flag = first_country ["flag" ],
108- )
109- else :
110- return os .environ ["WORKSPACE_COUNTRY" ]
80+ response = OpenHexaClient ().get_countries (workspace_slug = self .slug )
81+ return response ["workspace" ]["countries" ]
11182 except KeyError :
112- raise WorkspaceConfigError ("The workspace country is not available in this environment." )
83+ raise WorkspaceConfigError ("The workspace countries are not available in this environment." )
11384
11485 @property
11586 def database_host (self ) -> str :
0 commit comments