Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

api: added a bootstrap endpoint #1681

Merged
merged 2 commits into from
Mar 15, 2018
Merged

Conversation

mssola
Copy link
Collaborator

@mssola mssola commented Feb 14, 2018

This new endpoint lives inside of the user namespace and its main goal is to
allow people to create the first admin user from the API. This endpoint is only
allowed if the first_user_admin option has not been disabled. Another
restriction is that there shouldn't be a user already created. Last but not
least, this method can be called without being authenticated.

In the ideal case, you would call this method when you just started your Portus
instance. Then, you will get the first user created
(same arguments as POST /api/v1/users) and it will also get an application
token assigned to it. The reponse will be the plain_token from the application
token. Thus, the whole point of this method is to follow this workflow:

  1. Portus instance deployed.
  2. Admin uses this bootstrap endpoint to create the admin user and get an
    application token.
  3. With this application token the admin starts to administrate the
    instance (e.g. register the registry on Portus) entirely from the API.
  4. Admin makes the Portus instance available inside of the organization and
    starts structuring it inside of Portus.

Finally, this commit also started to make error responses more uniform. This was
firstly done to DRY some of the code created by this feature. It probably needs
more work (see #1437).

See #1412

Signed-off-by: Miquel Sabaté Solà [email protected]

@mssola
Copy link
Collaborator Author

mssola commented Mar 14, 2018

@vitoravelino this is passing now (with the second commit I'm fixing a silly issue with how we call rubocop so Travis is green).

@vitoravelino
Copy link
Contributor

This branch is out-of-date with the base branch

Is this a new github feature? Force rebase even if there's no conflict...

@mssola
Copy link
Collaborator Author

mssola commented Mar 15, 2018

Is this a new github feature? Force rebase even if there's no conflict...

I think it is. It's a new option from the repo settings, and we have it enabled (which kinda makes sense)

This new endpoint lives inside of the user namespace and its main goal is to
allow people to create the first admin user from the API. This endpoint is only
allowed if the `first_user_admin` option has not been disabled. Another
restriction is that there shouldn't be a user already created. Last but not
least, this method can be called without being authenticated.

In the ideal case, you would call this method when you just started your Portus
instance. Then, you will get the first user created
(same arguments as `POST /api/v1/users`) and it will also get an application
token assigned to it. The reponse will be the `plain_token` from the application
token. Thus, the whole point of this method is to follow this workflow:

1. Portus instance deployed.
2. Admin uses this bootstrap endpoint to create the admin user and get an
   application token.
3. With this application token the admin starts to administrate the
   instance (e.g. register the registry on Portus) entirely from the API.
4. Admin makes the Portus instance available inside of the organization and
   starts structuring it inside of Portus.

Finally, this commit also started to make error responses more uniform. This was
firstly done to DRY some of the code created by this feature. It probably needs
more work (see SUSE#1437).

See SUSE#1412

Signed-off-by: Miquel Sabaté Solà <[email protected]>
I've also added the -x flag so it's more obvious what's failing.

Signed-off-by: Miquel Sabaté Solà <[email protected]>
bad_request!(application_token.errors)
end
else
bad_request!(user.errors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be unprocessable_entity?

status 201
{ plain_token: plain_token }
else
bad_request!(application_token.errors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this one too?

Copy link
Contributor

@vitoravelino vitoravelino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job as usual! Thanks! 👍

@vitoravelino vitoravelino merged commit 3b2d38e into SUSE:master Mar 15, 2018
@mssola mssola deleted the api-bootstrap branch March 15, 2018 13:38
@mssola
Copy link
Collaborator Author

mssola commented Mar 15, 2018

The 400 vs 422 case will be moved into another PR, as discussed internally.

mssola added a commit that referenced this pull request Mar 20, 2018
See #1729
See #1681

Signed-off-by: Miquel Sabaté Solà <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants