Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Node Deactivated Timestamp Instead of HTTP 200 #5

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -241,15 +242,30 @@ func puppetNodeExists(client *http.Client, event *types.Event) (bool, error) {
endpoint := strings.TrimRight(handler.endpoint, "/")
endpoint = fmt.Sprintf("%s/%s", endpoint, name)
resp, err := client.Get(endpoint)
body, err := ioutil.ReadAll(resp.Body)
payload := string(body)
var info map[string]interface{}
json.Unmarshal([]byte(payload), &info)
nodeInfo := make(map[string]interface{})
errs := json.Unmarshal([]byte(payload), &nodeInfo)
if errs != nil {
panic(err)
}
timeDeactivated := nodeInfo["deactivated"]

if err != nil {
return false, err
}
_ = resp.Body.Close()

// Determine if the node exists
if resp.StatusCode == http.StatusOK {
log.Printf("puppet node %q exists", name)
return true, nil
log.Printf("puppet node %q exists, checking if deactivated", name)
if timeDeactivated != nil {
return false, nil
} else {
return true, nil
}
} else if resp.StatusCode == http.StatusNotFound {
log.Printf("puppet node %q does not exist", name)
return false, nil
Expand Down