Initial commit

This commit is contained in:
2021-03-21 23:10:46 +01:00
commit 3144420a47
22 changed files with 2364 additions and 0 deletions

36
cloud/google_firewall.go Normal file
View File

@@ -0,0 +1,36 @@
package gcp
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
)
func getAddress() string {
var c = &http.Client{
Timeout: time.Second * 5,
}
resp, err := c.Get("https://atto.run/ip")
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
return string(body)
}
func (c *ComputeClient) getFirewallRules() error {
a, err := c.Firewalls.Get(c.Project, "morning-mgmt-to-backend").Do()
if err != nil {
return err
}
b := getAddress()
for _, r := range a.SourceRanges {
if strings.HasPrefix(r, b) {
fmt.Println(r)
}
}
return nil
}