Skip to content

Conversation

@brunoocasali
Copy link
Member

@brunoocasali brunoocasali commented Feb 18, 2022

Create the generate_tenant_token following the specification meilisearch/specifications#89

@brunoocasali brunoocasali changed the base branch from main to bump-meilisearch-v0.26.0 February 18, 2022 20:40
This will help to test the generate_tenant_token feature, without this
I will need to implement the decode by hand, and test it.
@brunoocasali brunoocasali marked this pull request as ready for review February 22, 2022 11:39
@brunoocasali
Copy link
Member Author

bors try

meili-bors bot added a commit that referenced this pull request Feb 22, 2022
@brunoocasali brunoocasali changed the title Feature/tenant token Feature/Tenant Token: Add a module which can generate tenant tokens Feb 22, 2022
meili-bors bot added a commit that referenced this pull request Feb 22, 2022
@meilisearch meilisearch deleted a comment from meili-bors bot Feb 22, 2022
@meilisearch meilisearch deleted a comment from meili-bors bot Feb 22, 2022
end

def retrieve_valid_key!(*keys)
key = keys.compact.find { |k| !k.empty? }
Copy link
Member

@curquiza curquiza Feb 22, 2022

Choose a reason for hiding this comment

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

Are you checking the given key is an already existing key in the search engine?
the list of the keys is only retrievable if you pass the master key. What if the users want to use generate_tenant_token but don't instanciate the Client with the master key?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you checking the given key is an already existing key in the search engine?
Actually not, the generate_tenant_token method does not make an external request.

What I tried to achieve with this method, is to enable an optional behavior:

If the user wants to generate a token with a particular key, they can: client.generate_tenant_token(rules, api_key: new_key).
Otherwise, we will use the "default" key client.generate_tenant_token(rules), which means, we will use the @api_key defined when the user instantiated the client: client = MeiliSearch::Client.new(url, "masterKey") (we will use the "masterKey") then.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if we should validate the keys using the client.keys, because like you said, it is possible that the user instantiates the client with a key without the superpowers. And if they do that, we'll have a problem handling it, will not be clear to the user what is the "correct behavior".

And there are other possible situations if we validate the key using the keys from the server:

  • We will have to raise an error if the user uses the masterKey in the method, when the client is instantiated with the masterKey, ok, we will know that, but when the client was instantiated with another key we will not be able to know which is the masterKey the user used to start the server.
  • And if the core changes which key is allowed to create tokens, suppose that only keys with the action "keys.create" is allowed to do that, we know need to introduce a change in every SDK fixing this behavior the SDK will be tightly coupled with the business rules in the core.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry we're talking about this earlier and I completely forgot that it was only possible to check the other keys with the master key.

Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

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

Except for the return from @curquiza, Every thing looks good to me! 💪

end

def retrieve_valid_key!(*keys)
key = keys.compact.find { |k| !k.empty? }
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry we're talking about this earlier and I completely forgot that it was only possible to check the other keys with the master key.

@brunoocasali
Copy link
Member Author

@alallema I've added a use case to test the UTC thing as you mentioned in the Dart SDK!

@brunoocasali brunoocasali requested a review from curquiza March 2, 2022 12:57
@brunoocasali brunoocasali merged commit 8562f2d into bump-meilisearch-v0.26.0 Mar 2, 2022
@brunoocasali brunoocasali deleted the feature/tenant-token branch March 2, 2022 21:50
@brunoocasali brunoocasali added skip-changelog The PR will not appear in the release changelogs enhancement New feature or request and removed skip-changelog The PR will not appear in the release changelogs labels Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants