scaleway / scaleway-sdk-go

Integrate Scaleway with your Go application

Home Page:https://pkg.go.dev/github.com/scaleway/scaleway-sdk-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can create resources with postman but not with SDK (SAME API KEY)

SebUndefined opened this issue · comments

General infos:

  • The version of scaleway-sdk-go: v1.0.0-beta.16
  • Go version: 1.20
  • GOOS: Linux
  • GOARCH: amd64

When trying to create a Device with Postman, I send my request as described in the doc with my secret key as "X-Auth-Token". So far, everything works as expected. The device is created in the scaleway console, in the project of the API Key.

But when I try with the SDK, I have an error message:

Error #01: scaleway-sdk-go: insufficient permissions: read hubs; write hubs; write devices

The code below is used to initialized the api client :

	// create client scaleway
	apiClient, err := scw.NewClient(
		scw.WithDefaultOrganizationID(config.Scaleway.ScwDefaultOrganizationID),
		scw.WithDefaultProjectID("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"),
		scw.WithAuth("SCWXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXX"),
		scw.WithDefaultRegion(scw.RegionFrPar), scw.WithDefaultZone(scw.ZoneFrPar1),
		scw.WithAPIURL(config.Scaleway.ApiUrl))

I don't think this is a problem of permission as I can create it with Postman but just in case:

API Key:

  • name: MyKey
  • Application: MyApp
  • project: MyProject

Application "MyApp":

  • Group : IOT_HUB_ACCESS

Group "IOT_HUB_ACCESS":

  • Policy: IOT_HUB_ACCESS_POLICY

Policy "IOT_HUB_ACCESS_POLICY":

  • Scope: MyProject (Access to resources)
  • Permission sets : ioTFullAccess and ObservabilityFullAccess

What am I doing wrong ? The GetDevice method works (not found as I have no device, but at least, there is no permission error).

Best

When using sdk-go, you can use SCW_DEBUG=1 to have requests logged, tokens are partially anonymized but you can still check that the correct one is used.

Definitely my bad... The Hub ID was not correct... That is why it was rejected. The error message is quite confusing. But anyway, with the Debug mode, it is quite easy to check.

Thanks @Codelax and sorry for the newbie mistake.