Skip to content

Commit

Permalink
v0.4.0 (#58)
Browse files Browse the repository at this point in the history
* 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
wizedkyle authored Apr 12, 2021
1 parent d24e2bc commit 5d8f4c9
Show file tree
Hide file tree
Showing 11 changed files with 737 additions and 21 deletions.
32 changes: 21 additions & 11 deletions api/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ type GetPathResponse struct {
Path string `json:"path"`
}

type LookupTableSyncDefinition struct {
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Fields []fields `json:"fields"`
PrimaryKeys []string `json:"primaryKeys"`
TTL int `json:"ttl"`
SizeLimitAction string `json:"sizeLimitAction"`
}

type MetricsSavedSearchSyncDefinition struct {
Type string `json:"type"`
Name string `json:"name"`
Expand All @@ -53,16 +63,6 @@ type MetricsSearchSyncDefinition struct {
VisualSettings string `json:"visualSettings"`
}

type LookupTableSyncDefinition struct {
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Fields []fields `json:"fields"`
PrimaryKeys []string `json:"primaryKeys"`
TTL int `json:"ttl"`
SizeLimitAction string `json:"sizeLimitAction"`
}

type MewboardSyncDefinition struct {
Type string `json:"type"`
Name string `json:"name"`
Expand All @@ -79,6 +79,11 @@ type MewboardSyncDefinition struct {
ColoringRules coloringRulesDefinition `json:"coloringRules"`
}

type MoveResponse struct {
Id string `json:"id"`
Errors []moveErrors `json:"errors"`
}

type ResponseType struct {
Type string `json:"type"`
}
Expand Down Expand Up @@ -172,6 +177,11 @@ type metricsQueriesDefinition struct {
RowId string `json:"rowId"`
}

type moveErrors struct {
Code string `json:"code"`
Message string `json:"message"`
}

type panelsDefinition struct {
Id string `json:"id"`
Key string `json:"key"`
Expand Down Expand Up @@ -217,7 +227,7 @@ type reportPanelSyncDefinition struct {
MetricsQueries []metricsQueriesDefinition `json:"metricsQueries"`
TimeRange timeRangeDefinition `json:"timeRange"`
X int `json:"x"`
Y int `json:"Y"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
Properties string `json:"properties"`
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ package content

import (
"github.com/spf13/cobra"
cmdContentCopyStatus "github.com/wizedkyle/sumocli/pkg/cmd/content/copy-status"
cmdContentDeletionStatus "github.com/wizedkyle/sumocli/pkg/cmd/content/deletion-status"
cmdContentExportResult "github.com/wizedkyle/sumocli/pkg/cmd/content/export-result"
cmdContentExportStatus "github.com/wizedkyle/sumocli/pkg/cmd/content/export-status"
cmdContentGet "github.com/wizedkyle/sumocli/pkg/cmd/content/get"
cmdContentGetPath "github.com/wizedkyle/sumocli/pkg/cmd/content/get-path"
cmdContentImportStatus "github.com/wizedkyle/sumocli/pkg/cmd/content/import-status"
cmdContentMove "github.com/wizedkyle/sumocli/pkg/cmd/content/move"
cmdContentStartCopy "github.com/wizedkyle/sumocli/pkg/cmd/content/start-copy"
cmdContentStartDeletion "github.com/wizedkyle/sumocli/pkg/cmd/content/start-deletion"
cmdContentStartExport "github.com/wizedkyle/sumocli/pkg/cmd/content/start-export"
cmdContentStartImport "github.com/wizedkyle/sumocli/pkg/cmd/content/start-import"
)

func NewCmdContent() *cobra.Command {
Expand All @@ -15,10 +22,17 @@ func NewCmdContent() *cobra.Command {
Short: "Manage content",
Long: "Commands that allow you to manage content in your Sumo Logic tenant",
}
cmd.AddCommand(cmdContentCopyStatus.NewCmdCopyStatus())
cmd.AddCommand(cmdContentDeletionStatus.NewCmdDeletionStatus())
cmd.AddCommand(cmdContentExportResult.NewCmdExportResult())
cmd.AddCommand(cmdContentExportStatus.NewCmdExportStatus())
cmd.AddCommand(cmdContentGet.NewCmdGet())
cmd.AddCommand(cmdContentGetPath.NewCmdGetPath())
cmd.AddCommand(cmdContentImportStatus.NewCmdImportStatus())
cmd.AddCommand(cmdContentMove.NewCmdMove())
cmd.AddCommand(cmdContentStartDeletion.NewCmdStartDeletion())
cmd.AddCommand(cmdContentStartCopy.NewCmdStartCopy())
cmd.AddCommand(cmdContentStartExport.NewCmdStartExport())
cmd.AddCommand(cmdContentStartImport.NewCmdStartImport())
return cmd
}
69 changes: 69 additions & 0 deletions pkg/cmd/content/copy-status/copy-status.go
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, &copyStatusResponse)
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))
}
}
69 changes: 69 additions & 0 deletions pkg/cmd/content/deletion-status/deletion-status.go
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))
}
}
2 changes: 1 addition & 1 deletion pkg/cmd/content/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
69 changes: 69 additions & 0 deletions pkg/cmd/content/import-status/import-status.go
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))
}
}
74 changes: 74 additions & 0 deletions pkg/cmd/content/move/move.go
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.")
}
}
Loading

0 comments on commit 5d8f4c9

Please sign in to comment.