Skip to content

Commit d7d73c1

Browse files
authored
Add binary script (#45)
* adding python script to download oauth2l binary * moving python script to api * deleting duplicate python script * adding setup to test files and backend to download binaries * fixing tests * updating gitignore to ignore the installed binaries * fixing gitignore * fixing gitignore * fixing gitignore * fixing gitignore * fixing gitignore * fixing gitignore * adding spaces between operators in python script * removing binaries file
1 parent c82486a commit d7d73c1

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ npm-debug.log*
3030
TODOS.txt
3131

3232
# api
33-
./web/api/.env
33+
./api/.env
34+
35+
# binaries
36+
api/binaries/
37+
api/binaries/oauth2l

api/backend.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"log"
77
"net/http"
8+
"os/exec"
89
"reflect"
910
"strings"
1011
"time"
@@ -266,7 +267,17 @@ func CredentialsTokenHandler(w http.ResponseWriter, r *http.Request) {
266267
json.NewEncoder(w).Encode(responseBody)
267268
}
268269

270+
func getBinaries() {
271+
cmd := exec.Command("python3", "get_binaries.py")
272+
err := cmd.Run()
273+
if err != nil {
274+
log.Fatalf("error: %v", err)
275+
return
276+
}
277+
}
278+
269279
func main() {
280+
getBinaries()
270281
router := mux.NewRouter()
271282
log.Println("Authorization Playground")
272283
router.HandleFunc("/api", Handler)

api/backend_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ import (
55
"encoding/json"
66
"net/http"
77
"net/http/httptest"
8+
"os"
9+
"os/exec"
810
"reflect"
911
"strings"
1012
"testing"
1113
)
1214

15+
func TestMain(m *testing.M) {
16+
cmd := exec.Command("python3", "get_binaries.py")
17+
err := cmd.Run()
18+
if err != nil {
19+
os.Exit(1)
20+
}
21+
os.Exit(m.Run())
22+
23+
}
24+
1325
func TestHandlerAuthenticateCredentialsTokenValid(t *testing.T) {
1426
jsonStr := []byte(`{
1527
"commandtype":"fetch",

api/binaries/oauth2l

-9.07 MB
Binary file not shown.

api/get_binaries.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import platform
5+
6+
def main():
7+
binaryURL = ""
8+
if platform.system() == "Linux":
9+
binaryURL = "https://storage.googleapis.com/oauth2l/latest/linux_amd64.tgz"
10+
elif platform.system() == "Darwin":
11+
binaryURL = "https://storage.googleapis.com/oauth2l/latest/darwin_amd64.tgz"
12+
elif platform.system() == "Windows":
13+
binaryURL = "https://storage.googleapis.com/oauth2l/latest/windows_amd64.tgz"
14+
else:
15+
print("Platform not supported.")
16+
return
17+
18+
os.system("mkdir binaries| wget " + binaryURL + " -O - | tar -xz -C binaries --strip-components=1")
19+
20+
if __name__ == '__main__':
21+
main()

0 commit comments

Comments
 (0)