24
24
app = AsyncTyper ()
25
25
26
26
27
+ def get_repo_path (config_repo_str : str ) -> Path :
28
+ config_repo = TypeAdapter (ConfigSourceUrl ).validate_python (config_repo_str )
29
+ if config_repo .scheme != "git+file" or config_repo .path is None :
30
+ raise NotImplementedError ("Only git+file:// URLs are supported" )
31
+
32
+ repo_path = Path (config_repo .path )
33
+
34
+ return repo_path
35
+
36
+
37
+ def get_config_from_repo_path (repo_path : Path ) -> Config :
38
+ return ConfigSource .create_from_url (backend_url = repo_path ).read_config ()
39
+
40
+
27
41
@app .command ()
28
42
def generate_cs (config_repo : str ):
29
43
"""Generate a minimal DiracX configuration repository."""
30
44
# TODO: The use of TypeAdapter should be moved in to typer itself
31
- config_repo = TypeAdapter (ConfigSourceUrl ).validate_python (config_repo )
32
- if config_repo .scheme != "git+file" or config_repo .path is None :
33
- raise NotImplementedError ("Only git+file:// URLs are supported" )
34
- repo_path = Path (config_repo .path )
45
+
46
+ repo_path = get_repo_path (config_repo )
47
+
35
48
if repo_path .exists () and list (repo_path .iterdir ()):
36
49
typer .echo (f"ERROR: Directory { repo_path } already exists" , err = True )
37
50
raise typer .Exit (1 )
@@ -60,10 +73,8 @@ def add_vo(
60
73
):
61
74
"""Add a registry entry (vo) to an existing configuration repository."""
62
75
# TODO: The use of TypeAdapter should be moved in to typer itself
63
- config_repo = TypeAdapter (ConfigSourceUrl ).validate_python (config_repo )
64
- if config_repo .scheme != "git+file" or config_repo .path is None :
65
- raise NotImplementedError ("Only git+file:// URLs are supported" )
66
- repo_path = Path (config_repo .path )
76
+ repo_path = get_repo_path (config_repo )
77
+ config = get_config_from_repo_path (repo_path )
67
78
68
79
# A VO should at least contain a default group
69
80
new_registry = RegistryConfig (
@@ -77,8 +88,6 @@ def add_vo(
77
88
},
78
89
)
79
90
80
- config = ConfigSource .create_from_url (backend_url = repo_path ).read_config ()
81
-
82
91
if vo in config .Registry :
83
92
typer .echo (f"ERROR: VO { vo } already exists" , err = True )
84
93
raise typer .Exit (1 )
@@ -103,15 +112,11 @@ def add_group(
103
112
):
104
113
"""Add a group to an existing vo in the configuration repository."""
105
114
# TODO: The use of TypeAdapter should be moved in to typer itself
106
- config_repo = TypeAdapter (ConfigSourceUrl ).validate_python (config_repo )
107
- if config_repo .scheme != "git+file" or config_repo .path is None :
108
- raise NotImplementedError ("Only git+file:// URLs are supported" )
109
- repo_path = Path (config_repo .path )
115
+ repo_path = get_repo_path (config_repo )
116
+ config = get_config_from_repo_path (repo_path )
110
117
111
118
new_group = GroupConfig (Properties = set (properties ), Quota = None , Users = set ())
112
119
113
- config = ConfigSource .create_from_url (backend_url = repo_path ).read_config ()
114
-
115
120
if vo not in config .Registry :
116
121
typer .echo (f"ERROR: Virtual Organization { vo } does not exist" , err = True )
117
122
raise typer .Exit (1 )
@@ -139,16 +144,11 @@ def add_user(
139
144
):
140
145
"""Add a user to an existing vo and group."""
141
146
# TODO: The use of TypeAdapter should be moved in to typer itself
142
- config_repo = TypeAdapter (ConfigSourceUrl ).validate_python (config_repo )
143
- if config_repo .scheme != "git+file" or config_repo .path is None :
144
- raise NotImplementedError ("Only git+file:// URLs are supported" )
145
-
146
- repo_path = Path (config_repo .path )
147
+ repo_path = get_repo_path (config_repo )
148
+ config = get_config_from_repo_path (repo_path )
147
149
148
150
new_user = UserConfig (PreferedUsername = preferred_username )
149
151
150
- config = ConfigSource .create_from_url (backend_url = repo_path ).read_config ()
151
-
152
152
if vo not in config .Registry :
153
153
typer .echo (f"ERROR: Virtual Organization { vo } does not exist" , err = True )
154
154
raise typer .Exit (1 )
0 commit comments