Skip to content

Commit

Permalink
fix(Dojo-fixes): Fixed some insecure configurations in the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
dfradehubs committed Sep 27, 2024
1 parent f2b034f commit bbfaf31
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
15 changes: 12 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func main() {
log.Printf("MIG %s scaled up to its minimum size %d", migName, minSize)
if slackWebhookURL != "" {
message := fmt.Sprintf("MIG %s scaled up to its minimum size %d", migName, minSize)
slack.NotifySlack(message, slackWebhookURL)
err = slack.NotifySlack(message, slackWebhookURL)
if err != nil {
log.Printf("Error sending Slack notification: %v", err)
}
}
time.Sleep(time.Duration(defaultcooldownPeriodSeconds) * time.Second)
continue
Expand Down Expand Up @@ -99,7 +102,10 @@ func main() {
// Notify via Slack that a node has been added
if slackWebhookURL != "" {
message := fmt.Sprintf("Added new node to MIG %s. Current size is %d nodes and the maximum nodes to create are %d", migName, currentSize, maxSize)
slack.NotifySlack(message, slackWebhookURL)
err = slack.NotifySlack(message, slackWebhookURL)
if err != nil {
log.Printf("Error sending Slack notification: %v", err)
}
}
// Sleep for the default cooldown period before checking the conditions again
time.Sleep(time.Duration(defaultcooldownPeriodSeconds) * time.Second)
Expand All @@ -114,7 +120,10 @@ func main() {
// Notify via Slack that a node has been removed
if slackWebhookURL != "" {
message := fmt.Sprintf("Removed node %s from MIG %s. Current size is %d nodes and the minimum nodes to exist are %d", nodeRemoved, migName, currentSize, minSize)
slack.NotifySlack(message, slackWebhookURL)
err = slack.NotifySlack(message, slackWebhookURL)
if err != nil {
log.Printf("Error sending Slack notification: %v", err)
}
}
// Sleep for the scaledown cooldown period before checking the conditions again
time.Sleep(time.Duration(scaledowncooldownPeriodSeconds) * time.Second)
Expand Down
1 change: 1 addition & 0 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
read_only: true
ports:
- "9090:9090"

Expand Down
4 changes: 2 additions & 2 deletions internal/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func DrainElasticsearchNode(elasticURL, nodeName, username, password string) err
var tr http.RoundTripper
if insecureSkipVerify == "true" {
tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{InsecureSkipVerify: true, MinVersion: tls.VersionTLS13},
}
} else {
tr = http.DefaultTransport
Expand Down Expand Up @@ -225,7 +225,7 @@ func ClearElasticsearchClusterSettings(elasticURL, username, password string) er
var tr http.RoundTripper
if insecureSkipVerify == "true" {
tr = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
TLSClientConfig: &tls.Config{InsecureSkipVerify: true, MinVersion: tls.VersionTLS13},
}
} else {
tr = http.DefaultTransport
Expand Down
11 changes: 9 additions & 2 deletions internal/google/mig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package google

import (
"context"
"crypto/rand"
"fmt"
"log"
"math/rand"
"math/big"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -201,7 +202,13 @@ func GetInstanceToRemove(ctx context.Context, client *compute.InstanceGroupManag
}

// Randomly select an instance to remove
return getInstanceNameFromURL(instanceNames[rand.Intn(len(instanceNames))]), nil
randomIndex, err := rand.Int(rand.Reader, big.NewInt(int64(len(instanceNames))))
if err != nil {
return "", fmt.Errorf("error selecting random instance: %v", err)
}
randomInstance := int(randomIndex.Int64())

return getInstanceNameFromURL(instanceNames[randomInstance]), nil
}

// getMIGInstanceNames retrieves the list of instance names in a Managed Instance Group (MIG).
Expand Down

0 comments on commit bbfaf31

Please sign in to comment.