Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.64k stars 840 forks source link

List reservations #21627

Open puntakana opened 1 year ago

puntakana commented 1 year ago

Bug Report

Our symptom

I want to retrieve reservations by importing: github.com/Azure/azure-sdk-for-go/profiles/latest/reservations/mgmt/reservations and sdk version : v68.0.0

The problem is that when using this code:

authorizer, err := auth.NewAuthorizerFromCLI()
if err != nil {
  log.Fatalf("error auth %v")
}

client := reservations.NewOrderClient()
client.Authorizer = authorizer
ctx := context.Background()
for listResa, err := client.ListComplete(ctx); listResa.NotDone(); err = listResa.NextWithContext(ctx) {
  if err != nil {
      log.Fatalf("%v", err)
  }
  curResa := listResa.Value()

  fmt.Printf("%v : %v and ProvisioningState : %v\n", *curResa.DisplayName, curResa.ExpiryDate, curResa.ProvisioningState)
}

I don't get the full list of reservations (or at least the ones my user has access to). In fact, when going through the portal (reservations section), or using the az reservations list command, or even with this Python code:

import json

from azure.identity import DefaultAzureCredential
from azure.mgmt.reservations import AzureReservationAPI

subscription_id="XXXXXXX"

client = AzureReservationAPI(
        credential=DefaultAzureCredential(),
        subscription_id=subscription_id
    )

result = client.reservation.list_all()

for item in result:
    print(json.dumps(item.serialize()))

I can see many more reservations.

Upon further investigation, I've noticed that there is a difference in the IAM part.

For reservations where I don't have an inherited right, the Golang code does not allow me to see the reservation. However, if I have an inherited IAM (Identity and Access Management) right in this case, the Golang code allows me to see the reservation.

Do you have any idea what I might be doing wrong in my Golang code or maybe is it a bug in go-sdk ?

jhendrixMSFT commented 1 year ago

This is from our legacy SDK which is in maintenance mode and is likely outdated. The latest SDK for reservations can be found here. Can you please migrate and see if it resolves your issue?

github-actions[bot] commented 1 year ago

Hi @puntakana. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

puntakana commented 1 year ago

Hi @jhendrixMSFT,

Thank you for the response. I just tried the latest SDK (v3.0.1), but I'm experiencing the same symptoms (I only list reservations with an inherited right). I followed the example in the documentation:

clientFactory, err := armreservations.NewClientFactory(cred, nil)
if err != nil {
  log.Fatalf("failed to create client: %v", err)
}

pager := clientFactory.NewReservationOrderClient().NewListPager(nil)
for pager.More() {
  page, err := pager.NextPage(ctx)
  if err != nil {
      log.Fatalf("failed to advance page: %v", err)
  }
  for _, v := range page.Value {
      // You could use page here. We use blank identifier for just demo purposes.
      fmt.Printf("id: %v ||| ProvisioningState: %#v\n", *v.ID, *v.Properties.ProvisioningState)
  }
}
github-actions[bot] commented 1 year ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Rkapso.