Issue #16306 : Need help understanding hammer-cli options config

I am trying to understand how hammer-cli options config works.

Plugin hammer-cli-katello : What is the config/code that ensures
–id option to be numeric ?

I see that 'clamp' gem is being used, but didn't found anything that
matches the validation part in Readme
<https://github.com/mdub/clamp#validation>

The error which I see while doing *info *on content-view is:

[vagrant@centos7-hammer-devel hammer-cli-katello]$ hammer -s localhost:3000
content-view info --id=""
Error: option '–id': numeric value is required

See: 'hammer content-view info --help'

Debug trace for above query: https://da.gd/t94F

In case of foreman a delete on architecture with --id='' is actually making
an API call which it shouldn't and validate *–id *option prior.

[vagrant@centos7-hammer-devel hammer-cli-katello]$ hammer -s localhost:3000
architecture delete --id=''
Could not delete the architecture:
404 Not Found

Debug trace for above query: https://da.gd/Q58G

··· --

I found class Number is a normalizer


But not sure how options are defined of that type(Numeric in this case).

The reason behind this is I need to know why –id=’’ is giving the above
error in case of katello related models(content-views, compute resource,
hosts etc.) AND why its not raising error for foreman related
models(domain, architecture etc.)

Foreman's "id" fields are not numeric, they're identifiers which permit
either numbers or strings and so the numeric normaliser would not be
used automatically. An empty string is of the correct type.

The API docs describe the fields as strings but with a human-readable
validator description alongside.

··· On 09/11/16 09:42, Swapnil Abnave wrote: > In case of foreman a delete on architecture with --id='' is actually > making an API call which it shouldn't and validate *--id *option prior. > > > > [vagrant@centos7-hammer-devel hammer-cli-katello]$ hammer -s > localhost:3000architecture delete--id='' > Couldnotdeletethe architecture: > 404NotFound > > > > Debug trace for above query: https://da.gd/Q58G > > -- > > I found `class Number` is a normalizer > https://github.com/theforeman/hammer-cli/blob/36419717ad2ea6e012e8a6bb7623258e6e48f009/lib/hammer_cli/options/normalizers.rb#L94 > But not sure how options are defined of that type(Numeric in this case).


Dominic Cleal
dominic@cleal.org

Ahhh I see. Thanks Dominic.

Architecture:
http://www.katello.org/docs/3.2/api/apidoc/architectures/destroy.html

Content-View :
http://www.katello.org/docs/3.2/api/apidoc/content_views/destroy.html

··· --

One last question. If I update architectures_controller.rb to be like:

— architectures_controller.rb 2016-11-09 22:14:57.627000000 +0530
+++ architectures_controller.rb.new 2016-11-09 22:16:32.072000000 +0530
@@ -43,7 +43,7 @@
end

   api :DELETE, "/architectures/:id/", N_("Delete an architecture")
  •  param :id, :identifier, :required => true
    
  •  param :id, :number, :desc => N_("architecture numeric identifier"), 
    

:required => true

   def destroy
     process_response @architecture.destroy

Then the hammer command:

hammer architecture delete --id=’’

should validate *–id *to be of type Numeric ?

I tried it but still receiving error:

RestClient::ResourceNotFound (404 Resource Not Found):

Instead of expected error:

Clamp::UsageError (option ‘–id’: numeric value is required):

On Wednesday, November 9, 2016 at 6:38:09 PM UTC+5:30, Dominic Cleal wrote:

On 09/11/16 09:42, Swapnil Abnave wrote:

In case of foreman a delete on architecture with --id=’’ is actually
making an API call which it shouldn’t and validate *–id *option prior.

[vagrant@centos7-hammer-devel hammer-cli-katello]$ hammer -s
localhost:3000architecture delete–id=’'
Couldnotdeletethe architecture:
404NotFound

Debug trace for above query: https://da.gd/Q58G

I found class Number is a normalizer

https://github.com/theforeman/hammer-cli/blob/36419717ad2ea6e012e8a6bb7623258e6e48f009/lib/hammer_cli/options/normalizers.rb#L94

But not sure how options are defined of that type(Numeric in this case).

Foreman’s “id” fields are not numeric, they’re identifiers which permit
either numbers or strings and so the numeric normaliser would not be
used automatically. An empty string is of the correct type.

The API docs describe the fields as strings but with a human-readable
validator description alongside.


Dominic Cleal
dom...@cleal.org <javascript:>