-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb981a1
commit ab6c65e
Showing
43 changed files
with
837 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.vscode/ | ||
/.tool | ||
/go.sum | ||
/serviced | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
port: 8080 | ||
endpoint: /v1 | ||
webroot: /webroot | ||
mirrors: | ||
file: /mirrors.yaml | ||
firestore: | ||
collection: RudyMirrors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"type": "service_account", | ||
"project_id": "outdoorsafetylab", | ||
"private_key_id": "d53b9674c24ddbbbeef35d31da1b34bc17145695", | ||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDuvV6d1zKdY2Lg\nfG5FgBz7zw2dNZRBxVwzelePwtVhlMwesnmXffwYrPbX0fyNRkn6hs6UVN0KSSfb\nWKykTmc7BQS6U/DXJrVEvMDxIRsV8qIguWTIvNl++1UwnZDMpLh7bGqxNOK9xY22\nL2buk0qAxBGfdS6NMWxIZzFOFqixp7fYO4SNeIFIOr5OfTkwF6iPfb9NRF+nsJ9K\nKuAxicFlP203njJ+9E2Y9H/ayciOY7Rw9+PWuG0ODE1chW4suHZeOuXss7UNiVbA\nq5ygZRGLpIPl6Of3OYE0f5tvzum5EDXmO+r/DcyEDanFp10+5IRiKGEkJO+/hTke\n4NaK+TqhAgMBAAECggEAGdnum2fYhrti0w0WQbdYLBolDr9lAOQ2kipuvdXqlijv\nG2nXCcTuHdvo1MDbuI6CZzretqgj0T/PrYxCEX6d5gGqm+SIATwjR8CqodGkZbGC\nxclddPEiGgJsHJoLOmWhxleci/i+jq8MI8ypOC9B04Snpd0h/874uzRVXe/NL4NU\nrxKTgr/UC0DxgrIChC7C6W9QwiR2a+1XWCixA/IJEkp+/Hg4QSP7rj5n3iLxo+Am\n31cqF46e1xiNUQycPOV92WriI6arkBBOnTLnsrE674tt8UIRJFeswKmfbdz7xvFQ\nEidvsk4C7wi2/8BAlhlYK1IFBulkN/JdY80GZDqgqwKBgQD/X1IqS1BiigogUNAt\neLxoonIp8CO4bWVu5ShQxoubCjQHc72kr4k1/HfI0BEmWg/RRns4doKkbHVgpeBA\n6blFbBla8lmcNvG56hD717tkeXot7QTyIHtNMYDqdA/CGhsmEdlbCRXKXAj7hHqy\nGhtdATYan9Hmr3xSw5CUyBeSMwKBgQDvU5Ved6R0/kIMqUxAUsoxN/slDGv5Q6U9\nAKHpT0k4LrmbhE6gRGXsCyjSE/HoyjkhJD6tsdHzyT0oSUVoXnDjUU3gPOXEr9pz\nmvkJqnQMGSsqfwOCv2Q/uT7voGkBNGQdkzeDZfivay7VBHiAkEVmxeSb3ujPeeQq\nCzbIF5Uz2wKBgHSlJpO5CQOph8yQ/TX38x9cLAdp7/b6yR0pQQv8VKJBu9g3jsUd\nhPAK3O/10g+Rja4Kopf80dmmzMqTmeYsm/rQ0JgRIMtQ8YL5Hj7aoHbZYex+Wgb6\nvTdaSEdPMi932zS9bGm/sZtYBKZWMfEOKbeGqR7qJ2dWetQXDgBXkSSvAoGBAM+p\ndPhNVDP30xPtaq59p9fhPVg+WQomuiAehl9NXrkTQhZBTYAfGVkhrb/rcoKNxdiN\n/Jz2qLiiKyDjwwf2unlkOPCTpsNt211oYSMT9jHxPNVY9JDkxXXNpWCDjdlvvlcz\nQH4RYyHDHRXVFUJo7O9qUx005Eny+BnLNTOV0u71AoGBAMZjIeZXeKJyku8Mn3d7\nteVlRZ9esV3VnYwXs+d2DEslLFwKBIopcN5DvANIejpk6jppgIehA1Dv5C/fVvWw\nNzODws+Lv+nRALszFVDeYV12K04ghTA53flb6KfvNezf3PQgVwYfrFPXR7jtEMiW\nJk63kL5h86cAurcdgn+IawxD\n-----END PRIVATE KEY-----\n", | ||
"client_email": "[email protected]", | ||
"client_id": "117907332197232153525", | ||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firestoredb%40outdoorsafetylab.iam.gserviceaccount.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
log: | ||
dev: true | ||
port: 8080 | ||
endpoint: /v1 | ||
webroot: ./webroot | ||
db: | ||
file: mirrors.yaml | ||
#check: 30s | ||
mirrors: | ||
file: config/mirrors.yaml | ||
firestore: | ||
# project_id: test | ||
project_id: "*detect-project-id*" | ||
credential: config/firestoredb.json | ||
collection: RudyMirrors | ||
statuspage: | ||
key: 9d6e4756-debb-44a7-b6c5-49315faeb4f0 | ||
page: 4fbwbd76cnj2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package controller | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"service/config" | ||
"service/dao" | ||
) | ||
|
||
type AppController struct{} | ||
|
||
func (c *AppController) List(w http.ResponseWriter, r *http.Request) { | ||
dao := &dao.HealthDao{Context: r.Context()} | ||
apps, err := dao.Apps() | ||
if err != nil { | ||
http.Error(w, err.Error(), 500) | ||
return | ||
} | ||
prefix := config.Get().GetString("endpoint") | ||
for _, app := range apps { | ||
for _, v := range app.Variants { | ||
for _, a := range v.Artifacts { | ||
if a.Scheme == "" { | ||
if r.TLS == nil { | ||
a.Scheme = "http:" | ||
} else { | ||
a.Scheme = "https:" | ||
} | ||
} | ||
a.URL = fmt.Sprintf("%s//%s%s/%s", a.Scheme, r.Host, prefix, a.File) | ||
} | ||
} | ||
} | ||
enc := json.NewEncoder(w) | ||
err = enc.Encode(apps) | ||
if err != nil { | ||
http.Error(w, err.Error(), 500) | ||
return | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"net/http" | ||
"service/dao" | ||
"service/model" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type ArtifactController struct { | ||
Artifact *model.Artifact | ||
URI string | ||
} | ||
|
||
func (c *ArtifactController) URL(w http.ResponseWriter, r *http.Request) { | ||
url := fmt.Sprintf("%s//%s%s", c.Artifact.Scheme, r.Host, c.URI) | ||
http.Error(w, url, 200) | ||
} | ||
|
||
func (c *ArtifactController) Download(w http.ResponseWriter, r *http.Request) { | ||
dao := &dao.HealthDao{Context: r.Context()} | ||
urls, err := dao.GetAvailableURLs(c.Artifact) | ||
if err != nil { | ||
http.Error(w, err.Error(), 500) | ||
return | ||
} | ||
if urls == nil || len(urls) <= 0 { | ||
log.Warningf("No available sources: %s (%s)", c.Artifact.File, c.Artifact.File) | ||
http.Error(w, err.Error(), 501) | ||
return | ||
} | ||
u := urls[rand.Intn(len(urls))] | ||
log.Warningf("Redircting: %s (%s) => %s", c.Artifact.File, c.Artifact.File, u.String()) | ||
http.Redirect(w, r, u.String(), 302) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package controller | ||
|
||
import ( | ||
"net/http" | ||
"service/dao" | ||
"service/mirror" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type HealthController struct{} | ||
|
||
func (c *HealthController) Check(w http.ResponseWriter, r *http.Request) { | ||
artifacts, err := mirror.Artifacts() | ||
if err != nil { | ||
http.Error(w, err.Error(), 500) | ||
return | ||
} | ||
client := &http.Client{ | ||
Timeout: 5 * time.Second, | ||
} | ||
for _, a := range artifacts { | ||
log.Debugf("Checking artifact: %s", a.File) | ||
for _, s := range a.Sources { | ||
_ = s.Check(client) | ||
log.Debugf("%s => %s", s.URL.String(), s.Status.String()) | ||
} | ||
} | ||
dao := &dao.HealthDao{Context: r.Context()} | ||
err = dao.Update(artifacts) | ||
if err != nil { | ||
http.Error(w, err.Error(), 500) | ||
return | ||
} | ||
} |
Oops, something went wrong.