-
Notifications
You must be signed in to change notification settings - Fork 1
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
b52a701
commit fa20f77
Showing
3 changed files
with
63 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# use ubuntu image as base and copy go code | ||
FROM ubuntu | ||
RUN apt update | ||
RUN apt install -y git golang | ||
FROM golang:buster | ||
RUN mkdir /app | ||
COPY ./pkg/ /app/pkg | ||
COPY . /app | ||
WORKDIR /app | ||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
ENV GOARCH=amd64 | ||
RUN go build -o /app/main /app/main.go | ||
CMD ["/bin/bash"] |
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,55 @@ | ||
package actions | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/therealpaulgg/ssh-sync/pkg/dto" | ||
"github.com/therealpaulgg/ssh-sync/pkg/utils" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func ListMachines(c *cli.Context) error { | ||
setup, err := checkIfSetup() | ||
if err != nil { | ||
return err | ||
} | ||
if !setup { | ||
fmt.Fprintln(os.Stderr, "ssh-sync has not been set up on this system. Please set up before continuing.") | ||
return nil | ||
} | ||
profile, err := utils.GetProfile() | ||
if err != nil { | ||
return err | ||
} | ||
url := profile.ServerUrl | ||
url.Path = "/api/v1/machines/" | ||
req, err := http.NewRequest("GET", url.String(), nil) | ||
if err != nil { | ||
return err | ||
} | ||
token, err := utils.GetToken() | ||
if err != nil { | ||
return err | ||
} | ||
req.Header.Set("Authorization", "Bearer "+token) | ||
req.Header.Set("Content-Type", "application/json") | ||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
if resp.StatusCode != http.StatusOK { | ||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode) | ||
} | ||
machines := []dto.MachineDto{} | ||
err = json.NewDecoder(resp.Body).Decode(&machines) | ||
if err != nil { | ||
return err | ||
} | ||
for _, machine := range machines { | ||
fmt.Println(machine.Name) | ||
} | ||
return nil | ||
} |