Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

armauthorization: issue with json unmarshalling #23895

Open
nnzv opened this issue Dec 29, 2024 · 3 comments
Open

armauthorization: issue with json unmarshalling #23895

nnzv opened this issue Dec 29, 2024 · 3 comments
Assignees
Labels
Authorization customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@nnzv
Copy link

nnzv commented Dec 29, 2024

Bug Report

I'm using the Azure SDK for Go (v3.0.0-beta.2), specifically the armauthorization package, and facing an issue when calling client.Create with the RoleAssignmentScheduleRequestsClient. The problem seems to be with the scope parameter, but I'm unsure of the correct format. This occurs with Go version 1.23.1, and the API response isn't unmarshalling as expected.

github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v3 v3.0.0-beta.2

What happened?

When calling a function from the armauthorization/v3 package, specifically when interacting with the RoleAssignmentScheduleRequestsClient, an error occurs during the JSON unmarshalling process. The error message is:

2024/12/28 22:06:24 main.go: unmarshalling type *runtime.requestError: json: cannot unmarshal string into Go value of type runtime.requestError

What did you expect or want to happen?

The API response should be unmarshalled correctly into the appropriate Go struct, without any errors.

How can we reproduce it?

It appears that the issue is related to the scope, but I'm unsure if there is any documentation detailing the correct format for the scope. The error occurs after the client.Create function is called, as indicated in the logs.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v3"
	"k8s.io/utils/ptr"
)

func main() {
	// Set up the credentials to authenticate with Azure
	cred, err := azidentity.NewDeviceCodeCredential(&azidentity.DeviceCodeCredentialOptions{
		TenantID: "dummy-tenant-id-1234-5678-91011-abcdefg", // Replace with dummy tenant ID
		ClientOptions: policy.ClientOptions{
			Cloud: cloud.AzurePublic,
		},
		UserPrompt: func(ctx context.Context, message azidentity.DeviceCodeMessage) error {
			fmt.Println(message.Message) // Print the device code prompt
			return nil
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// Create the client for role assignment schedule requests
	client, err := armauthorization.NewRoleAssignmentScheduleRequestsClient(cred, nil)
	if err != nil {
		log.Fatal(err)
	}

	// Dummy values for principalID, roleDefinitionID, and scope
	principalID := "dummy-principal-id-1234-5678-91011"
	roleDefinitionID := "/providers/Microsoft.Authorization/roleDefinitions/dummy-role-id-1234-5678-91011"
	justification := "dummy justification"
	scope := "/providers/Microsoft.Management/managementGroups/dummy-management-group-id"

	// Make the request to create a role assignment schedule
	resp, err := client.Create(
		context.Background(),
		scope,
		"dummy-role-assignment-request-id", // Dummy request ID
		armauthorization.RoleAssignmentScheduleRequest{
			Properties: &armauthorization.RoleAssignmentScheduleRequestProperties{
				PrincipalID:      ptr.To(principalID),
				RequestType:      ptr.To(armauthorization.RequestTypeSelfActivate),
				RoleDefinitionID: ptr.To(roleDefinitionID),
				Justification:    ptr.To(justification),
				Scope:            ptr.To(scope),
				ScheduleInfo: &armauthorization.RoleAssignmentScheduleRequestPropertiesScheduleInfo{
					Expiration: &armauthorization.RoleAssignmentScheduleRequestPropertiesScheduleInfoExpiration{
						Type:     to.Ptr(armauthorization.TypeAfterDuration),
						Duration: to.Ptr("PT30M"),
					},
					StartDateTime: to.Ptr(time.Now()),
				},
			},
		}, nil,
	)
	if err != nil {
		log.Fatal(err)
	}
	// If successful, print the response
	fmt.Printf("Role assignment schedule request created successfully: %+v\n", resp)
}

Anything we should know about your environment?

Nothing specific, I'm just running the code I provided on Gentoo Linux.

@github-actions github-actions bot added Authorization customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. labels Dec 29, 2024
Copy link

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

@lirenhe
Copy link
Member

lirenhe commented Dec 30, 2024

@jliusan, could you take a look at this first? It looks our client library could not unmarshall the json error.

@jliusan
Copy link
Member

jliusan commented Jan 2, 2025

@nnzv could you turn on logging by setting environment variable AZURE_SDK_GO_LOGGING to all and configure policy.LogOption to print the body of this call? Please help to check the details info in the raw response.
https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/new-version-guideline.md#logging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Authorization customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

3 participants