mongodb / go-client-mongodb-atlas

Go Client for MongoDB Atlas
https://www.mongodb.com/docs/atlas/reference/api-resources-spec/
Apache License 2.0
79 stars 33 forks source link

ClustersService does not list the available clusters #532

Closed pantelis-karamolegkos closed 6 months ago

pantelis-karamolegkos commented 6 months ago

Describe the bug I am trying to list the clusters for my organization using ClustersService.

The following code snippet does not retrieve any clusters despite I know I have deployed a couple

(the *client instance is valid since I am able to list my projects' names)

    projects, _, err := client.Projects.GetAllProjects(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }
    for _, project := range projects.Results {
        client.Clusters.List(ctx, project.ID, nil)
    }

Expected behavior Clusters should be listed.

Logs If applicable, add logs to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

gssbzn commented 6 months ago

Hi @pantelis-karamolegkos currnetly I'm unable to reproduce

Full snipped

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/mongodb-forks/digest"
    "go.mongodb.org/atlas/mongodbatlas"
)

func main() {
    apiKey := os.Getenv("API_KEY")
    apiSecret := os.Getenv("API_SECRET")
    baseURL := os.Getenv("BASE_URL")
    t := digest.NewTransport(apiKey, apiSecret)

    tc, err := t.Client()
    if err != nil {
        log.Fatalf(err.Error())
    }

    client, _ := mongodbatlas.New(tc, mongodbatlas.SetBaseURL(baseURL))

    ctx := context.Background()
    projects, _, err := client.Projects.GetAllProjects(ctx, nil)
    if err != nil {
        log.Fatalf(err.Error())
    }
    // ppProjects, err := json.MarshalIndent(projects, "", "\t")
    // if err != nil {
    //  log.Fatalf(err.Error())
    // }
    //fmt.Println(string(ppProjects))
    for _, p := range projects.Results {
        fmt.Println("projectID", p.ID)
        clusters, _, err := client.Clusters.List(ctx, p.ID, nil)
        if err != nil {
            log.Fatalf(err.Error())
        }
        for _, c := range clusters {
            fmt.Println("clusterName", c.Name)
        }
    }
}

Are you able to reproduce with the snipped above? if yes, can you share details like the project ID which you expect to have access to clusters? and if you are not able to share here then I would recommend to reach out to mongodb support to share those details?

Also a little reminder this project is now deprecated and probably won't receive further updates so we recommend to migrate to https://github.com/mongodb/atlas-sdk-go/

pantelis-karamolegkos commented 6 months ago

Hi @gssbzn apologies, this was a typo on my code! Sorry for not closing this promptly and waisted your time 🙏🏻