/** * Yats - yats * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli * @copyright Paolo Lulli 2024 */ package client import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os" "time" ) func (c *YatsClient) PkiPostCsr(endpoint string, certRequest CertificateRequest) []byte { client := http.Client{ Timeout: 30 * time.Second, } body, err := json.Marshal(certRequest) //fmt.Printf("body: -> %s\n", body) req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(body)) req.Header.Set("Content-Type", "application/json; charset=UTF-8") if err != nil { fmt.Println("Unable to make POST request", err) os.Exit(1) } req.Header.Add("Accept", "*/*") resp, err := client.Do(req) if err != nil { fmt.Println(err) os.Exit(1) } defer resp.Body.Close() data, _ := io.ReadAll(resp.Body) return data } type CertificateRequest struct { ClientCn string `json:"clientCn"` Csr string `json:"csr"` SecretPin string `json:"pin"` } type CertificateResponse struct { Base64Certificate string `json:"base64cert"` }