github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/dashboard/dashboardserver/types.go (about)

     1  package dashboardserver
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/turbot/steampipe/pkg/control/controlstatus"
     6  	"github.com/turbot/steampipe/pkg/dashboard/dashboardtypes"
     7  	"github.com/turbot/steampipe/pkg/steampipeconfig"
     8  	"gopkg.in/olahol/melody.v1"
     9  	"time"
    10  )
    11  
    12  type ListenType string
    13  
    14  const (
    15  	ListenTypeLocal   ListenType = "local"
    16  	ListenTypeNetwork ListenType = "network"
    17  )
    18  
    19  // IsValid is a validator for ListenType known values
    20  func (lt ListenType) IsValid() error {
    21  	switch lt {
    22  	case ListenTypeNetwork, ListenTypeLocal:
    23  		return nil
    24  	}
    25  	return fmt.Errorf("invalid listen type. Must be one of '%v' or '%v'", ListenTypeNetwork, ListenTypeLocal)
    26  }
    27  
    28  type ListenPort int
    29  
    30  // IsValid is a validator for ListenType known values
    31  func (lp ListenPort) IsValid() error {
    32  	if lp < 1 || lp > 65535 {
    33  		return fmt.Errorf("invalid port - must be within range (1:65535)")
    34  	}
    35  	return nil
    36  }
    37  
    38  type ErrorPayload struct {
    39  	Action string `json:"action"`
    40  	Error  string `json:"error"`
    41  }
    42  
    43  var ExecutionStartedSchemaVersion int64 = 20221222
    44  
    45  type ExecutionStartedPayload struct {
    46  	SchemaVersion string                           `json:"schema_version"`
    47  	Action        string                           `json:"action"`
    48  	ExecutionId   string                           `json:"execution_id"`
    49  	Panels        map[string]any                   `json:"panels"`
    50  	Layout        *dashboardtypes.SnapshotTreeNode `json:"layout"`
    51  	Inputs        map[string]interface{}           `json:"inputs,omitempty"`
    52  	Variables     map[string]string                `json:"variables,omitempty"`
    53  	StartTime     time.Time                        `json:"start_time"`
    54  }
    55  
    56  var LeafNodeUpdatedSchemaVersion int64 = 20221222
    57  
    58  type LeafNodeUpdatedPayload struct {
    59  	SchemaVersion string         `json:"schema_version"`
    60  	Action        string         `json:"action"`
    61  	DashboardNode map[string]any `json:"dashboard_node"`
    62  	ExecutionId   string         `json:"execution_id"`
    63  	Timestamp     time.Time      `json:"timestamp"`
    64  }
    65  
    66  type ControlEventPayload struct {
    67  	Action      string                                 `json:"action"`
    68  	Control     controlstatus.ControlRunStatusProvider `json:"control"`
    69  	Name        string                                 `json:"name"`
    70  	Progress    *controlstatus.ControlProgress         `json:"progress"`
    71  	ExecutionId string                                 `json:"execution_id"`
    72  	Timestamp   time.Time                              `json:"timestamp"`
    73  }
    74  
    75  type ExecutionErrorPayload struct {
    76  	Action    string    `json:"action"`
    77  	Error     string    `json:"error"`
    78  	Timestamp time.Time `json:"timestamp"`
    79  }
    80  
    81  var ExecutionCompletePayloadSchemaVersion int64 = 20221222
    82  
    83  type ExecutionCompletePayload struct {
    84  	Action        string                            `json:"action"`
    85  	SchemaVersion string                            `json:"schema_version"`
    86  	Snapshot      *dashboardtypes.SteampipeSnapshot `json:"snapshot"`
    87  	ExecutionId   string                            `json:"execution_id"`
    88  }
    89  
    90  type DisplaySnapshotPayload struct {
    91  	Action        string `json:"action"`
    92  	SchemaVersion string `json:"schema_version"`
    93  	// snapshot is a map here as we cannot deserialise SteampipeSnapshot into a struct
    94  	// (without custom deserialisation code) as the Panels property is an interface
    95  	Snapshot    map[string]any `json:"snapshot"`
    96  	ExecutionId string         `json:"execution_id"`
    97  }
    98  
    99  type InputValuesClearedPayload struct {
   100  	Action        string   `json:"action"`
   101  	ClearedInputs []string `json:"cleared_inputs"`
   102  	ExecutionId   string   `json:"execution_id"`
   103  }
   104  
   105  type DashboardClientInfo struct {
   106  	Session         *melody.Session
   107  	Dashboard       *string
   108  	DashboardInputs map[string]interface{}
   109  }
   110  
   111  type ClientRequestDashboardPayload struct {
   112  	FullName string `json:"full_name"`
   113  }
   114  
   115  type ClientRequestPayload struct {
   116  	Dashboard    ClientRequestDashboardPayload `json:"dashboard"`
   117  	InputValues  map[string]interface{}        `json:"input_values"`
   118  	ChangedInput string                        `json:"changed_input"`
   119  }
   120  
   121  type ClientRequest struct {
   122  	Action  string               `json:"action"`
   123  	Payload ClientRequestPayload `json:"payload"`
   124  }
   125  
   126  type ModAvailableDashboard struct {
   127  	Title       string            `json:"title,omitempty"`
   128  	FullName    string            `json:"full_name"`
   129  	ShortName   string            `json:"short_name"`
   130  	Tags        map[string]string `json:"tags"`
   131  	ModFullName string            `json:"mod_full_name"`
   132  }
   133  
   134  type ModAvailableBenchmark struct {
   135  	Title       string                  `json:"title,omitempty"`
   136  	FullName    string                  `json:"full_name"`
   137  	ShortName   string                  `json:"short_name"`
   138  	Tags        map[string]string       `json:"tags"`
   139  	IsTopLevel  bool                    `json:"is_top_level"`
   140  	Children    []ModAvailableBenchmark `json:"children,omitempty"`
   141  	Trunks      [][]string              `json:"trunks"`
   142  	ModFullName string                  `json:"mod_full_name"`
   143  }
   144  
   145  type AvailableDashboardsPayload struct {
   146  	Action     string                           `json:"action"`
   147  	Dashboards map[string]ModAvailableDashboard `json:"dashboards"`
   148  	Benchmarks map[string]ModAvailableBenchmark `json:"benchmarks"`
   149  	Snapshots  map[string]string                `json:"snapshots"`
   150  }
   151  
   152  type ModDashboardMetadata struct {
   153  	Title     string `json:"title,omitempty"`
   154  	FullName  string `json:"full_name"`
   155  	ShortName string `json:"short_name"`
   156  }
   157  
   158  type DashboardCLIMetadata struct {
   159  	Version string `json:"version,omitempty"`
   160  }
   161  
   162  type DashboardMetadata struct {
   163  	Mod           *ModDashboardMetadata           `json:"mod,omitempty"`
   164  	InstalledMods map[string]ModDashboardMetadata `json:"installed_mods,omitempty"`
   165  	CLI           DashboardCLIMetadata            `json:"cli"`
   166  	Cloud         *steampipeconfig.CloudMetadata  `json:"cloud,omitempty"`
   167  	Telemetry     string                          `json:"telemetry"`
   168  }
   169  
   170  type DashboardMetadataPayload struct {
   171  	Action   string            `json:"action"`
   172  	Metadata DashboardMetadata `json:"metadata"`
   173  }