Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ jobs:
contents: read
security-events: write # for reporting vulnerabilities via code-scanning API
with:
# Use PR head branch (the feature branch) when running from a pull_request event.
# Fallback to github.head_ref (sanity) or ref name for other contexts.
target-branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref_name }}
# Use PR head SHA for pull requests (supports PRs from forks).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not familiar with this repos workflows, so maybe someone from the agent team can take a look and see why this is necessary

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

# Fallback to ref name for other contexts.
target-branch: ${{ github.event.pull_request.head.sha || github.ref_name }}

unit-test:
name: Unit Tests
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/vulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ jobs:
runs-on: ubuntu-22.04
permissions:
security-events: write # for reporting vulnerabilities via code-scanning API
env:
GOPROXY: "https://proxy.golang.org,direct"
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
# For a pull_request event use the PR head branch (github.head_ref)
# to this ensures vulncheck runs against the feature branch.
# Otherwise, fall back to inputs.target-branch, github.ref_name, then 'main'.
ref: ${{ (github.event_name == 'pull_request' && github.head_ref) || inputs.target-branch || github.ref_name || 'main' }}
# Use inputs.target-branch which can be a branch name or SHA.
# Falls back to github.ref_name or 'main' if not provided.
ref: ${{ inputs.target-branch || github.ref_name || 'main' }}

- name: Check Go version
id: get-go-version
Expand Down
8 changes: 8 additions & 0 deletions internal/file/external_file_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/gabriel-vasile/mimetype"
mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
"github.com/nginx/agent/v3/internal/model"
"github.com/nginx/agent/v3/pkg/files"
)

type ExternalFileOperator struct {
Expand Down Expand Up @@ -50,6 +51,7 @@ func (efo *ExternalFileOperator) DownloadExternalFile(ctx context.Context, fileA
var contentToWrite []byte
var downloadErr, updateError error
var headers DownloadHeader
var hash string

contentToWrite, headers, downloadErr = efo.downloadFileContent(ctx, fileAction.File)

Expand Down Expand Up @@ -93,6 +95,12 @@ func (efo *ExternalFileOperator) DownloadExternalFile(ctx context.Context, fileA
return fmt.Errorf("failed to write downloaded content to temp file %s: %w", filePath, writeErr)
}

hash = files.GenerateHash(contentToWrite)
slog.InfoContext(ctx, "Successfully downloaded external file",
"event_tag", externalFileEventTag,
"location", location,
"hash", hash)

return nil
}

Expand Down
13 changes: 12 additions & 1 deletion internal/file/file_manager_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
dirPerm = 0o755
filePerm = 0o600
executePerm = 0o111
// externalFileEventTag is used for internal event generation
externalFileEventTag = "ID-1310"
)

type DownloadHeader struct {
Expand Down Expand Up @@ -651,6 +653,7 @@ func (fms *FileManagerService) executeFileActions(ctx context.Context) (actionEr
return actionError
}

//nolint:revive // adding error logs increased cog. complexity
func (fms *FileManagerService) downloadUpdatedFilesToTempLocation(ctx context.Context) (updateError error) {
var downloadFiles []*model.FileCache
for _, fileAction := range fms.fileActions {
Expand All @@ -674,7 +677,15 @@ func (fms *FileManagerService) downloadUpdatedFilesToTempLocation(ctx context.Co

switch fileAction.Action {
case model.ExternalFile:
return fms.externalFileOperator.DownloadExternalFile(errGroupCtx, fileAction, tempFilePath)
err := fms.externalFileOperator.DownloadExternalFile(errGroupCtx, fileAction, tempFilePath)
if err != nil {
slog.ErrorContext(ctx, "Failed to download external file",
"event_tag", externalFileEventTag,
"location", fileAction.File.GetExternalDataSource().GetLocation(),
"err", err)
}

return err
case model.Add, model.Update:
slog.DebugContext(
errGroupCtx,
Expand Down
Loading