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

datasources added: artifactory_file & artifactory_fileinfo #65

Merged
merged 10 commits into from
Dec 16, 2019

Conversation

volkc-basf
Copy link
Contributor

@volkc-basf volkc-basf commented Oct 24, 2019

This PR implements #63, means it will add support to download artifacts using terraform. It won't compile as long as atlassian/go-artifactory#19 is not merged.

Best,
Chris

provider "artifactory" { ... } # this is up to you

data "artifactory_file" "test" {
   # required - the repository key
   repository = "repo-key" 

   # required - the path to the artifact within the repo
   path = "/path/to/the/artifact.zip" 

   # optional (default: empty)   - if set terraform will download the artifact to the specified output_path, if nil only the metadata (see below) are accessible
   output_path = "artifact.zip"

   # optional (default: false) - if true, terraform will overwrite the existing file specified via output_path
   force_overwrite = true                                                                 
}

output "created" {
  value = data.artifactory_file.test.created_by
}

output "created_by" {
  value = data.artifactory_file.test.created_by
}

output "last_modified" {
  value = data.artifactory_file.test.last_modified
}

output "modified_by" {
  value = data.artifactory_file.test.modified_by
}

output "last_updated" {
  value = data.artifactory_file.test.last_updated
}

output "mimetype" {
  value = data.artifactory_file.test.mimetype
}

output "size" {
  value = data.artifactory_file.test.size
}

output "uri" {
  value = data.artifactory_file.test.download_uri
}

output "md5" {
  value = data.artifactory_file.test.md5
}

output "sha1" {
  value = data.artifactory_file.test.sha1
}

output "sha256" {
  value = data.artifactory_file.test.sha256
}

output "output_path" {
  value = data.artifactory_file.test.output_path
}

@volkc-basf
Copy link
Contributor Author

Just to give you an intuition how the output of the above hcl script could look like ... ;-)

image

Copy link
Contributor

@ttsangAtlassian ttsangAtlassian left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the contribution. Now that Dillon, the original maintainer, has left the company we are still trying to determine how we are going to handle these repos. Unfortunately my knowledge of Go is limited but I'll make sure I get someone to look into this PR and the PR in go-artifactory in the next few days.

@volkc-basf
Copy link
Contributor Author

Hey @ttsangAtlassian,

may I ask you for an update? Please let me know if you do need any further help from my side.

Thanks,
Chris

@jamestoyer
Copy link
Contributor

@volkc-basf apologies. I will try and take a look today. I have noticed that the formatting is failing to pass in the build test. Could you fix that up?

@volkc-basf
Copy link
Contributor Author

@jamestoyer Hope it's okay now.

@jamestoyer
Copy link
Contributor

jamestoyer commented Nov 11, 2019

@volkc-basf I've gone ahead and released v2.5.0 of the go-artifactory client library. Could you update to it and check that everything works as expected? 🙂

@volkc-basf
Copy link
Contributor Author

@jamestoyer: From my side, everything looks very good ;-)

Copy link
Contributor

@jamestoyer jamestoyer left a comment

Choose a reason for hiding this comment

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

Looking through this I think what you really want are two data sources. One for the File Info and one to get the file. Right now it feels like you're trying to do both in one go and there could be scenarios where you want to only get the File Info.

It would be good to also add to the documentation in website/docs/r

pkg/artifactory/datasource_artifactory_file.go Outdated Show resolved Hide resolved
pkg/artifactory/datasource_artifactory_file.go Outdated Show resolved Hide resolved
pkg/artifactory/datasource_artifactory_file.go Outdated Show resolved Hide resolved
pkg/artifactory/datasource_artifactory_file.go Outdated Show resolved Hide resolved
pkg/artifactory/datasource_artifactory_file.go Outdated Show resolved Hide resolved
@volkc-basf
Copy link
Contributor Author

Looking through this I think what you really want are two data sources. One for the File Info and one to get the file.

Do you have a use case for that, where someone is only interested in file metadata? I mean Terraform is built to deploy certain things, hence I believe people are more interested in the raw file rather than in its metadata. But of course, one thing we could discuss is to make the output_path property mandatory.

@jamestoyer
Copy link
Contributor

I can think of a few scenarios whereby you might only want one or the other

  1. You are using the file info to populate a template used by something else, e.g. userdata in an EC2 instance
  2. You might want to get the file info and conditionally download the file based on that information

In both scenarios you don't want the file at first, but may want it later. Having an optional field which modifies the download behaviour of the file feels like it's making the process more opaque.

@volkc-basf
Copy link
Contributor Author

Okay, I don't mind. Added a second dataSource called artifactory_fileinfo, that can be used to access the metadata only and in parallel I set the output_path in artifactory_file as required. Docs are also there now.

@volkc-basf volkc-basf changed the title datasource artifactory_file added datasources added: artifactory_file & artifactory_fileinfo Nov 13, 2019
Copy link
Contributor

@jamestoyer jamestoyer left a comment

Choose a reason for hiding this comment

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

Looks good. I think we're almost there. I'm not sure we still need the SkipDownload method now or if we do it can be simplified just to check the SHAs of an existing file

return err
}

skip, err := SkipDownload(fileInfo, outputPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that output_path is required, do we still need this? Maybe the verification of the SHAs can be here instead

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 tried to refactor that part, however I believe it's not safe to verify the checksum only. There are multiple reasons why the checksum verification could fail:

  • file doesn't exist
  • any problems with the hash library
  • io issues

However we only want to proceed with the download in the first case. Having that said, we'll still need to check whether the file exists or not.

@volkc-basf
Copy link
Contributor Author

@jamestoyer: The build is failing with "Please check your payment method or billing status.", could you please check that?

@jamestoyer
Copy link
Contributor

jamestoyer commented Nov 26, 2019

😞

@ttsangAtlassian have actions been turned off for this repo?

Copy link
Contributor

@jamestoyer jamestoyer left a comment

Choose a reason for hiding this comment

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

It looks good. I'll just wait for @ttsangAtlassian to check what's happened to the GitHub actions then we can get this merged.

@volkc-basf
Copy link
Contributor Author

It looks good. I'll just wait for @ttsangAtlassian to check what's happened to the GitHub actions then we can get this merged.

Perfect, thank you for your help!

@ttsangAtlassian
Copy link
Contributor

I have a bad feeling we are being bitten by this https://github.community/t5/GitHub-Actions/GitHub-Actions-workflows-can-t-be-executed-on-this-repository/td-p/38153 It looks like when actions went GA on Nov 14th, legacy plans had actions disabled for all plans including OSS. I'll try and chase this up

@volkc-basf
Copy link
Contributor Author

I have a bad feeling we are being bitten by this https://github.community/t5/GitHub-Actions/GitHub-Actions-workflows-can-t-be-executed-on-this-repository/td-p/38153 It looks like when actions went GA on Nov 14th, legacy plans had actions disabled for all plans including OSS. I'll try and chase this up

@ttsangAtlassian: How is it? Hope you have some positive news for me l;-)

@ttsangAtlassian
Copy link
Contributor

@volkc-basf I'm sorry we are still trying to work out what is happening with our licenses on our end. For now I am happy to remove the build checks to get this merged.

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