diff --git a/README b/README index 39aa081..bca7d7b 100644 --- a/README +++ b/README @@ -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 } Вызов diff --git a/cmd/main.go b/cmd/main.go index 4a7c71a..d4b41b3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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 { diff --git a/config.conf b/config.conf deleted file mode 100644 index c772ece..0000000 --- a/config.conf +++ /dev/null @@ -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 -} diff --git a/tciapi/tciapi.go b/tciapi/tciapi.go index 888b247..d88a5b2 100644 --- a/tciapi/tciapi.go +++ b/tciapi/tciapi.go @@ -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 } }