How do I make the fancy name for id lookup work?

I am looking at Bug #5598: Hammer cannot list repositories - Katello - Foreman and I have a
fix at:

However… this gives me:

Usage:
hammer repository list [OPTIONS]

Options:
–by BY Field to sort the results on
–content-type CONTENT_TYPE limit to only repositories of this time
–content-view-id CONTENT_VIEW_ID ID of a content view to show
repositories in
–environment-id ENVIRONMENT_ID ID of an environment to show
repositories in
–full-results FULL_RESULTS Whether or not to show all results
–library LIBRARY show repositories in Library and the
default content view
–order ORDER Sort field and order, eg. ‘name DESC’
–organization ORGANIZATION_NAME
–organization-id ORGANIZATION_ID ID of an organization to show
repositories in
–organization-label ORGANIZATION_LABEL
–page PAGE Page number, starting at 1
–per-page PER_PAGE Number of results per page to return
–product-id PRODUCT_ID ID of a product to show repositories of
–search SEARCH Search string
-h, --help print help

where I really want to do the fancy name and/or ids for content view,
environment, and product. I tried to look at
Fixes #5569 - support --name for repository-set available-repositories by iNecas · Pull Request #157 · Katello/hammer-cli-katello · GitHub to make it work
but I have not seen code like that in other areas. Teach a dude to fish,
how do I do the fancy option switching?

– bk

I looked at your issue. You had the code right. There is actually
problem with option builders creating fancy options only for required id
parameter.
This PR should fix it, please test:

https://github.com/theforeman/hammer-cli-foreman/pull/116

I played with the repository command and discovered some more issues. I
found 12 Katello controllers (including repo controller) that don't
allow searches by name in index actions. I'm not sure if this
requirement is valid for all of them though:

Another problem is that Katello controllers use elasticsearch for
querying index actions. They don't do exact matches but search for a
pattern by default. Therefore
$ hammer lifecycle-environment --name "Dev" --organization-id 1
which calls
/katello/api/organizations/1/environments?name=Dev
can find both "Dev" and "Development" and raise ambiguous search
exception. It also ignores letter cases.

Is this intended behavior? I'm looking for the right place to fix it. Is
it possible to force the api to perform exact match? Maybe the id
resolver constructs the search phrases wrong.

Cheers
Tomas

··· On 05/06/2014 10:45 PM, Bryan Kearney wrote: > I am looking at http://projects.theforeman.org/issues/5598 and I have a > fix at: > > https://github.com/bkearney/hammer-cli-katello/commit/a644bc99559871bd88b30637126bf601d2d38336 > > > However.. this gives me: > > Usage: > hammer repository list [OPTIONS] > > Options: > --by BY Field to sort the results on > --content-type CONTENT_TYPE limit to only repositories of this time > --content-view-id CONTENT_VIEW_ID ID of a content view to show > repositories in > --environment-id ENVIRONMENT_ID ID of an environment to show > repositories in > --full-results FULL_RESULTS Whether or not to show all results > --library LIBRARY show repositories in Library and the > default content view > --order ORDER Sort field and order, eg. 'name DESC' > --organization ORGANIZATION_NAME > --organization-id ORGANIZATION_ID ID of an organization to show > repositories in > --organization-label ORGANIZATION_LABEL > --page PAGE Page number, starting at 1 > --per-page PER_PAGE Number of results per page to return > --product-id PRODUCT_ID ID of a product to show repositories of > --search SEARCH Search string > -h, --help print help > > > where I really want to do the fancy name and/or ids for content view, > environment, and product. I tried to look at > https://github.com/Katello/hammer-cli-katello/pull/157 to make it work > but I have not seen code like that in other areas. Teach a dude to fish, > how do I do the fancy option switching? > > -- bk >

Talked with Justin this morning. This is a bug if it's returning "Dev" and "Development" for name=Dev. I believe only name=Dev* should do that.

That said, we do have another problem though: the query 'name=Dev' is case insensitive and we allow names/labels that differ by case (ie "dev" and "Dev") so 'name=Dev' could potentially return more than 1 result.

David

··· ----- Original Message ----- > From: "Tomas Strachota" > To: foreman-dev@googlegroups.com > Sent: Tuesday, May 13, 2014 6:12:52 AM > Subject: Re: [foreman-dev] How do I make the fancy name for id lookup work? > > On 05/06/2014 10:45 PM, Bryan Kearney wrote: > > I am looking at http://projects.theforeman.org/issues/5598 and I have a > > fix at: > > > > https://github.com/bkearney/hammer-cli-katello/commit/a644bc99559871bd88b30637126bf601d2d38336 > > > > > > However.. this gives me: > > > > Usage: > > hammer repository list [OPTIONS] > > > > Options: > > --by BY Field to sort the results on > > --content-type CONTENT_TYPE limit to only repositories of this time > > --content-view-id CONTENT_VIEW_ID ID of a content view to show > > repositories in > > --environment-id ENVIRONMENT_ID ID of an environment to show > > repositories in > > --full-results FULL_RESULTS Whether or not to show all results > > --library LIBRARY show repositories in Library and the > > default content view > > --order ORDER Sort field and order, eg. 'name DESC' > > --organization ORGANIZATION_NAME > > --organization-id ORGANIZATION_ID ID of an organization to show > > repositories in > > --organization-label ORGANIZATION_LABEL > > --page PAGE Page number, starting at 1 > > --per-page PER_PAGE Number of results per page to return > > --product-id PRODUCT_ID ID of a product to show repositories of > > --search SEARCH Search string > > -h, --help print help > > > > > > where I really want to do the fancy name and/or ids for content view, > > environment, and product. I tried to look at > > https://github.com/Katello/hammer-cli-katello/pull/157 to make it work > > but I have not seen code like that in other areas. Teach a dude to fish, > > how do I do the fancy option switching? > > > > -- bk > > > > I looked at your issue. You had the code right. There is actually > problem with option builders creating fancy options only for required id > parameter. > This PR should fix it, please test: > > https://github.com/theforeman/hammer-cli-foreman/pull/116 > > I played with the repository command and discovered some more issues. I > found 12 Katello controllers (including repo controller) that don't > allow searches by name in index actions. I'm not sure if this > requirement is valid for all of them though: > > http://projects.theforeman.org/issues/5686 > > Another problem is that Katello controllers use elasticsearch for > querying index actions. They don't do exact matches but search for a > pattern by default. Therefore > $ hammer lifecycle-environment --name "Dev" --organization-id 1 > which calls > /katello/api/organizations/1/environments?name=Dev > can find both "Dev" and "Development" and raise ambiguous search > exception. It also ignores letter cases. > > Is this intended behavior? I'm looking for the right place to fix it. Is > it possible to force the api to perform exact match? Maybe the id > resolver constructs the search phrases wrong. > > Cheers > Tomas > > > > > > -- > You received this message because you are subscribed to the Google Groups > "foreman-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to foreman-dev+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. >

>> I am looking at Bug #5598: Hammer cannot list repositories - Katello - Foreman and I have a
>> fix at:
>>
>> https://github.com/bkearney/hammer-cli-katello/commit/a644bc99559871bd88b30637126bf601d2d38336
>>
>>
>>
>> However… this gives me:
>>
>> Usage:
>> hammer repository list [OPTIONS]
>>
>> Options:
>> --by BY Field to sort the results on
>> --content-type CONTENT_TYPE limit to only repositories of this
>> time
>> --content-view-id CONTENT_VIEW_ID ID of a content view to show
>> repositories in
>> --environment-id ENVIRONMENT_ID ID of an environment to show
>> repositories in
>> --full-results FULL_RESULTS Whether or not to show all results
>> --library LIBRARY show repositories in Library and the
>> default content view
>> --order ORDER Sort field and order, eg. 'name DESC'
>> --organization ORGANIZATION_NAME
>> --organization-id ORGANIZATION_ID ID of an organization to show
>> repositories in
>> --organization-label ORGANIZATION_LABEL
>> --page PAGE Page number, starting at 1
>> --per-page PER_PAGE Number of results per page to return
>> --product-id PRODUCT_ID ID of a product to show
>> repositories of
>> --search SEARCH Search string
>> -h, --help print help
>>
>>
>> where I really want to do the fancy name and/or ids for content view,
>> environment, and product. I tried to look at
>> https://github.com/Katello/hammer-cli-katello/pull/157 to make it work
>> but I have not seen code like that in other areas. Teach a dude to fish,
>> how do I do the fancy option switching?
>>
>> – bk
>>
>
> I looked at your issue. You had the code right. There is actually
> problem with option builders creating fancy options only for required id
> parameter.
> This PR should fix it, please test:
>
> https://github.com/theforeman/hammer-cli-foreman/pull/116

I have acked this. It worked great for me. I would love to see a quick
merge on this :slight_smile:

>
> I played with the repository command and discovered some more issues. I
> found 12 Katello controllers (including repo controller) that don't
> allow searches by name in index actions. I'm not sure if this
> requirement is valid for all of them though:
>
> Bug #5686: Some controllers don't allow to search resources by name - Katello - Foreman

I will get someone to take a look… thanks.

– bk

··· On 05/13/2014 06:12 AM, Tomas Strachota wrote: > On 05/06/2014 10:45 PM, Bryan Kearney wrote:

> Talked with Justin this morning. This is a bug if it's returning "Dev" and "Development" for name=Dev. I believe only name=Dev* should do that.
The behavior I observed here was actually problem in hammer using wrong
controller for the name searches, which resulted in returning all items.
The fact that they all contained "Dev" was only a coincidence.
I'll send a separate email with more details. The issue is here:
http://projects.theforeman.org/issues/5876

> That said, we do have another problem though: the query 'name=Dev' is case insensitive and we allow names/labels that differ by case (ie "dev" and "Dev") so 'name=Dev' could potentially return more than 1 result.
This one is still valid. I filed issue here:
http://projects.theforeman.org/issues/5874

··· On 05/13/2014 02:23 PM, David Davis wrote:

David

----- Original Message -----

From: “Tomas Strachota” tstrachota@redhat.com
To: foreman-dev@googlegroups.com
Sent: Tuesday, May 13, 2014 6:12:52 AM
Subject: Re: [foreman-dev] How do I make the fancy name for id lookup work?

On 05/06/2014 10:45 PM, Bryan Kearney wrote:

I am looking at Bug #5598: Hammer cannot list repositories - Katello - Foreman and I have a
fix at:

https://github.com/bkearney/hammer-cli-katello/commit/a644bc99559871bd88b30637126bf601d2d38336

However… this gives me:

Usage:
hammer repository list [OPTIONS]

Options:
–by BY Field to sort the results on
–content-type CONTENT_TYPE limit to only repositories of this time
–content-view-id CONTENT_VIEW_ID ID of a content view to show
repositories in
–environment-id ENVIRONMENT_ID ID of an environment to show
repositories in
–full-results FULL_RESULTS Whether or not to show all results
–library LIBRARY show repositories in Library and the
default content view
–order ORDER Sort field and order, eg. ‘name DESC’
–organization ORGANIZATION_NAME
–organization-id ORGANIZATION_ID ID of an organization to show
repositories in
–organization-label ORGANIZATION_LABEL
–page PAGE Page number, starting at 1
–per-page PER_PAGE Number of results per page to return
–product-id PRODUCT_ID ID of a product to show repositories of
–search SEARCH Search string
-h, --help print help

where I really want to do the fancy name and/or ids for content view,
environment, and product. I tried to look at
https://github.com/Katello/hammer-cli-katello/pull/157 to make it work
but I have not seen code like that in other areas. Teach a dude to fish,
how do I do the fancy option switching?

– bk

I looked at your issue. You had the code right. There is actually
problem with option builders creating fancy options only for required id
parameter.
This PR should fix it, please test:

https://github.com/theforeman/hammer-cli-foreman/pull/116

I played with the repository command and discovered some more issues. I
found 12 Katello controllers (including repo controller) that don’t
allow searches by name in index actions. I’m not sure if this
requirement is valid for all of them though:

Bug #5686: Some controllers don't allow to search resources by name - Katello - Foreman

Another problem is that Katello controllers use elasticsearch for
querying index actions. They don’t do exact matches but search for a
pattern by default. Therefore
$ hammer lifecycle-environment --name “Dev” --organization-id 1
which calls
/katello/api/organizations/1/environments?name=Dev
can find both “Dev” and “Development” and raise ambiguous search
exception. It also ignores letter cases.

Is this intended behavior? I’m looking for the right place to fix it. Is
it possible to force the api to perform exact match? Maybe the id
resolver constructs the search phrases wrong.

Cheers
Tomas


You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.