-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implemented Artifactory upload and download handling #30
Open
eeasaa01
wants to merge
53
commits into
cisco-open:main
Choose a base branch
from
eeasaa01:feature/artifactory-upload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
1675df4
Implemented Artifactory upload and download handling
eeasaa01 0a01f2e
Fixed authentication error and adjusted log level to debug for succes…
eeasaa01 412a3aa
Conditional ARTIFACTORY_TOKEN check and removed spurious comment
eeasaa01 825c3ea
Restored COMMENT_PREFIX and improved error logging for resource creat…
eeasaa01 d6229c9
Fixed Artifactory integration and addressed PR feedback
eeasaa01 0ea343f
Implemented requested changes and added tests for Artifactory integra…
eeasaa01 082c98b
Added comprehensive tests for Artifactory cache functionality
eeasaa01 a484aa3
Updating delete function to also delete artifactory cache
amdurh05 61ec037
Implemented Artifactory upload and download handling
eeasaa01 e98d7af
Fixed authentication error and adjusted log level to debug for succes…
eeasaa01 503e529
Conditional ARTIFACTORY_TOKEN check and removed spurious comment
eeasaa01 f5f034e
Restored COMMENT_PREFIX and improved error logging for resource creat…
eeasaa01 410b85b
Fixed Artifactory integration and addressed PR feedback
eeasaa01 4033f12
Implemented requested changes and added tests for Artifactory integra…
eeasaa01 c389fb2
Added comprehensive tests for Artifactory cache functionality
eeasaa01 2ab9448
Cleanup: Remove binary files and add gitignore
eeasaa01 2090e45
Fix: Code review feedback and cleanup
eeasaa01 1ee74b5
Fix: Pass token as parameter to uploadToArtifactory
eeasaa01 f0676ab
Fix: Prefix NO_CACHE_UPLOAD with GRABIT_
eeasaa01 5d9a7c8
Fix: Code improvements and cleanup
eeasaa01 513e420
Fix: Use requests library for cache upload
eeasaa01 8a41679
Update cmd/add.go with feedback implementation
eeasaa01 f2e8c42
Update cmd/cache_test.go with cache download tests
eeasaa01 5ba7cdd
Update log level to warn when failing to upload to cache
eeasaa01 335070a
Update hash.go and lock.go based on code review
eeasaa01 a10e728
Update .gitignore
eeasaa01 d4dcfd7
Merge branch 'feature/artifactory-upload' into feature/artifactory-de…
eeasaa01 3396a6f
Merge pull request #1 from eeasaa01/feature/artifactory-delete
eeasaa01 aa45dcb
Delete cmd/6ae8a75555209fd6c44157c0aed8016e763ff435a19cf186f768631401…
eeasaa01 de40802
Update add.go
eeasaa01 932ceef
Delete cmd/cache_test.go
eeasaa01 60c174f
Update download.go
eeasaa01 c1afae0
Delete cmd/test.txt
eeasaa01 1623787
Update hash.go
eeasaa01 ee5fafe
Update lock.go
eeasaa01 5d77339
Update resource.go
eeasaa01 1acba07
Delete a640986bc257389dd379886fdae6264c8cfa56bc98b71ce3ae3dfbd8ce61dbe3
eeasaa01 6794f82
Delete openmpi-5.0.5.tar.bz2
eeasaa01 1273d45
Replace old project files with new ones
eeasaa01 e5aefe8
Fix typo in filename: dowload_test.go -> download_test.go
eeasaa01 2b68e57
Fix merge conflict
amdurh05 f7f3445
readding artifactory add functionality
amdurh05 f93213b
Updating delete function and changing Artifactory filename to SRI format
amdurh05 8301d12
Fix bug in AddResource
amdurh05 534d546
Fix Artifactory download logic and tests for resource cache behavior
eeasaa01 9344f52
Update resource.go
eeasaa01 01d5f3e
Update lock.go
eeasaa01 1f5cf14
Update artifactory_cache_test.go
eeasaa01 2d597ba
Update lock.go
eeasaa01 738ec4b
Delete grsbit
eeasaa01 ba91254
refactor: replace http client with requests library in lock.go
eeasaa01 fb7c978
fix: update logic in lock.go
eeasaa01 79d9e43
WIP: Save local changes before pulling
eeasaa01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// artifactory_test.go | ||
package internal | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/base64" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/cisco-open/grabit/test" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAddWithArtifactoryCache(t *testing.T) { | ||
t.Run("TokenNotSet", func(t *testing.T) { | ||
os.Unsetenv("GRABIT_ARTIFACTORY_TOKEN") | ||
|
||
handler := func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(`test content`)) | ||
} | ||
port, server := test.HttpHandler(handler) | ||
defer server.Close() | ||
|
||
path := test.TmpFile(t, "") | ||
lock, err := NewLock(path, true) | ||
require.NoError(t, err) | ||
|
||
// Use a testing server | ||
sourceURL := fmt.Sprintf("http://localhost:%d/test.txt", port) | ||
cacheURL := fmt.Sprintf("http://localhost:%d", port) | ||
|
||
err = lock.AddResource([]string{sourceURL}, "sha256", []string{}, "", cacheURL) | ||
assert.Contains(t, err.Error(), "GRABIT_ARTIFACTORY_TOKEN environment variable is not set") | ||
}) | ||
} | ||
func TestDownloadWithArtifactoryCache(t *testing.T) { | ||
t.Run("NO_CACHE_UPLOAD", func(t *testing.T) { | ||
// Turn on NO_CACHE_UPLOAD setting | ||
os.Setenv("NO_CACHE_UPLOAD", "1") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use https://pkg.go.dev/testing#B.Setenv instead. This guarantees that it gets restored after the test runs. |
||
defer os.Unsetenv("NO_CACHE_UPLOAD") | ||
|
||
testContent := []byte("test content") | ||
hash := sha256.Sum256(testContent) | ||
expectedHash := "sha256-" + base64.StdEncoding.EncodeToString(hash[:]) | ||
|
||
// Start a test server | ||
uploadAttempted := false | ||
handler := func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == "PUT" { | ||
uploadAttempted = true | ||
t.Error("Should not attempt upload when NO_CACHE_UPLOAD is set") | ||
} | ||
w.Write(testContent) | ||
} | ||
port, server := test.HttpHandler(handler) | ||
defer server.Close() | ||
|
||
// Make a test folder | ||
tmpDir := test.TmpDir(t) | ||
|
||
// Make a test lock file with a cache URL and correct hash | ||
lockContent := fmt.Sprintf(`[[Resource]] | ||
Urls = ['http://localhost:%d/test.txt'] | ||
Integrity = '%s' | ||
CacheUri = 'http://localhost:%d/cache'`, port, expectedHash, port) | ||
|
||
// Set up the lock file | ||
lockPath := test.TmpFile(t, lockContent) | ||
lock, err := NewLock(lockPath, false) | ||
require.NoError(t, err) | ||
|
||
// Check the download process | ||
err = lock.Download(tmpDir, []string{}, []string{}, "") | ||
assert.NoError(t, err) | ||
|
||
// Make sure no upload happened | ||
assert.False(t, uploadAttempted) | ||
|
||
// Make sure the file downloaded properly | ||
downloadedFile := filepath.Join(tmpDir, "test.txt") | ||
assert.FileExists(t, downloadedFile) | ||
|
||
// Make sure the content is the same | ||
content, err := os.ReadFile(downloadedFile) | ||
require.NoError(t, err) | ||
assert.Equal(t, testContent, content) | ||
}) | ||
} | ||
|
||
func TestDeleteWithArtifactoryCache(t *testing.T) { | ||
t.Run("SuccessfulDelete", func(t *testing.T) { | ||
os.Setenv("GRABIT_ARTIFACTORY_TOKEN", "test-token") | ||
defer os.Unsetenv("GRABIT_ARTIFACTORY_TOKEN") | ||
|
||
// Start the test server | ||
handler := func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == "DELETE" { | ||
w.WriteHeader(http.StatusOK) | ||
} | ||
} | ||
port, server := test.HttpHandler(handler) | ||
defer server.Close() | ||
|
||
url := fmt.Sprintf("http://localhost:%d/test.txt", port) | ||
cacheUrl := fmt.Sprintf("http://localhost:%d", port) | ||
|
||
tmpDir := test.TmpDir(t) | ||
lockContent := fmt.Sprintf(`[[Resource]] | ||
Urls = ['%s'] | ||
Integrity = 'sha256-test' | ||
CacheUri = '%s'`, url, cacheUrl) | ||
|
||
lockPath := filepath.Join(tmpDir, "grabit.lock") | ||
err := os.WriteFile(lockPath, []byte(lockContent), 0644) | ||
require.NoError(t, err) | ||
|
||
lock, err := NewLock(lockPath, false) | ||
require.NoError(t, err) | ||
|
||
// Keep the starting state | ||
err = lock.Save() | ||
require.NoError(t, err) | ||
|
||
lock.DeleteResource(url) | ||
|
||
// Keep the updates | ||
err = lock.Save() | ||
require.NoError(t, err) | ||
|
||
// Make sure the resource was deleted | ||
newLock, err := NewLock(lockPath, false) | ||
require.NoError(t, err) | ||
assert.Equal(t, 0, len(newLock.conf.Resource)) | ||
}) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is poorly named, but let's not rename it as part of this PR -- let's rename it in a separate PR.