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

Introducing support for Contexts (Config, Secret,Yaml, SecretYaml) #27

Merged
merged 2 commits into from
Jan 28, 2021

Conversation

sandrogattuso
Copy link
Contributor

Adding support to manage "Shared Configuration" for both resource and data source.
Supported contexts:

  • config
  • secret
  • yaml
  • secret-yaml

@logicbomb421
Copy link

Would love to see this released soon!

Copy link

@logicbomb421 logicbomb421 left a comment

Choose a reason for hiding this comment

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

Checked this out and ran it locally and noticed a few issues with context names that include spaces. Not entirely sure if this is an issue in the CF API, as + is often recognized as encoding for a space, but does not seem to work here. The suggested fix handles spaces using standard url encoding, which does work.

}

func (client *Client) GetContext(name string) (*Context, error) {
fullPath := fmt.Sprintf("/contexts/%s?decrypt=true", url.QueryEscape(name))
Copy link

@logicbomb421 logicbomb421 Jan 25, 2021

Choose a reason for hiding this comment

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

Suggested change
fullPath := fmt.Sprintf("/contexts/%s?decrypt=true", url.QueryEscape(name))
fullPath := fmt.Sprintf("/contexts/%s?decrypt=true", url.PathEscape(name))

Using QueryEscape here produces odd results when name contains spaces. For example, My Context/Other Piece becomes My+Context%2FOther+Piece, which seems to return an HTTP 500 (confirmed via direct API call).

Using PathEsacpe, however, produces My%20Context%2FOther%20Piece, which does return the context (and HTTP 200).

return nil, err
}

fullPath := fmt.Sprintf("/contexts/%s", url.QueryEscape(context.Metadata.Name))

Choose a reason for hiding this comment

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

Suggested change
fullPath := fmt.Sprintf("/contexts/%s", url.QueryEscape(context.Metadata.Name))
fullPath := fmt.Sprintf("/contexts/%s", url.PathEscape(context.Metadata.Name))

Same reasoning here.


func (client *Client) DeleteContext(name string) error {

fullPath := fmt.Sprintf("/contexts/%s", url.QueryEscape(name))

Choose a reason for hiding this comment

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

Suggested change
fullPath := fmt.Sprintf("/contexts/%s", url.QueryEscape(name))
fullPath := fmt.Sprintf("/contexts/%s", url.PathEscape(name))

Same reasoning here.

@sandrogattuso
Copy link
Contributor Author

Checked this out and ran it locally and noticed a few issues with context names that include spaces. Not entirely sure if this is an issue in the CF API, as + is often recognized as encoding for a space, but does not seem to work here. The suggested fix handles spaces using standard url encoding, which does work.

@logicbomb421 definitely not an issue with the API, not sure how I decided to use the QueryEscape function instead of the PathEscape. The value definitely belongs to the path, 100% agree with your feedback and the suggested changes.
I will push an update shortly and I'll also add a test case that contains special characters to validate this type of scenario.
Thanks for taking the time to provide the above input, really appreciated

@sandrogattuso
Copy link
Contributor Author

@palson-cf also rebased this one, will do further rebase based on which PR is merged first

@sandrogattuso
Copy link
Contributor Author

@palson-cf rebased again after last merge, this is now ready for review

@palson-cf palson-cf merged commit e791f82 into codefresh-io:master Jan 28, 2021
@sandrogattuso sandrogattuso deleted the feature/contexts branch April 5, 2021 21:57
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