Update modes for output files. Change server error handling

This commit is contained in:
tci@tcinet.ru 2023-07-18 15:00:49 +03:00
parent 30bd14ac30
commit aaaf2d3666
4 changed files with 33 additions and 18 deletions

14
README
View File

@ -34,13 +34,13 @@ TCI CertRobot
Пример файла конфигурации:
{
"backend_hostname" : "cs-tls.ru",
"api_path" : "api/1.0/",
"login" : "user@test.ru",
"password" : "your_password",
"working_dir" : "/etc/tcibot/private",
"root_cert_file" : "path_to_cert's_dir",
"debug" : false
"backend_hostname" : "cs-tls.ru",
"api_path" : "api/1.0/",
"login" : "user@test.ru",
"password" : "",
"working_dir" : "/etc/tcibot/private",
"root_cert_file" : "",
"debug" : false
}
Вызов

View File

@ -580,6 +580,7 @@ var DCVtype int
certFile.Close()
panic("Could not create output file (key)! " + err.Error())
}
keyFile.Chmod(os.FileMode(int(0600)))
wKey := bufio.NewWriter(keyFile)
_, err = wKey.WriteString(reqData.PrivateKey)
if err != nil {

View File

@ -1,9 +0,0 @@
{
"backend_hostname" : "tlscc.ru",
"api_path" : "api/1.0/",
"login" : "user@test.ru",
"password" : "your_password",
"working_dir" : "/etc/tcibot/private",
"root_cert_file" : "path_to_cert_file",
"debug" : false
}

View File

@ -34,6 +34,13 @@ type stUnauthorized struct {
Message string `json:"message"`
}
type stGenericError struct {
Status string `json:"status"`
StatusCode int `json:"statusCode"`
ErrorDesc string `json:"error"`
Message string `json:"message"`
}
type stErrorResp struct {
StatusCode int `json:"statusCode"`
ErrorDesc string `json:"error"`
@ -212,7 +219,6 @@ defer func() {
res.AuthToken = s.Result.AccessToken
if debugFlag {
fmt.Fprintf(os.Stderr, "Connected (%s)\n", res.Hostname)
fmt.Fprintf(os.Stderr, "%s\n", res.AuthToken)
}
return &res, true
}
@ -227,9 +233,15 @@ defer func() {
fmt.Fprintf(os.Stderr, "\t%s\n\t%s\n\n", s.ErrorDesc, s.Message)
return &res, false
}
case 502:
{
fmt.Fprintf(os.Stderr, "Unexpected response, API is down: HTTP 502 (%s)!\n", res.Hostname)
return &res, false
}
default:
{
fmt.Fprintf(os.Stderr, "Unexpected response (%s)!\n", res.Hostname)
// fmt.Fprintf(os.Stderr, "\n\n%s\n\n", body)
return &res, false
}
}
@ -341,10 +353,21 @@ defer func() {
fmt.Fprintf(os.Stderr, "\t%s\n\t%s\n\n", s.ErrorDesc, s.Message)
return false
}
case 500:
{
s := new(stGenericError)
e := json.Unmarshal([]byte(respBody), s)
if e != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", e.Error())
return false
}
fmt.Fprintf(os.Stderr, "\t%s (%d, %s)\n\t%s\n\n", s.Status, s.StatusCode, s.ErrorDesc, s.Message)
return false
}
default:
{
fmt.Fprintf(os.Stderr, "Unexpected response (%s)!\n", r.Hostname)
fmt.Fprintf(os.Stderr, "\n\n%s\n\n", respBody)
return false
}
}