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

[OSD-21620] Add validation for the backplane config file #420

Merged
merged 1 commit into from
May 31, 2024

Conversation

bmeng
Copy link
Contributor

@bmeng bmeng commented May 16, 2024

validation mandatory value proxy-url in backplane config validate the PD API KEY in config file if login via PD

What type of PR is this?

(/feature/)

What this PR does / Why we need it?

There are two parts for this PR:

  1. Add validation to the backplane config
    The original plan is to make the struct BackplaneConfiguration to have the mandatory fields as required, but it turns out the there are multiple ways to setup the proxy-url currently.
  • ocm backplane login --proxy-url
  • HTTPS_PROXY=xxxx ocm backplane login
  • read through the config file

So it is not possible to change the struct. Adding a small function to make sure the proxy url was set by any of above methods, and exit early if it is not set.

  1. Validate the pd api key when login via PD
    Currently, the PD API Key can be configured in config file only, and the --pd will be used in login sub-command only. So, just add a simple condition to check the backplane config when --pd passed.

Which Jira/Github issue(s) does this PR fix?

Resolves #OSD-21620

Special notes for your reviewer

Pre-checks (if applicable)

  • Ran unit tests locally
  • Validated the changes in a cluster
  • Included documentation changes with PR

@bmeng bmeng changed the title [OSD-21620] Add vlidation for the backplane config file [OSD-21620] Add validation for the backplane config file May 16, 2024
@openshift-ci openshift-ci bot requested review from mjlshen and supreeth7 May 16, 2024 09:21
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 16, 2024
@bmeng
Copy link
Contributor Author

bmeng commented May 17, 2024

/retest

1 similar comment
@bmeng
Copy link
Contributor Author

bmeng commented May 17, 2024

/retest

@bmeng
Copy link
Contributor Author

bmeng commented May 17, 2024

The test passed locally, but got timeout in the CI...

@bmeng
Copy link
Contributor Author

bmeng commented May 20, 2024

/retest

@bmeng bmeng force-pushed the validate branch 3 times, most recently from 7d995ec to 0ed2136 Compare May 20, 2024 05:24
@codecov-commenter
Copy link

codecov-commenter commented May 20, 2024

Codecov Report

Attention: Patch coverage is 69.23077% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 44.58%. Comparing base (c21ada9) to head (9d8e37c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #420      +/-   ##
==========================================
+ Coverage   44.51%   44.58%   +0.07%     
==========================================
  Files          63       63              
  Lines        5284     5291       +7     
==========================================
+ Hits         2352     2359       +7     
  Misses       2615     2615              
  Partials      317      317              
Files Coverage Δ
cmd/ocm-backplane/login/login.go 70.06% <100.00%> (+0.19%) ⬆️
pkg/cli/config/config.go 81.57% <87.50%> (+0.84%) ⬆️
cmd/ocm-backplane/console/console.go 37.59% <0.00%> (ø)


// Validate the proxy url
if viper.GetStringSlice("proxy-url") == nil && os.Getenv(info.BackplaneProxyEnvName) == "" && globalOpts.ProxyURL == "" {
return fmt.Errorf("proxy-url must be set explicitly in either config file or via the environment HTTPS_PROXY or the global option --proxy")
Copy link
Contributor

Choose a reason for hiding this comment

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

I have concerns on making proxy mandatory. There are cases where we don't need/want a proxy. Eg, for testing environment or Fedramp environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with you that it should not be mandatory, anyway it is Warning for now https://github.com/openshift/backplane-cli/pull/420/files#diff-4e5b97588faff423da8ddd605ee2a4760f4f168d9bdb8ad220d4adc5823ef086R67-R68
The plan is to make the field required, but it seems for some use cases, we will still need the proxy unset.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, ok, I missed the logger.Warn(err).

@@ -26,6 +26,19 @@ func TestGetBackplaneConfig(t *testing.T) {
}
})

t.Run("It should fail if the proxy-url is not configured", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I expect the GetBackplaneConfiguration() should succeed if the proxy-url is not configured. I am also confused on why this test succeed.....

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 30, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 31, 2024
@bmeng
Copy link
Contributor Author

bmeng commented May 31, 2024

The globalFlag --proxy part is a bit tricky, it is used in the login subcommand only. And it has the validation within the login cmd. So I removed it from the config validating function.
And also updated the tests.

Copy link
Contributor

openshift-ci bot commented May 31, 2024

@bmeng: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Contributor

@mjlshen mjlshen 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 May 31, 2024
Copy link
Contributor

openshift-ci bot commented May 31, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bmeng, mjlshen

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:

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

@openshift-merge-bot openshift-merge-bot bot merged commit d2e0d30 into openshift:main May 31, 2024
7 checks passed
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.

5 participants