github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/export/snapshot_exporter.go (about)

     1  package export
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"strings"
     7  
     8  	"github.com/turbot/steampipe/pkg/constants"
     9  	"github.com/turbot/steampipe/pkg/dashboard/dashboardtypes"
    10  )
    11  
    12  type SnapshotExporter struct {
    13  	ExporterBase
    14  }
    15  
    16  func (e *SnapshotExporter) Export(_ context.Context, input ExportSourceData, filePath string) error {
    17  	snapshot, ok := input.(*dashboardtypes.SteampipeSnapshot)
    18  	if !ok {
    19  		return fmt.Errorf("SnapshotExporter input must be *dashboardtypes.SteampipeSnapshot")
    20  	}
    21  	snapshotBytes, err := snapshot.AsStrippedJson(false)
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	res := strings.NewReader(fmt.Sprintf("%s\n", string(snapshotBytes)))
    27  
    28  	return Write(filePath, res)
    29  }
    30  
    31  func (e *SnapshotExporter) FileExtension() string {
    32  	return constants.SnapshotExtension
    33  }
    34  
    35  func (e *SnapshotExporter) Name() string {
    36  	return constants.OutputFormatSnapshot
    37  }
    38  
    39  func (*SnapshotExporter) Alias() string {
    40  	return "sps"
    41  }