Skip to content

Commit

Permalink
Merge pull request #3 from turbot/bubble
Browse files Browse the repository at this point in the history
Add DownloadedArtifactInfo with LocalName and size - this is what Loaders and Extractors accept as arg now
  • Loading branch information
kaidaguerre authored Jan 21, 2025
2 parents 3b5f449 + b22167d commit 89d62dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions sources/file_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"context"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"

"github.com/elastic/go-grok"
typehelpers "github.com/turbot/go-kit/types"
"github.com/turbot/pipe-fittings/filter"
"github.com/turbot/tailpipe-plugin-sdk/artifact_source"
"github.com/turbot/tailpipe-plugin-sdk/row_source"
"github.com/turbot/tailpipe-plugin-sdk/types"
"io/fs"
"path/filepath"
)

// register the source from the package init function
Expand Down Expand Up @@ -83,8 +85,14 @@ func (s *FileSource) DiscoverArtifacts(ctx context.Context) error {

// DownloadArtifact does nothing as the artifact already exists on the local file system
func (s *FileSource) DownloadArtifact(ctx context.Context, info *types.ArtifactInfo) error {
// notify observers of the discovered artifact
// NOTE: just pass on the info as is
// if the file was downloaded we would update the Name to the local path, leaving OriginalName as the source path
return s.OnArtifactDownloaded(ctx, info)
// for file source, the local name is the same as the name
localName := info.Name
fileInfo, err := os.Stat(localName)
if err != nil {
return fmt.Errorf("error getting file info for %s: %v", localName, err)
}
downloadInfo := types.NewDownloadedArtifactInfo(info, localName, fileInfo.Size())

// notify observers of the downloaded artifact
return s.OnArtifactDownloaded(ctx, downloadInfo)
}
2 changes: 1 addition & 1 deletion sources/file_system_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type testObserver struct {
func (t *testObserver) Notify(ctx context.Context, e events.Event) error {
switch ty := e.(type) {
case *events.ArtifactDiscovered:
t.Artifacts = append(t.Artifacts, ty.Info.OriginalName)
t.Artifacts = append(t.Artifacts, ty.Info.Name)
}
return nil
}
Expand Down

0 comments on commit 89d62dc

Please sign in to comment.