aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan DeMasi <jon.demasi@colorado.edu>2019-06-05 11:09:07 -0600
committerJonathan DeMasi <jon.demasi@colorado.edu>2019-06-05 11:09:07 -0600
commitbbfc6effdca3f7d620ca706a80197e681b28f9c2 (patch)
treef69e6c057f41b1575233ac6a34633f4d3f7270c8
downloadgh_authkey_checker-bbfc6effdca3f7d620ca706a80197e681b28f9c2.tar
gh_authkey_checker-bbfc6effdca3f7d620ca706a80197e681b28f9c2.tar.gz
gh_authkey_checker-bbfc6effdca3f7d620ca706a80197e681b28f9c2.tar.bz2
gh_authkey_checker-bbfc6effdca3f7d620ca706a80197e681b28f9c2.tar.lz
gh_authkey_checker-bbfc6effdca3f7d620ca706a80197e681b28f9c2.tar.xz
gh_authkey_checker-bbfc6effdca3f7d620ca706a80197e681b28f9c2.tar.zst
gh_authkey_checker-bbfc6effdca3f7d620ca706a80197e681b28f9c2.zip
init
-rw-r--r--.gitignore12
-rw-r--r--main.go69
2 files changed, 81 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f1c181e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,12 @@
+# Binaries for programs and plugins
+*.exe
+*.exe~
+*.dll
+*.so
+*.dylib
+
+# Test binary, build with `go test -c`
+*.test
+
+# Output of the go coverage tool, specifically when used with LiteIDE
+*.out
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..3ebcb97
--- /dev/null
+++ b/main.go
@@ -0,0 +1,69 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "net"
+ "os"
+ "net/http"
+ "io/ioutil"
+)
+
+func parseArgs() string {
+ // Check for at least one arg, bail if none
+ if len(os.Args) < 2 {
+ log.Fatalln("You must provide exactly one GitHub username.")
+ }
+
+ // We have one arg possible comma separated
+ if len(os.Args) == 2 {
+ return(os.Args[1])
+ } else {
+ log.Fatalln("You have provided too many arguments")
+ }
+ return("")
+}
+
+func fetchKeys(username string) string {
+ log.Printf("Fetching keys for user %s", username)
+
+ url := fmt.Sprintf("https://github.com/%s.keys", username)
+ resp, err := http.Get(url)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ defer resp.Body.Close()
+
+ if resp.StatusCode == http.StatusOK {
+ bodyBytes, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ log.Fatal(err)
+ }
+ bodyString := string(bodyBytes)
+ return(bodyString)
+ }
+ return("")
+}
+
+// Need to fix this to not be an infinite loop
+func checkResolvers() {
+ for {
+ _, err := net.LookupIP("github.com")
+ if err != nil {
+ log.Println("No DNS yet...")
+ } else {
+ break
+ }
+ }
+ return
+}
+
+func main() {
+ username := parseArgs()
+ checkResolvers()
+ //fmt.Println(username)
+ keys := fetchKeys(username)
+ fmt.Print(keys)
+ return
+}