mirror of
https://github.com/cert-manager/webhook-example.git
synced 2025-07-03 07:05:50 +02:00
add description for functions
This commit is contained in:
parent
409e6cd1bb
commit
4753e58c17
1 changed files with 25 additions and 14 deletions
|
@ -30,9 +30,11 @@ var baseURL string
|
||||||
var token string
|
var token string
|
||||||
var configName string
|
var configName string
|
||||||
|
|
||||||
|
// bluecatLogin to be able to talk to the bluecat API, you must login to generate a bluecat API token
|
||||||
func bluecatLogin(bluecatURL, username, password string, bluecatConfigName string) error {
|
func bluecatLogin(bluecatURL, username, password string, bluecatConfigName string) error {
|
||||||
baseURL = bluecatURL
|
baseURL = bluecatURL
|
||||||
configName = bluecatConfigName
|
configName = bluecatConfigName
|
||||||
|
|
||||||
queryArgs := map[string]string{
|
queryArgs := map[string]string{
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": password,
|
"password": password,
|
||||||
|
@ -59,6 +61,7 @@ func bluecatLogin(bluecatURL, username, password string, bluecatConfigName strin
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bluecatLogout logout to invoke bluecat API token
|
||||||
func bluecatLogout() error {
|
func bluecatLogout() error {
|
||||||
if len(token) == 0 {
|
if len(token) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -90,6 +93,7 @@ func bluecatLogout() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bluecatLookupConfID search configuration by id
|
||||||
func bluecatLookupConfID() (uint, error) {
|
func bluecatLookupConfID() (uint, error) {
|
||||||
queryArgs := map[string]string{
|
queryArgs := map[string]string{
|
||||||
"parentId": strconv.Itoa(0),
|
"parentId": strconv.Itoa(0),
|
||||||
|
@ -106,11 +110,12 @@ func bluecatLookupConfID() (uint, error) {
|
||||||
var conf entityResponse
|
var conf entityResponse
|
||||||
err = json.NewDecoder(resp.Body).Decode(&conf)
|
err = json.NewDecoder(resp.Body).Decode(&conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("bluecat: %w", err)
|
return 0, fmt.Errorf("bluecat: cannot get entity by name. %w", err)
|
||||||
}
|
}
|
||||||
return conf.ID, nil
|
return conf.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bluecatLookupViewID search view by name
|
||||||
func bluecatLookupViewID(viewName string) (uint, error) {
|
func bluecatLookupViewID(viewName string) (uint, error) {
|
||||||
confID, err := bluecatLookupConfID()
|
confID, err := bluecatLookupConfID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -138,11 +143,15 @@ func bluecatLookupViewID(viewName string) (uint, error) {
|
||||||
return view.ID, nil
|
return view.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bluecatLookupParentZoneID search parent zone id
|
||||||
func bluecatLookupParentZoneID(viewID uint, fqdn string) (uint, string, error) {
|
func bluecatLookupParentZoneID(viewID uint, fqdn string) (uint, string, error) {
|
||||||
parentViewID := viewID
|
parentViewID := viewID
|
||||||
name := ""
|
name := ""
|
||||||
|
|
||||||
if fqdn != "" {
|
if fqdn == "" {
|
||||||
|
return parentViewID, name, nil
|
||||||
|
}
|
||||||
|
|
||||||
zones := strings.Split(strings.Trim(fqdn, "."), ".")
|
zones := strings.Split(strings.Trim(fqdn, "."), ".")
|
||||||
last := len(zones) - 1
|
last := len(zones) - 1
|
||||||
name = zones[0]
|
name = zones[0]
|
||||||
|
@ -157,11 +166,11 @@ func bluecatLookupParentZoneID(viewID uint, fqdn string) (uint, string, error) {
|
||||||
}
|
}
|
||||||
parentViewID = zoneID
|
parentViewID = zoneID
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return parentViewID, name, nil
|
return parentViewID, name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bluecatGetZone search zone by name
|
||||||
func bluecatGetZone(parentID uint, name string) (uint, error) {
|
func bluecatGetZone(parentID uint, name string) (uint, error) {
|
||||||
queryArgs := map[string]string{
|
queryArgs := map[string]string{
|
||||||
"parentId": strconv.FormatUint(uint64(parentID), 10),
|
"parentId": strconv.FormatUint(uint64(parentID), 10),
|
||||||
|
@ -189,6 +198,7 @@ func bluecatGetZone(parentID uint, name string) (uint, error) {
|
||||||
return zone.ID, nil
|
return zone.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bluecatDeploy
|
||||||
func bluecatDeploy(entityID uint) error {
|
func bluecatDeploy(entityID uint) error {
|
||||||
queryArgs := map[string]string{
|
queryArgs := map[string]string{
|
||||||
"entityId": strconv.FormatUint(uint64(entityID), 10),
|
"entityId": strconv.FormatUint(uint64(entityID), 10),
|
||||||
|
@ -203,6 +213,7 @@ func bluecatDeploy(entityID uint) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bluecatSendRequest send a API request to bluecat
|
||||||
func bluecatSendRequest(method, resource string, payload interface{}, queryArgs map[string]string) (*http.Response, error) {
|
func bluecatSendRequest(method, resource string, payload interface{}, queryArgs map[string]string) (*http.Response, error) {
|
||||||
url := fmt.Sprintf("%s/Services/REST/v1/%s", baseURL, resource)
|
url := fmt.Sprintf("%s/Services/REST/v1/%s", baseURL, resource)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue