netbox-community / go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Other
195 stars 146 forks source link

Non trusted certificate failure #69

Closed pezhore closed 3 years ago

pezhore commented 4 years ago

On my MacBook Pro, when running the example custom host go code, I get an error apparently due to certificate trust issues.

Get "https://netbox.cyber.range/api/dcim/racks/": x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "cyber.range")

Is there a way to ignore ssl verification?

vx3r commented 4 years ago

I have the same issue and found a way to pass custom http.client:

    // ignore expired / self signed SSL certificates
    httpClient := &http.Client{
        Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
    }

    transport := httptransport.NewWithClient(os.Getenv("NETBOX_HOST"), client.DefaultBasePath, []string{"https"}, httpClient)
    transport.DefaultAuthentication = httptransport.APIKeyAuth("Authorization", "header", "Token " + os.Getenv("NETBOX_API_KEY"))

    c := client.New(transport, nil)

    req := dcim.NewDcimSitesListParams()
    res, err := c.Dcim.DcimSitesList(req, nil)
    if err != nil {
        log.Fatalf("Cannot get sites list: %v", err)
    }
    log.Infof("res: %v", res)