-
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.
- Loading branch information
Showing
8 changed files
with
174 additions
and
1 deletion.
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
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,71 @@ | ||
package change | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/rs/zerolog" | ||
"github.com/spf13/cobra" | ||
"github.com/wizedkyle/sumocli/api" | ||
"github.com/wizedkyle/sumocli/pkg/cmd/factory" | ||
"github.com/wizedkyle/sumocli/pkg/logging" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func NewCmdUserChangeEmail() *cobra.Command { | ||
var ( | ||
id string | ||
email string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "change email", | ||
Short: "Changes the email address of a Sumo Logic user.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger := logging.GetLoggerForCommand(cmd) | ||
logger.Debug().Msg("User change email request started.") | ||
userChangeEmail(id, email, logger) | ||
logger.Debug().Msg("User change email request finished.") | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&id, "id", "", "Specify the id of the user that needs to have the email changed.") | ||
cmd.Flags().StringVar(&email, "email", "", "Specify the users new email address.") | ||
|
||
return cmd | ||
} | ||
|
||
func userChangeEmail(id string, email string, logger zerolog.Logger) { | ||
if id == "" { | ||
fmt.Println("--id field needs to be set.") | ||
os.Exit(0) | ||
} | ||
if email == "" { | ||
fmt.Println("--email field needs to be set.") | ||
os.Exit(0) | ||
} | ||
|
||
requestBodySchema := &api.UpdateUserEmail{ | ||
Email: email, | ||
} | ||
requestBody, _ := json.Marshal(requestBodySchema) | ||
requestUrl := "v1/users/" + id + "/email/requestChange" | ||
client, request := factory.NewHttpRequestWithBody("POST", requestUrl, requestBody) | ||
response, err := client.Do(request) | ||
logging.LogError(err, logger) | ||
|
||
defer response.Body.Close() | ||
responseBody, err := ioutil.ReadAll(response.Body) | ||
logging.LogError(err, logger) | ||
|
||
if response.StatusCode != 204 { | ||
var responseError api.ResponseError | ||
jsonErr := json.Unmarshal(responseBody, &responseError) | ||
logging.LogError(jsonErr, logger) | ||
if responseError.Errors[0].Code == "um1:unverified_email" { | ||
fmt.Println(responseError.Errors[0].Message) | ||
} | ||
} else { | ||
fmt.Println("Users email address successfully updated to: " + email) | ||
} | ||
} |
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,60 @@ | ||
package delete | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/rs/zerolog" | ||
"github.com/spf13/cobra" | ||
"github.com/wizedkyle/sumocli/api" | ||
"github.com/wizedkyle/sumocli/pkg/cmd/factory" | ||
"github.com/wizedkyle/sumocli/pkg/logging" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func NewCmdUserDelete() *cobra.Command { | ||
var ( | ||
id string | ||
transferTo string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
Short: "Deletes a Sumo Logic user", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger := logging.GetLoggerForCommand(cmd) | ||
logger.Debug().Msg("User delete request started.") | ||
deleteUser(id, transferTo, logger) | ||
logger.Debug().Msg("User delete request finished.") | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&id, "id", "", "Specify the id of the user to delete.") | ||
cmd.Flags().StringVar(&transferTo, "transferto", "", "Specify the id of the user to transfer data to.") | ||
|
||
return cmd | ||
} | ||
|
||
func deleteUser(id string, transferTo string, logger zerolog.Logger) { | ||
if id == "" { | ||
fmt.Println("--id field needs to be set.") | ||
os.Exit(0) | ||
} | ||
|
||
requestUrl := "v1/users/" + id | ||
client, request := factory.NewHttpRequest("DELETE", requestUrl) | ||
response, err := client.Do(request) | ||
logging.LogError(err, logger) | ||
|
||
defer response.Body.Close() | ||
responseBody, err := ioutil.ReadAll(response.Body) | ||
logging.LogError(err, logger) | ||
|
||
if response.StatusCode != 204 { | ||
var responseError api.ResponseError | ||
jsonErr := json.Unmarshal(responseBody, &responseError) | ||
logging.LogError(jsonErr, logger) | ||
} else { | ||
fmt.Println("User was deleted.") | ||
} | ||
} |
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,32 @@ | ||
package disable | ||
|
||
import ( | ||
"github.com/rs/zerolog" | ||
"github.com/spf13/cobra" | ||
"github.com/wizedkyle/sumocli/pkg/logging" | ||
) | ||
|
||
func NewCmdUserDisableMFA() *cobra.Command { | ||
var ( | ||
id string | ||
email string | ||
password string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "disable mfa", | ||
Short: "Disables MFA for a Sumo Logic user.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger := logging.GetLoggerForCommand(cmd) | ||
logger.Debug().Msg("User disable mfa request started.") | ||
userDisableMFA(id, email, password, logger) | ||
logger.Debug().Msg("User disable mfa request finished.") | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func userDisableMFA(id string, email string, password string, logger zerolog.Logger) { | ||
|
||
} |
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