2023-03-07 20:31:39 +01:00
|
|
|
package zrokEdgeSdk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/x509"
|
2023-05-25 17:50:38 +02:00
|
|
|
"github.com/openziti/edge-api/rest_management_api_client"
|
|
|
|
"github.com/openziti/edge-api/rest_util"
|
2023-03-07 20:31:39 +01:00
|
|
|
)
|
|
|
|
|
2023-03-10 20:25:29 +01:00
|
|
|
type Config struct {
|
2023-03-07 20:31:39 +01:00
|
|
|
ApiEndpoint string
|
|
|
|
Username string
|
|
|
|
Password string `cf:"+secret"`
|
|
|
|
}
|
|
|
|
|
2023-03-10 20:25:29 +01:00
|
|
|
func Client(cfg *Config) (*rest_management_api_client.ZitiEdgeManagement, error) {
|
2023-03-07 20:31:39 +01:00
|
|
|
caCerts, err := rest_util.GetControllerWellKnownCas(cfg.ApiEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
caPool := x509.NewCertPool()
|
|
|
|
for _, ca := range caCerts {
|
|
|
|
caPool.AddCert(ca)
|
|
|
|
}
|
|
|
|
return rest_util.NewEdgeManagementClientWithUpdb(cfg.Username, cfg.Password, cfg.ApiEndpoint, caPool)
|
|
|
|
}
|