-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added full content API coverage, they can be used by running sumocli content <command> * macOS binaries are now signed and notarized (these will soon be available by homebrew) * macOS Apple Silicon binary is now available
- Loading branch information
Showing
11 changed files
with
737 additions
and
21 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 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,69 @@ | ||
package copy_status | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/wizedkyle/sumocli/api" | ||
"github.com/wizedkyle/sumocli/pkg/cmd/factory" | ||
"github.com/wizedkyle/sumocli/pkg/logging" | ||
"io" | ||
) | ||
|
||
func NewCmdCopyStatus() *cobra.Command { | ||
var ( | ||
id string | ||
jobId string | ||
isAdminMode bool | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "copy-status", | ||
Short: "Get the status of the copy request with the given job identifier. On success, field statusMessage will contain identifier of the newly copied content.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
copyStatus(id, jobId, isAdminMode) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&id, "id", "", "Specify the id of the content that was copied") | ||
cmd.Flags().StringVar(&jobId, "jobId", "", "Specify the job id for the import (returned from running sumocli content start-import)") | ||
cmd.Flags().BoolVar(&isAdminMode, "isAdminMode", false, "Set to true if you want to perform the request as a content administrator") | ||
cmd.MarkFlagRequired("id") | ||
cmd.MarkFlagRequired("jobId") | ||
return cmd | ||
} | ||
|
||
func copyStatus(id string, jobId string, isAdminMode bool) { | ||
var copyStatusResponse api.ExportStatusResponse | ||
log := logging.GetConsoleLogger() | ||
requestUrl := "v2/content/" + id + "/copy/" + jobId + "/status" | ||
client, request := factory.NewHttpRequest("GET", requestUrl) | ||
if isAdminMode == true { | ||
request.Header.Add("isAdminMode", "true") | ||
} | ||
response, err := client.Do(request) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to make http request to " + requestUrl) | ||
} | ||
|
||
defer response.Body.Close() | ||
responseBody, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to read response body") | ||
} | ||
|
||
err = json.Unmarshal(responseBody, ©StatusResponse) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to unmarshal response body") | ||
} | ||
|
||
copyStatusJson, err := json.MarshalIndent(copyStatusResponse, "", " ") | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to marshal exportStatusResponse") | ||
} | ||
|
||
if response.StatusCode != 200 { | ||
factory.HttpError(response.StatusCode, responseBody, log) | ||
} else { | ||
fmt.Println(string(copyStatusJson)) | ||
} | ||
} |
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,69 @@ | ||
package deletion_status | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/wizedkyle/sumocli/api" | ||
"github.com/wizedkyle/sumocli/pkg/cmd/factory" | ||
"github.com/wizedkyle/sumocli/pkg/logging" | ||
"io" | ||
) | ||
|
||
func NewCmdDeletionStatus() *cobra.Command { | ||
var ( | ||
id string | ||
jobId string | ||
isAdminMode bool | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "deletion-status", | ||
Short: "Get the status of an asynchronous content deletion job request for the given job identifier.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
deletionStatus(id, jobId, isAdminMode) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&id, "id", "", "Specify the id of the content to delete") | ||
cmd.Flags().StringVar(&jobId, "jobId", "", "Specify the job id for the deletion (returned from running sumocli content start-deletion)") | ||
cmd.Flags().BoolVar(&isAdminMode, "isAdminMode", false, "Set to true if you want to perform the request as a content administrator") | ||
cmd.MarkFlagRequired("contentId") | ||
cmd.MarkFlagRequired("jobId") | ||
return cmd | ||
} | ||
|
||
func deletionStatus(id string, jobId string, isAdminMode bool) { | ||
var deletionStatusResponse api.ExportStatusResponse | ||
log := logging.GetConsoleLogger() | ||
requestUrl := "v2/content/" + id + "/delete/" + jobId + "/status" | ||
client, request := factory.NewHttpRequest("GET", requestUrl) | ||
if isAdminMode == true { | ||
request.Header.Add("isAdminMode", "true") | ||
} | ||
response, err := client.Do(request) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to make http request to " + requestUrl) | ||
} | ||
|
||
defer response.Body.Close() | ||
responseBody, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to read response body") | ||
} | ||
|
||
err = json.Unmarshal(responseBody, &deletionStatusResponse) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to unmarshal response body") | ||
} | ||
|
||
importStatusJson, err := json.MarshalIndent(deletionStatusResponse, "", " ") | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to marshal exportStatusResponse") | ||
} | ||
|
||
if response.StatusCode != 200 { | ||
factory.HttpError(response.StatusCode, responseBody, log) | ||
} else { | ||
fmt.Println(string(importStatusJson)) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ func NewCmdGet() *cobra.Command { | |
getContent(path) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&path, "path", "", "Specify the path of the content you want to retrieve") | ||
cmd.Flags().StringVar(&path, "path", "", "Specify the path of the content you want to retrieve (e.g. /Library/Users/[email protected]/SampleFolder)") | ||
cmd.MarkFlagRequired("path") | ||
return cmd | ||
} | ||
|
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,69 @@ | ||
package import_status | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/wizedkyle/sumocli/api" | ||
"github.com/wizedkyle/sumocli/pkg/cmd/factory" | ||
"github.com/wizedkyle/sumocli/pkg/logging" | ||
"io" | ||
) | ||
|
||
func NewCmdImportStatus() *cobra.Command { | ||
var ( | ||
folderId string | ||
jobId string | ||
isAdminMode bool | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "import-status", | ||
Short: "Get the status of an asynchronous content import request for the given job identifier", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
importStatus(folderId, jobId, isAdminMode) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&folderId, "folderId", "", "Specify the id of the folder to import to") | ||
cmd.Flags().StringVar(&jobId, "jobId", "", "Specify the job id for the import (returned from running sumocli content start-import)") | ||
cmd.Flags().BoolVar(&isAdminMode, "isAdminMode", false, "Set to true if you want to perform the request as a content administrator") | ||
cmd.MarkFlagRequired("folderId") | ||
cmd.MarkFlagRequired("jobId") | ||
return cmd | ||
} | ||
|
||
func importStatus(folderId string, jobId string, isAdminMode bool) { | ||
var importStatusResponse api.ExportStatusResponse | ||
log := logging.GetConsoleLogger() | ||
requestUrl := "v2/content/folders/" + folderId + "/import/" + jobId + "/status" | ||
client, request := factory.NewHttpRequest("GET", requestUrl) | ||
if isAdminMode == true { | ||
request.Header.Add("isAdminMode", "true") | ||
} | ||
response, err := client.Do(request) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to make http request to " + requestUrl) | ||
} | ||
|
||
defer response.Body.Close() | ||
responseBody, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to read response body") | ||
} | ||
|
||
err = json.Unmarshal(responseBody, &importStatusResponse) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to unmarshal response body") | ||
} | ||
|
||
importStatusJson, err := json.MarshalIndent(importStatusResponse, "", " ") | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to marshal exportStatusResponse") | ||
} | ||
|
||
if response.StatusCode != 200 { | ||
factory.HttpError(response.StatusCode, responseBody, log) | ||
} else { | ||
fmt.Println(string(importStatusJson)) | ||
} | ||
} |
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,74 @@ | ||
package move | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"github.com/wizedkyle/sumocli/api" | ||
"github.com/wizedkyle/sumocli/pkg/cmd/factory" | ||
"github.com/wizedkyle/sumocli/pkg/logging" | ||
"io" | ||
"net/url" | ||
) | ||
|
||
func NewCmdMove() *cobra.Command { | ||
var ( | ||
id string | ||
destinationFolderId string | ||
isAdminMode bool | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "move", | ||
Short: "Moves an item from its current location to another folder.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
move(id, destinationFolderId, isAdminMode) | ||
}, | ||
} | ||
cmd.Flags().StringVar(&id, "id", "", "Specify the id of the content to move") | ||
cmd.Flags().StringVar(&destinationFolderId, "destinationFolderId", "", "Specify the destination folder to move the content to") | ||
cmd.Flags().BoolVar(&isAdminMode, "isAdminMode", false, "Set to true if you want to perform the request as a content administrator") | ||
cmd.MarkFlagRequired("id") | ||
cmd.MarkFlagRequired("destinationFolderId") | ||
return cmd | ||
} | ||
|
||
func move(id string, destinationFolderId string, isAdminMode bool) { | ||
var moveResponse api.MoveResponse | ||
log := logging.GetConsoleLogger() | ||
requestUrl := "v2/content/" + id + "/move" | ||
client, request := factory.NewHttpRequest("POST", requestUrl) | ||
if isAdminMode == true { | ||
request.Header.Add("isAdminMode", "true") | ||
} | ||
query := url.Values{} | ||
query.Add("destinationFolderId", destinationFolderId) | ||
request.URL.RawQuery = query.Encode() | ||
response, err := client.Do(request) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to make http request to ") | ||
} | ||
|
||
defer response.Body.Close() | ||
responseBody, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to read response body") | ||
} | ||
|
||
err = json.Unmarshal(responseBody, &moveResponse) | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to unmarshal response body") | ||
} | ||
|
||
moveJson, err := json.MarshalIndent(moveResponse, "", " ") | ||
if err != nil { | ||
log.Error().Err(err).Msg("failed to marshal copyResponse") | ||
} | ||
|
||
if response.StatusCode != 200 { | ||
factory.HttpError(response.StatusCode, responseBody, log) | ||
fmt.Println(string(moveJson)) | ||
} else { | ||
fmt.Println("Content successfully moved.") | ||
} | ||
} |
Oops, something went wrong.