@@ -4,10 +4,7 @@ use shuttle_admin::{
4
4
client:: Client ,
5
5
config:: get_api_key,
6
6
} ;
7
- use std:: {
8
- collections:: { hash_map:: RandomState , HashMap } ,
9
- fmt:: Write ,
10
- } ;
7
+ use shuttle_backends:: project_name:: ProjectName ;
11
8
use tracing:: trace;
12
9
13
10
#[ tokio:: main]
@@ -21,131 +18,63 @@ async fn main() {
21
18
let api_key = get_api_key ( ) ;
22
19
let client = Client :: new ( args. api_url . clone ( ) , api_key) ;
23
20
24
- let res = match args. command {
25
- Command :: Revive => client. revive ( ) . await . expect ( "revive to succeed" ) ,
26
- Command :: Destroy => client. destroy ( ) . await . expect ( "destroy to succeed" ) ,
21
+ match args. command {
22
+ Command :: Revive => {
23
+ let s = client. revive ( ) . await . expect ( "revive to succeed" ) ;
24
+ println ! ( "{s}" ) ;
25
+ }
26
+ Command :: Destroy => {
27
+ let s = client. destroy ( ) . await . expect ( "destroy to succeed" ) ;
28
+ println ! ( "{s}" ) ;
29
+ }
27
30
Command :: Acme ( AcmeCommand :: CreateAccount { email, acme_server } ) => {
28
31
let account = client
29
32
. acme_account_create ( & email, acme_server)
30
33
. await
31
34
. expect ( "to create ACME account" ) ;
32
35
33
- let mut res = String :: new ( ) ;
34
- writeln ! ( res, "Details of ACME account are as follow. Keep this safe as it will be needed to create certificates in the future" ) . unwrap ( ) ;
35
- writeln ! ( res, "{}" , serde_json:: to_string_pretty( & account) . unwrap( ) ) . unwrap ( ) ;
36
-
37
- res
36
+ println ! ( "Details of ACME account are as follow. Keep this safe as it will be needed to create certificates in the future" ) ;
37
+ println ! ( "{}" , serde_json:: to_string_pretty( & account) . unwrap( ) ) ;
38
38
}
39
39
Command :: Acme ( AcmeCommand :: Request {
40
40
fqdn,
41
41
project,
42
42
credentials,
43
- } ) => client
44
- . acme_request_certificate ( & fqdn, & project, & credentials)
45
- . await
46
- . expect ( "to get a certificate challenge response" ) ,
43
+ } ) => {
44
+ let s = client
45
+ . acme_request_certificate ( & fqdn, & project, & credentials)
46
+ . await
47
+ . expect ( "to get a certificate challenge response" ) ;
48
+ println ! ( "{s}" ) ;
49
+ }
47
50
Command :: Acme ( AcmeCommand :: RenewCustomDomain {
48
51
fqdn,
49
52
project,
50
53
credentials,
51
- } ) => client
52
- . acme_renew_custom_domain_certificate ( & fqdn, & project, & credentials)
53
- . await
54
- . expect ( "to get a certificate challenge response" ) ,
55
- Command :: Acme ( AcmeCommand :: RenewGateway { credentials } ) => client
56
- . acme_renew_gateway_certificate ( & credentials)
57
- . await
58
- . expect ( "to get a certificate challenge response" ) ,
54
+ } ) => {
55
+ let s = client
56
+ . acme_renew_custom_domain_certificate ( & fqdn, & project, & credentials)
57
+ . await
58
+ . expect ( "to get a certificate challenge response" ) ;
59
+ println ! ( "{s}" ) ;
60
+ }
61
+ Command :: Acme ( AcmeCommand :: RenewGateway { credentials } ) => {
62
+ let s = client
63
+ . acme_renew_gateway_certificate ( & credentials)
64
+ . await
65
+ . expect ( "to get a certificate challenge response" ) ;
66
+ println ! ( "{s}" ) ;
67
+ }
59
68
Command :: ProjectNames => {
60
69
let projects = client
61
70
. get_projects ( )
62
71
. await
63
72
. expect ( "to get list of projects" ) ;
64
-
65
- let projects: HashMap < String , String , RandomState > = HashMap :: from_iter (
66
- projects
67
- . into_iter ( )
68
- . map ( |project| ( project. project_name , project. account_name ) ) ,
69
- ) ;
70
-
71
- let mut res = String :: new ( ) ;
72
-
73
- for ( project_name, account_name) in & projects {
74
- let mut issues = Vec :: new ( ) ;
75
- let cleaned_name = project_name. to_lowercase ( ) ;
76
-
77
- // Were there any uppercase characters
78
- if & cleaned_name != project_name {
79
- // Since there were uppercase characters, will the new name clash with any existing projects
80
- if let Some ( other_account) = projects. get ( & cleaned_name) {
81
- if other_account == account_name {
82
- issues. push (
83
- "changing to lower case will clash with same owner" . to_string ( ) ,
84
- ) ;
85
- } else {
86
- issues. push ( format ! (
87
- "changing to lower case will clash with another owner: {other_account}"
88
- ) ) ;
89
- }
90
- }
91
- }
92
-
93
- let cleaned_underscore = cleaned_name. replace ( '_' , "-" ) ;
94
- // Were there any underscore cleanups
95
- if cleaned_underscore != cleaned_name {
96
- // Since there were underscore cleanups, will the new name clash with any existing projects
97
- if let Some ( other_account) = projects. get ( & cleaned_underscore) {
98
- if other_account == account_name {
99
- issues
100
- . push ( "cleaning underscore will clash with same owner" . to_string ( ) ) ;
101
- } else {
102
- issues. push ( format ! (
103
- "cleaning underscore will clash with another owner: {other_account}"
104
- ) ) ;
105
- }
106
- }
107
- }
108
-
109
- let cleaned_separator_name = cleaned_underscore. trim_matches ( '-' ) ;
110
- // Were there any dash cleanups
111
- if cleaned_separator_name != cleaned_underscore {
112
- // Since there were dash cleanups, will the new name clash with any existing projects
113
- if let Some ( other_account) = projects. get ( cleaned_separator_name) {
114
- if other_account == account_name {
115
- issues. push ( "cleaning dashes will clash with same owner" . to_string ( ) ) ;
116
- } else {
117
- issues. push ( format ! (
118
- "cleaning dashes will clash with another owner: {other_account}"
119
- ) ) ;
120
- }
121
- }
122
- }
123
-
124
- // Are reserved words used
125
- match cleaned_separator_name {
126
- "shuttleapp" | "shuttle" => issues. push ( "is a reserved name" . to_string ( ) ) ,
127
- _ => { }
128
- }
129
-
130
- // Is it longer than 63 chars
131
- if cleaned_separator_name. len ( ) > 63 {
132
- issues. push ( "final name is too long" . to_string ( ) ) ;
133
- }
134
-
135
- // Only report of problem projects
136
- if !issues. is_empty ( ) {
137
- writeln ! ( res, "{project_name}" )
138
- . expect ( "to write name of project name having issues" ) ;
139
-
140
- for issue in issues {
141
- writeln ! ( res, "\t - {issue}" ) . expect ( "to write issue with project name" ) ;
142
- }
143
-
144
- writeln ! ( res) . expect ( "to write a new line" ) ;
73
+ for p in projects {
74
+ if !ProjectName :: is_valid ( & p. project_name ) {
75
+ println ! ( "{}" , p. project_name) ;
145
76
}
146
77
}
147
-
148
- res
149
78
}
150
79
Command :: Stats ( StatsCommand :: Load { clear } ) => {
151
80
let resp = if clear {
@@ -156,14 +85,14 @@ async fn main() {
156
85
157
86
let has_capacity = if resp. has_capacity { "a" } else { "no" } ;
158
87
159
- format ! (
88
+ println ! (
160
89
"Currently {} builds are running and there is {} capacity for new builds" ,
161
90
resp. builds_count, has_capacity
162
91
)
163
92
}
164
93
Command :: IdleCch => {
165
94
client. idle_cch ( ) . await . expect ( "cch projects to be idled" ) ;
166
- "Idled CCH projects" . to_string ( )
95
+ println ! ( "Idled CCH projects" )
167
96
}
168
97
Command :: ChangeProjectOwner {
169
98
project_name,
@@ -173,9 +102,7 @@ async fn main() {
173
102
. change_project_owner ( & project_name, & new_user_id)
174
103
. await
175
104
. unwrap ( ) ;
176
- format ! ( "Changed project owner: {project_name} -> {new_user_id}" )
105
+ println ! ( "Changed project owner: {project_name} -> {new_user_id}" )
177
106
}
178
107
} ;
179
-
180
- println ! ( "{res}" ) ;
181
108
}
0 commit comments