AzBuilder / terrakube

Open source IaC Automation and Collaboration Software.
https://docs.terrakube.io
Apache License 2.0
523 stars 44 forks source link

publishing provider via api not working 404 #1244

Closed khaounen closed 2 months ago

khaounen commented 2 months ago

Bug description 🐞

Hi @alfespa17 and thank you for the detailed documentation you added to publish a private provider https://github.com/AzBuilder/docs/blob/main/user-guide/private-registry/using-providers.md

I've tried it today but I'm getting a 404 error, not sure from where comes this error

user@MacBook-Pro-de-Test terrakube-helm-chart % curl -XPOST https://terrakube-api.awnen.com/organizations/140206a1-b498-4a04-840c-ed1e3c8cdf37/provider -H "Content-Type: application/vnd.api+json" -H "Authorization: Bearer xxxxxxx" -d '{
    "data": {
        "type": "provider",
        "attributes": {
          "name": "random",
          "description": "random provider"
        }
    }
}'
{"timestamp":"2024-08-30T14:23:30.391+00:00","status":404,"error":"Not Found","path":"/organizations/140206a1-b498-4a04-840c-ed1e3c8cdf37/provider"}

Steps to reproduce

Go to user settings -> create an api token and generate API TOKEN to call the api

Create an organization

Create provider inside organization

curl -XPOST https://terrakube-api.awnen.com/organizations/<PASTE ORGANISATION ID HERE>/provider -H "Content-Type: application/vnd.api+json" -H "Authorization: Bearer  <PASTE GENERATED API TOKEN>" -d '{
    "data": {
        "type": "provider",
        "attributes": {
          "name": "random",
          "description": "random provider"
        }
    }
}'

Expected behavior

return code status code 200 or 201maybe?

Example repository

No response

Anything else?

I tried to check in the @RestController classes in the api project to find the provider endpoint but couldn't find it? maybe it was moved somewhere else? or removed completely?

alfespa17 commented 2 months ago

Hello @khaounen the correct path is

https://terrakube-api.awnen.com/api/v1/organizations/140206a1-b498-4a04-840c-ed1e3c8cdf37/provider

You are missing the "api/v1" part

alfespa17 commented 2 months ago

By the way you didnt find any RestController because for some part of the code we are using elide so we only define the database entity and the framework takes care of generating all the CRUD endpoints

khaounen commented 2 months ago

Thank you again for your quick reply I'm getting "Unknow Collection Organization" in the response now, Is this because of the organization ID I copied from the URL? This is the the URL to access my org https://terrakube-ui.awnen.com/organizations/140206a1-b498-4a04-840c-ed1e3c8cdf37/workspaces

So I used 140206a1-b498-4a04-840c-ed1e3c8cdf37 as organization ID, isn't this correct?

curl -XPOST https://terrakube-api.awnen.com/api/v1/organizations/140206a1-b498-4a04-840c-ed1e3c8cdf37/provider -H "Content-Type: application/vnd.api+json" -H "Authorization: Bearer xxxxxx" -d '{
    "data": {
        "type": "provider",
        "attributes": {
          "name": "random",
          "description": "random provider"
        }
    }
}'
{"errors":[{"detail":"Unknown collection organizations"}]}
alfespa17 commented 2 months ago

It is organization not organizations in the path

The correct way should be

curl -X POST https://terrakube-api.awnen.com/api/v1/organization/140206a1-b498-4a04-840c-ed1e3c8cdf37/provider -H "Content-Type: application/vnd.api+json" -H "Authorization: Bearer xxxxxx" -d '{
    "data": {
        "type": "provider",
        "attributes": {
          "name": "random",
          "description": "random provider"
        }
    }
}
khaounen commented 2 months ago

Oh my bad! its fixed but looks like the user I'm connecting with (member of TERRAKUBE_ADMIN) doesn't have the right to create the provider in the organization

{"errors":[{"detail":"CreatePermission Denied"}]}

Maybe another group needed for this?

alfespa17 commented 2 months ago

TERRAKUBE_ADMIN

The TERRAKUBE_ADMIN group can only manage teams and create organization inside Terrakube,

If you want to use that team to manage workspace, providers, modules, etc you will have to add that team to the teams organization setting.

You can follow this:

https://docs.terrakube.io/user-guide/organizations/team-management

khaounen commented 2 months ago

Ok great! thank you again, I'm closing my ticket as there is no bug from the api side, its more from the post I was doing, thank you again, I'll check the doc and give it a try later

EDIT: Checked quickly the link you've sent me, I only needed to create a team called TERRAKUBE_ADMIN and check Manage providers, and now the Post is working