Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalSSH
Commits
18556600
Commit
18556600
authored
Feb 28, 2019
by
Lukas Burgey
Browse files
Add more error handling when doing rest calls
parent
e8df6b87
Changes
1
Hide whitespace changes
Inline
Side-by-side
main.go
View file @
18556600
...
...
@@ -60,6 +60,19 @@ func restCall(method string, path string, body io.Reader) (responseBytes []byte,
return
}
if
response
.
StatusCode
>=
400
{
switch
response
.
StatusCode
{
case
403
:
err
=
fmt
.
Errorf
(
"Response: %s
\n\t
Is your access token valid?
\n\t
Is the issuer correct?"
,
response
.
Status
,
)
default
:
err
=
fmt
.
Errorf
(
"Response: %s"
,
response
.
Status
)
}
return
}
responseBytes
,
err
=
ioutil
.
ReadAll
(
response
.
Body
)
if
err
!=
nil
{
return
...
...
@@ -218,9 +231,9 @@ func sshConnect(creds api.Credentials) {
// use the credentials to access the service
if
credsBytes
,
err
:=
json
.
MarshalIndent
(
creds
,
""
,
" "
);
err
==
nil
{
log
.
Printf
(
"Received credentials:
%s"
,
credsBytes
)
log
.
Printf
(
"Received credentials:
\n
%s"
,
credsBytes
)
}
else
{
log
.
Printf
(
"Received credentials:
%s"
,
creds
)
log
.
Printf
(
"Received credentials:
\n
%s"
,
creds
)
}
var
(
userOk
,
hostOk
bool
...
...
@@ -252,7 +265,10 @@ func sshConnect(creds api.Credentials) {
cmd
.
Stdout
=
os
.
Stdout
err
=
cmd
.
Run
()
}
else
{
fmt
.
Printf
(
"Deployment successful. You can now ssh to the service using:
\n
ssh -i %s %s@%s'"
,
*
pubKey
,
sshUser
,
sshHost
)
fmt
.
Printf
(
"
\n
Deployment successful. You can now ssh to the service using:
\n
ssh -i %s %s@%s'
\n
"
,
*
pubKey
,
sshUser
,
sshHost
,
)
}
}
...
...
@@ -266,6 +282,9 @@ func main() {
os
.
Exit
(
1
)
}
log
.
Printf
(
"Using issuer: %s"
,
*
issuerURI
)
log
.
Printf
(
"Using access token: %s"
,
*
accessToken
)
var
serviceID
=
findServiceID
()
uploadPubKey
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment