Skip to content

Commit

Permalink
Fixed a tonne of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharpz7 committed Nov 4, 2021
1 parent a3680bd commit 9698ae0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=3
VERSION=3.1
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ tasks:
On linux, just run:
```console
╭─adam@box ~/
╰─➤ sudo curl -s -L https://github.com/Sharpz7/sharpcd/releases/download/3/install.sh | sudo bash
╰─➤ sudo curl -s -L https://github.com/Sharpz7/sharpcd/releases/download/3.1/install.sh | sudo bash
```

Or for just the client:
```console
╭─adam@box ~/
╰─➤ sudo curl -s -L https://github.com/Sharpz7/sharpcd/releases/download/3.1/install.sh | sudo bash -s client
```

## Command Options
Expand Down
3 changes: 2 additions & 1 deletion src/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func client() {
var err error
var file []byte

if len(secretFlag) == 0 {
if len(secretFlag) != 0 {
resp, err := http.Get(secretFlag)
handle(err, "Failed to download remote sharpcd.yml")
defer resp.Body.Close()
Expand Down Expand Up @@ -101,6 +101,7 @@ func post(payload postData, url string) (response, int) {
InsecureSkipVerify: true,
},
},
Timeout: 5 * time.Second,
}

// Do Request
Expand Down
8 changes: 4 additions & 4 deletions src/errors.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package main

import (
"flag"
"fmt"
"log"
"os"

ui "github.com/gizak/termui"
"github.com/joho/godotenv"
)

Expand All @@ -19,8 +18,9 @@ func handle(e error, msg string) {
if os.Getenv("DEV") == "TRUE" {
fmt.Println(e)
}
log.Fatal(msg)
flag.Usage()
ui.Close()
fmt.Print(msg)
os.Exit(1)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/gorilla/websocket"
)

var sharpCDVersion = "3"
var sharpCDVersion = "3.1"

type statusCodes struct {
NotPostMethod int
Expand Down
47 changes: 37 additions & 10 deletions src/trak.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ import (

var tablePadding int = 2

var forceEnd = make(chan int)

func trak() {

if len(flag.Args()) < 2 {
handle(errors.New(""), "No valid trak arg was given")
flag.Usage()
}

var trakArg = flag.Args()[1]

switch trakArg {
Expand All @@ -43,6 +50,11 @@ func trak() {

// Lists all jobs running on server
func listJobs() {
if len(flag.Args()) < 3 {
handle(errors.New(""), "No valid location was given")
flag.Usage()
}

var location = flag.Args()[2]

var jobIDs []string
Expand All @@ -55,7 +67,10 @@ func listJobs() {

urlJobs := con.Trak[location] + "/api/jobs/"

apiOutput, _ := getAPIOutput(urlJobs)
// Insert needed data
secret := getSec()

apiOutput, _ := getAPIOutput(urlJobs, secret)
jobs := apiOutput.Jobs

for _, job := range jobs {
Expand All @@ -77,6 +92,11 @@ func liveFeed() {
var trakAll string = "alljobs"
var trakOne string = "job"

if len(flag.Args()) < 3 {
handle(errors.New(""), "No valid location was given")
flag.Usage()
}

var trakArg = flag.Args()[1]
var location = flag.Args()[2]

Expand All @@ -90,14 +110,22 @@ func liveFeed() {

// Only needed for single job requests
if trakArg == trakOne {
if len(flag.Args()) < 3 {
handle(errors.New(""), "No valid Job ID was given")
flag.Usage()
}

var jobID = flag.Args()[3]

urlJob = con.Trak[location] + "/api/job/" + jobID
urlLog = con.Trak[location] + "/api/logsfeed/" + jobID
}

// Insert needed data
secret := getSec()

// Tests to ensure you can actually reach the server
apiOutput, code := getAPIOutput(urlJobs)
apiOutput, code := getAPIOutput(urlJobs, secret)

if code == statCode.Accepted {
fmt.Printf("Connection to API...")
Expand All @@ -121,15 +149,15 @@ func liveFeed() {

// Gets all rows if there is one job
if trakArg == trakOne {
apiOutput, _ := getAPIOutput(urlJob)
apiOutput, _ := getAPIOutput(urlJob, secret)
job := apiOutput.Job

jobs = append(jobs, job)
}

// Gets all rows if there is there are multiple jobs
if trakArg == trakAll {
apiOutput, _ = getAPIOutput(urlJobs)
apiOutput, _ = getAPIOutput(urlJobs, secret)
jobs = apiOutput.Jobs
}

Expand Down Expand Up @@ -166,7 +194,7 @@ func liveFeed() {
var trakLogs *widgets.Paragraph

if trakArg == trakOne {
trakLogs, heightLogs = logging(width, heightTable, urlLog)
trakLogs, heightLogs = logging(width, heightTable, urlLog, secret)
ui.Render(trakLogs)
} else {
heightLogs = heightTable
Expand All @@ -191,6 +219,7 @@ func liveFeed() {
}
case <-ticker:
draw()

}
}

Expand Down Expand Up @@ -273,8 +302,8 @@ func closing(width int, tablePadding int, heightLogs int) *widgets.Paragraph {
}

// Creates the logging page
func logging(width int, heightTable int, urlLog string) (*widgets.Paragraph, int) {
logs, _ := getAPIOutput(urlLog)
func logging(width int, heightTable int, urlLog string, secret string) (*widgets.Paragraph, int) {
logs, _ := getAPIOutput(urlLog, secret)
msg := logs.Message

deltaYLogs := heightTable
Expand Down Expand Up @@ -329,10 +358,8 @@ func generateColumnWidths(rows [][]string, columns []string) []int {
return columnWidths
}

func getAPIOutput(url string) (response, int) {
func getAPIOutput(url string, secret string) (response, int) {

// Insert needed data
secret := getSec()
trakPayload := trakPostData{
Secret: secret,
Version: sharpCDVersion,
Expand Down

0 comments on commit 9698ae0

Please sign in to comment.