Skip to content

Commit

Permalink
CLOUDP-184833: minor fixes for the examples (panic errors) (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki authored Jun 15, 2023
1 parent e2bd292 commit 15b5a8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions examples/db_users/db_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func main() {
current := new(admin.CloudDatabaseUser)
update(current)

_, response, err:= sdk.ProjectsApi.GetProject(ctx, current.GroupId).Execute()
if err != nil {
fmt.Println("Project missconfigured. Did you set the correct values in update() function?")
examples.HandleErr(err, response)
}

params := &admin.UpdateDatabaseUserApiParams{
GroupId: current.GroupId,
DatabaseName: current.DatabaseName,
Expand All @@ -50,6 +56,7 @@ func main() {

// Here we should provide input parameters for the dbUser update we wish to apply
func update(current *admin.CloudDatabaseUser) *admin.CloudDatabaseUser {
// Note that this values require manual edits
current.GroupId = "groupId"
current.Username = "user"
current.Password = admin.PtrString("password")
Expand Down
3 changes: 3 additions & 0 deletions examples/download/downloadLogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func main() {
// -- 2. Get first Process
hosts, response, err := sdk.MonitoringAndLogsApi.ListAtlasProcesses(ctx, projectId).Execute()
examples.HandleErr(err, response)
if len(hosts.GetResults()) == 0 {
log.Fatal("MongoDB atlas hosts are missing. Please review your cluster details in Atlas CLI or UI")
}
host := hosts.GetResults()[0].GetHostname()
params := &admin.GetHostLogsApiParams{
GroupId: projectId,
Expand Down
4 changes: 2 additions & 2 deletions examples/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func HandleErr(err error, resp *http.Response) {

if resp != nil {
fmt.Println(resp.Body)
// Printing generic message
fmt.Println(err.Error())
}
// Printing generic message
fmt.Println(err.Error())
apiErr, _ := admin.AsError(err)
log.Fatalf("Error when performing SDK request: %v", apiErr.GetDetail())
}

0 comments on commit 15b5a8f

Please sign in to comment.