Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
royroyee committed Apr 21, 2024
1 parent 6785523 commit 3c8de02
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
14 changes: 4 additions & 10 deletions api/ftp/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
)

func UploadFile(ac *client.AlpaconClient, src []string, dest, username, groupname string) ([]string, error) {
serverName, remotePath := splitPath(dest)
serverName, remotePath := utils.SplitPath(dest)

serverID, err := server.GetServerIDByName(ac, serverName)
if err != nil {
Expand Down Expand Up @@ -89,7 +89,7 @@ func UploadFile(ac *client.AlpaconClient, src []string, dest, username, groupnam
}

func DownloadFile(ac *client.AlpaconClient, src, dest, username, groupname string) error {
serverName, remotePathStr := splitPath(src)
serverName, remotePathStr := utils.SplitPath(src)

var remotePaths []string

Expand Down Expand Up @@ -120,9 +120,6 @@ func DownloadFile(ac *client.AlpaconClient, src, dest, username, groupname strin
return err
}

maxAttempts := 100
var resp *http.Response

status, err := event.PollCommandExecution(ac, downloadResponse.Command)
if err != nil {
return err
Expand All @@ -136,6 +133,8 @@ func DownloadFile(ac *client.AlpaconClient, src, dest, username, groupname strin
}
utils.CliWarning(fmt.Sprintf("File Transfer Status: '%s'. Attempting to transfer '%s' from the Alpacon server. Note: Transfer may timeout after 100 seconds.", status.Result, path))

maxAttempts := 100
var resp *http.Response
for count := 0; count < maxAttempts; count++ {
resp, err = ac.SendGetRequestForDownload(utils.RemovePrefixBeforeAPI(downloadResponse.DownloadURL))
if err != nil {
Expand Down Expand Up @@ -168,8 +167,3 @@ func DownloadFile(ac *client.AlpaconClient, src, dest, username, groupname strin

return nil
}

func splitPath(path string) (string, string) {
parts := strings.SplitN(path, ":", 2)
return parts[0], parts[1]
}
1 change: 0 additions & 1 deletion api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func GetServerNameByID(ac *client.AlpaconClient, serverID string) (string, error

func CreateServer(ac *client.AlpaconClient, serverRequest ServerRequest) (ServerCreatedResponse, error) {
var response ServerCreatedResponse

responseBody, err := ac.SendPostRequest(serverURL, serverRequest)
if err != nil {
return ServerCreatedResponse{}, err
Expand Down
7 changes: 3 additions & 4 deletions api/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ type ServerAttributes struct {
}

type ServerRequest struct {
Name string `json:"name"`
Platform string `json:"platform"`
// Key string `json:"key"`
Groups []string `json:"groups"`
Name string `json:"name"`
Platform string `json:"platform"`
Groups []string `json:"groups"`
}

type ServerCreatedResponse struct {
Expand Down
5 changes: 5 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,8 @@ func PrettyJSON(data []byte) (*bytes.Buffer, error) {

return &prettyJSON, nil
}

func SplitPath(path string) (string, string) {
parts := strings.SplitN(path, ":", 2)
return parts[0], parts[1]
}

0 comments on commit 3c8de02

Please sign in to comment.