Skip to content

feat(service-registry rule): add describe and list command#1431

Merged
rkpattnaik780 merged 12 commits intoservice-registry-rulesfrom
rules_view
Feb 16, 2022
Merged

feat(service-registry rule): add describe and list command#1431
rkpattnaik780 merged 12 commits intoservice-registry-rulesfrom
rules_view

Conversation

@rkpattnaik780
Copy link
Contributor

@rkpattnaik780 rkpattnaik780 commented Feb 14, 2022

Add describe and list command for service-registry rules.

Fetching global compatibility rule for artifacts in the Service Registry instance
{
  "config": "FULL",
  "type": "COMPATIBILITY"
}
Fetching global rules for artifacts in Service Registry Instance

  RULE TYPE       DESCRIPTION                                                 STATUS    
 --------------- ----------------------------------------------------------- ---------- 
  VALIDITY        Ensure that content is valid when updating this artifact.   DISABLED  
  COMPATIBILITY   Enforce a compatibility level when updating this            ENABLED   
                  artifact (for example, Backwards Compatibility).                      

Run describe command to view confiuration of enabled rule

Verification Steps

  1. Run the following commands for list operation:
rhoas service-registry rule list 
rhoas service-registry rule list --artifact-id my-id
  1. Run following commands for describe operation.
./rhoas service-registry rule describe --rule-type compatibility
./rhoas service-registry rule describe --rule-type compatibility --artifact-id my-artifact

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Other (please specify)

Checklist

  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer

@rkpattnaik780 rkpattnaik780 changed the base branch from main to service-registry-rules February 14, 2022 08:33
@rkpattnaik780 rkpattnaik780 requested a review from a team as a code owner February 14, 2022 08:33
@craicoverflow
Copy link
Contributor

craicoverflow commented Feb 14, 2022

Add describe and list command for service-registry rules.

Screenshot from 2022-02-14 14-05-32

Screenshot from 2022-02-14 14-05-49

It is better to not use screenshots unless necessary or to complement readable text. Screenshots cannot be understood by screen readers and so it makes this inaccessible to those with visual impairments. It is better to paste the code if needed.

Edit: though I see that this is not verification steps or anything important, so it is probably fine :)

@rkpattnaik780 rkpattnaik780 changed the title Rules view feat(service-registry rule): add describe and list command Feb 14, 2022
var compatibilityRuleStatus = ruleRow{
RuleType: ruleCompatibility,
Description: "Enforce a compatibility level when updating this artifact (for example, Backwards Compatibility).",
Status: "DISABLED",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Status: "DISABLED",
Status: DISABLED_RULE_CONSTANT,

You should use a constant here.


var compatibilityRuleStatus = ruleRow{
RuleType: ruleCompatibility,
Description: "Enforce a compatibility level when updating this artifact (for example, Backwards Compatibility).",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should that use i18n?


for _, rule := range enabledRules {
if rule == ruleValidity {
validityRuleStatus.Status = "ENABLED"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
validityRuleStatus.Status = "ENABLED"
validityRuleStatus.Status = SHOULD_BE_A_CONSTANT

Copy link
Contributor

Choose a reason for hiding this comment

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

Would lowercase "enabled" be possible instead? Will this value ever need to be input by the user? If so we will want it to be lowercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is just for display.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even if it is just for display - all uppercase is harder to read than all lowercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed:

Fetching global rules for artifacts in Service Registry Instance

  RULE TYPE       DESCRIPTION                                                 STATUS   
 --------------- ----------------------------------------------------------- --------- 
  validity        Ensure that content is valid when updating this artifact.   enabled  
  compatibility   Enforce a compatibility level when updating this            enabled  
                  artifact (for example, Backwards Compatibility).                     

Run describe command to view configuration of an enabled rule:

$ rhoas service-registry rule describe --rule-type <compatibility/validity>

Comment on lines +22 to +23
ruleValidity = "VALIDITY"
ruleCompatibility = "COMPATIBILITY"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be in lowercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These serve two purpose: check the server response, display the status of rules.

one = 'No rules enabled'

[registry.rule.list.log.info.describeHint]
one = 'Run describe command to view confiuration of enabled rule'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
one = 'Run describe command to view confiuration of enabled rule'
one = 'Run describe command to view configuration of enabled rule'

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be less vague about what the describe command is, and just give them the full command instead.

Run "rhoas service-registry describe"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing text to :

Run describe command to view configuration of an enabled rule:

$ rhoas service-registry rule describe --rule-type <compatibility/validity>

@@ -0,0 +1,175 @@
package describe
Copy link
Contributor

Choose a reason for hiding this comment

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

$ rhoas service-registry rule describe --rule-type compatibilitkiy -v
❌ Invalid value "&{0xc00044fd10}" for --rule-type, valid options are: "validity", "compatibility". Run the command in verbose mode using the -v flag to see more information

Putting in an invalid type-type value is not handled correctly.

return err
}

instanceIDPrompt := &survey.Input{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wtrocki prompts for few flags got missed in the last PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be prompting for the instance ID - it is not a pattern used in the other commands.

}
}

cfg, err := opts.Config.Load()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be moved to line 101 - it is out of the place

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

Verified functionally, good job 👍🏻

My main concern though is that the artifact ID and instance ID are not being validated in interactive mode. Can we have that?


[registry.rule.list.log.info.describeHint]
one = '''
Run describe command to view configuration of an enabled rule:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it reads very well currently, maybe this?

Suggested change
Run describe command to view configuration of an enabled rule:
Run the following to view the configuration of an enabled rule:

one = '''
Run describe command to view configuration of an enabled rule:

$ rhoas service-registry rule describe --rule-type <compatibility/validity>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be indented.

return err
}

instanceIDPrompt := &survey.Input{
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be prompting for the instance ID - it is not a pattern used in the other commands.

return err
}

artifactIDPrompt := &survey.Input{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would make more sense to be a list you can select from - it would be less error prone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validating and suggesting values becomes bit tricky here as artifact operations need the group before hand. Even if we put the group prompt before artifact prompt, there doesn't seem to be any way to retrieve the list of groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should be prompting for the instance ID - it is not a pattern used in the other commands.

I agree but other interactive modes didn't have the instance id flags, I am not sure if we should make the interactive mode have less options than non-interactive.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep in mind that sometimes reasons why integration is soo hard is because API is simply making it hard. If there is some suggestion we can put for future versions of the API (this area is being worked on) it would be good for entire service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed instance ID argument to flag only, removed from prompt.

}
} else {

opts.Logger.Info(opts.localizer.MustLocalize(
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have a spinner in front of it (use these as much as possible when some action is taking place)


opts.localizer.MustLocalize("registry.rule.list.compatibilityRule.description")

var compatibilityRuleStatus = ruleRow{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var compatibilityRuleStatus = ruleRow{
compatibilityRuleStatus := ruleRow{

^ recommended

Comment on lines +23 to +29
RuleValidity = "validity"
RuleCompatibility = "compatibility"
)

const (
RuleDisabled = "disabled"
RuleEnabled = "enabled"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these variables need to be public?

"github.com/redhat-developer/app-services-cli/pkg/core/localize"
)

type RegistryRuleError struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type RegistryRuleError struct {
type RegistryRuleError struct {

That name is misleading - when I saw it being used in the code I thought that it is an error struct.

Comment on lines +26 to +37
// AddArtifactID adds a flag for setting the artifact ID
func (fs *flagSet) AddArtifactID(artifactID *string) {
flagName := "artifact-id"

fs.StringVar(
artifactID,
flagName,
"",
fs.factory.Localizer.MustLocalize("artifact.common.id"),
)

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could that be more common - isn't artifact-id used elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

flagbuilders for --artifact-id and --group will be moved to the registrycmdutil in the next PR.

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

LGTM. However I recommend improving how the spinner indicator gets displayed by keeping the message there and not having it disappear.

s.Stop()
} else {
s := spinner.New(opts.IO.ErrOut, opts.localizer)
s.SetLocalizedSuffix("registry.rule.list.log.info.fetching.artifactRules")
Copy link
Contributor

Choose a reason for hiding this comment

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

"Fetching global rules for artifacts in Service Registry Instance" disappears once the data has loaded Do you want that? Maybe it is better to not have any message at all since I am not sure if it tells the user something they don't know.

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise it would be better to let that message remain on the top of the display even after it has completed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same goes in other instances where this happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same goes in other instances where this happens.

Is this suggestion for list command only or all commands that use spinners?
I cant form a strong opinion about the loader text. We can probably remove it as it shows nothing new.
Cc @wtrocki

Copy link
Contributor

Choose a reason for hiding this comment

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

The loader text is fine but it should not just flash up for a half second and disappear - the user will be thinking they missed something important. It is best to ensure it just does not be deleted so the user can still see the message as normal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Updating PR to keep the spinners.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Persisting the spinner texts runs to newline issue, logger.info() or \n for spacing doesn't seem to fix this either.

⣷ Fetching rules for the artifact❌ Artifact with ID 41590799-c99f-47cc-85a2-c50578 not found. Run the command in verbose mode using the -v flag to see more information

Any instance where we have leave spinner unclosed?

@rkpattnaik780 rkpattnaik780 merged commit f3219bd into service-registry-rules Feb 16, 2022
@rkpattnaik780 rkpattnaik780 deleted the rules_view branch February 16, 2022 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants