Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating ospid logic to exit if legacy project id is provided #773

Merged
merged 1 commit into from
Aug 30, 2022
Merged

updating ospid logic to exit if legacy project id is provided #773

merged 1 commit into from
Aug 30, 2022

Conversation

acornett21
Copy link
Contributor

@acornett21 acornett21 commented Aug 22, 2022

Output from test

Examples:
  preflight check container quay.io/repo-name/container-name:version

Flags:
      --certification-project-id string   Certification Project ID from connect.redhat.com/projects/{certification-project-id}/overview
                                          URL paramater. This value may differ from the PID on the overview page. (env: PFLT_CERTIFICATION_PROJECT_ID)
  -h, --help                              help for container
      --pyxis-api-token string            API token for Pyxis authentication (env: PFLT_PYXIS_API_TOKEN)
      --pyxis-env string                  Env to use for Pyxis submissions. (default "prod")
      --pyxis-host string                 Host to use for Pyxis submissions. This will override Pyxis Env. Only set this if you know what you are doing.
                                          If you do set it, it should include just the host, and the URI path. (env: PFLT_PYXIS_HOST)
  -s, --submit                            submit check container results to red hat

Global Flags:
      --artifacts string       Where check-specific artifacts will be written. (env: PFLT_ARTIFACTS)
  -d, --docker-config string   Path to docker config.json file. This value is optional for publicly accessible images.
                               However, it is strongly encouraged for public Docker Hub images,
                               due to the rate limit imposed for unauthenticated requests. (env: PFLT_DOCKERCONFIG)
      --logfile string         Where the execution logfile will be written. (env: PFLT_LOGFILE)
      --loglevel string        The verbosity of the preflight tool itself. Ex. warn, debug, trace, info, error. (env: PFLT_LOGLEVEL)

2022/08/24 16:11:12 certification project id: ospid-62423-f26c346-6cc1dc7fae92 is improperly formatted see help command for instructions on obtaining proper value

Signed-off-by: Adam D. Cornett adc@redhat.com

@openshift-ci openshift-ci bot requested a review from skattoju August 22, 2022 22:29
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2022
Copy link
Contributor

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

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

Couple of suggestions..

// counting the `-` values, if the user provides more than one, we know they inputted a legacy project id
// which can not be used to query pyxis, exiting early to show the help menu
if strings.Count(certificationProjectID, "-") != 1 {
return errors.Errorf("certification prodject id: %s is improperly formatted see help for instructions on obtaining proper value", certificationProjectID)
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
return errors.Errorf("certification prodject id: %s is improperly formatted see help for instructions on obtaining proper value", certificationProjectID)
return errors.Errorf("certification prodject id: %s is improperly formatted, see instructions to obtain the proper value", certificationProjectID)

Copy link
Contributor

Choose a reason for hiding this comment

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

But also... Where are these instructions? A link might help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only have that info in our help output, I believe.

certification/runtime/config.go Outdated Show resolved Hide resolved
return &cfg, nil
}

// storeContainerPolicyConfiguration reads container-policy-specific config
// items in viper, normalizes them, and stores them in Config.
func (c *Config) storeContainerPolicyConfiguration(vcfg viper.Viper) {
func (c *Config) storeContainerPolicyConfiguration(vcfg viper.Viper) error {
c.PyxisAPIToken = vcfg.GetString("pyxis_api_token")
c.Submit = vcfg.GetBool("submit")
c.PyxisHost = pyxisHostLookup(vcfg.GetString("pyxis_env"), vcfg.GetString("pyxis_host"))

// Strip the ospid- prefix from the project ID if provided.
certificationProjectID := vcfg.GetString("certification_project_id")
if strings.HasPrefix(certificationProjectID, "ospid-") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make more sense to do these validations before we get here? Like as a PreRunE.

I can see it both ways; it won't take much to sway me one way or the other. Consider this non-blocking. Just thinking out loud.

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 that the flags would be loaded into viper if there was a PreRunE, but I might be wrong.

@bcrochet Thoughts on this?

Copy link
Contributor

@bcrochet bcrochet Aug 24, 2022

Choose a reason for hiding this comment

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

You can add a PreRunE. It should still run the PersistentPreRun. And I agree with @komish. The validation should happen earlier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The flags do get loaded before PreRunE so I have removed the logic from config.go to check_containter.go PTAL.

@coveralls
Copy link

coveralls commented Aug 23, 2022

Coverage Status

Coverage increased (+0.03%) to 84.563% when pulling 6627ef0 on acornett21:bugfix_ospid_parsing into 5f4cc98 on redhat-openshift-ecosystem:main.

cmd/check_container.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

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

Fix the gofumpt error, but otherwise lgtm

@acornett21
Copy link
Contributor Author

/test 4.8-images

Copy link
Contributor

@komish komish left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 25, 2022
@acornett21 acornett21 added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 25, 2022
@acornett21
Copy link
Contributor Author

Putting this on hold, there is another use case that we've never covered. ie a user never gives an ospid but provides a legacy project id of 123-456-789-000. Might as well try to cover that case as well.

…egacy project id

Signed-off-by: Adam D. Cornett <adc@redhat.com>
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 25, 2022
@acornett21 acornett21 removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 25, 2022
Copy link
Contributor

@komish komish left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 26, 2022
Copy link
Contributor

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented Aug 30, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: acornett21, bcrochet, jomkz, komish

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [acornett21,bcrochet,jomkz,komish]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jomkz jomkz merged commit 7555dc9 into redhat-openshift-ecosystem:main Aug 30, 2022
@acornett21 acornett21 deleted the bugfix_ospid_parsing branch September 6, 2022 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

certification-project-id with multiple dashes causes 404 status when trying to submit
6 participants