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

feat: create xray watch resource #10

Closed
wants to merge 5 commits into from

Conversation

josh-barker-coles
Copy link
Contributor

@josh-barker-coles josh-barker-coles commented Nov 2, 2020

Hi,

This PR implements the artifactory_watch resource.

Note: It only supports the configuration of repositories and builds.

References

Dependencies:

Copy link

@peters95 peters95 left a comment

Choose a reason for hiding this comment

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

We need to implement Xray Policies as well as watches because a Watch without a policy is automatically disabled.

@josh-barker-coles
Copy link
Contributor Author

Hi @peters95, thanks for your feedback.
From what I can see, neither of the go client's support CRUD operations for an Xray policy.

I would also expect that the resource for an Xray Policy would be in a separate PR.

@josh-barker-coles
Copy link
Contributor Author

Hi @chb0github , will you be taking over this PR too?

@peters95
Copy link

@chb0github please review this PR.
@josh-barker-coles we may delay this PR until we can implement both watches and policies through the new client that uses jfrog cli go client instead.

}
details.SetUrl(url)

if username != "" && password != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

These are not nested cases (so, no else if needed).

Also, please have independent cases for element missing; not all bunched up into 1 error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @chb0github ,

There are 3 ways someone could authenticate to xray.

  1. User name and password
  2. API Key
  3. Access token

The cases are mutually exclusive.
Hence, the else if.

accessToken := d.Get("access_token").(string)

url := d.Get("xray_url").(string)
if url[len(url)-1] != '/' {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, a url of gopher://thing will work? Please validate it's a legit url. And, you're not checking that even it's not empty

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've added some validation on the url.

client := m.(*ArtClient).XrayClient

if client == nil {
return fmt.Errorf("you must specify the xray_url in the provider to manage a watch")
Copy link
Contributor

Choose a reason for hiding this comment

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

But, that's not what you're actually checking for - you're checking for nil, but assuming the reason for a nil is because the url was missing. Asserting client isn't nil is fine, I guess. But the error message has to reflect the issue

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've updated the error message.

client := m.(*ArtClient).XrayClient

if client == nil {
return fmt.Errorf("you must specify the xray_url in the provider to manage a watch")
Copy link
Contributor

Choose a reason for hiding this comment

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

But, that's not what you're actually checking for - you're checking for nil, but assuming the reason for a nil is because the url was missing. Asserting client isn't nil is fine, I guess. But the error message has to reflect the issue

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've updated the error message.

client := m.(*ArtClient).XrayClient

if client == nil {
return false, fmt.Errorf("you must specify the xray_url in the provider to manage a watch")
Copy link
Contributor

Choose a reason for hiding this comment

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

But, that's not what you're actually checking for - you're checking for nil, but assuming the reason for a nil is because the url was missing. Asserting client isn't nil is fine, I guess. But the error message has to reflect the issue

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've updated the error message.

return false, fmt.Errorf("you must specify the xray_url in the provider to manage a watch")
}

watchName := d.Id()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why create this extra variable?

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've removed the variable

sort.Strings(packageTypes)
paths := castToStringArr(repository["paths"].(*schema.Set).List())
sort.Strings(paths)
mimeTypes := castToStringArr(repository["mime_types"].(*schema.Set).List())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you sorting these?

And, please put spaces between the string slices and the sort pair

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'm sorting the lists to ensure that terraform does not think there is a change if the returned list is ordered differently.

Copy link
Contributor

Choose a reason for hiding this comment

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

Pesky sets/hashes!

@github-actions
Copy link

github-actions bot commented Dec 1, 2020

CLA Assistant Lite bot All contributors have signed the CLA ✍️

@peters95
Copy link

peters95 commented Dec 1, 2020

Based upon the internal discussions this effort has been put on hold while we align with the product team to understand how we want to implement xray. Given the name of this provider is specific to artifactory we will need to take a step back and evaluate what makes sense from a product roadmap decision before moving forward with this work.

In addition, we will need to use the new jfrog cli go client to implement this for both policies and watches when we do pick this work back up. Until then this will be put on hold for now. Apologies for any inconvenience this causes.

@peters95 peters95 closed this Dec 1, 2020
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