github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/steampipeconfig/parse/schema.go (about)

     1  package parse
     2  
     3  import (
     4  	"github.com/hashicorp/hcl/v2"
     5  	"github.com/turbot/steampipe/pkg/steampipeconfig/modconfig"
     6  )
     7  
     8  // cache resource schemas
     9  var resourceSchemaCache = make(map[string]*hcl.BodySchema)
    10  
    11  var ConfigBlockSchema = &hcl.BodySchema{
    12  	Attributes: []hcl.AttributeSchema{},
    13  	Blocks: []hcl.BlockHeaderSchema{
    14  		{
    15  			Type:       modconfig.BlockTypeConnection,
    16  			LabelNames: []string{"name"},
    17  		},
    18  		{
    19  			Type:       modconfig.BlockTypePlugin,
    20  			LabelNames: []string{"name"},
    21  		},
    22  		{
    23  			Type:       modconfig.BlockTypeOptions,
    24  			LabelNames: []string{"type"},
    25  		},
    26  		{
    27  			Type:       modconfig.BlockTypeWorkspaceProfile,
    28  			LabelNames: []string{"name"},
    29  		},
    30  	},
    31  }
    32  var PluginBlockSchema = &hcl.BodySchema{
    33  	Attributes: []hcl.AttributeSchema{},
    34  	Blocks: []hcl.BlockHeaderSchema{
    35  		{
    36  			Type:       modconfig.BlockTypeRateLimiter,
    37  			LabelNames: []string{"name"},
    38  		},
    39  	},
    40  }
    41  
    42  var WorkspaceProfileBlockSchema = &hcl.BodySchema{
    43  
    44  	Blocks: []hcl.BlockHeaderSchema{
    45  		{
    46  			Type:       "options",
    47  			LabelNames: []string{"type"},
    48  		},
    49  	},
    50  }
    51  
    52  var ConnectionBlockSchema = &hcl.BodySchema{
    53  	Attributes: []hcl.AttributeSchema{
    54  		{
    55  			Name:     "plugin",
    56  			Required: true,
    57  		},
    58  		{
    59  			Name: "type",
    60  		},
    61  		{
    62  			Name: "connections",
    63  		},
    64  		{
    65  			Name: "import_schema",
    66  		},
    67  	},
    68  	Blocks: []hcl.BlockHeaderSchema{
    69  		{
    70  			Type:       "options",
    71  			LabelNames: []string{"type"},
    72  		},
    73  	},
    74  }
    75  
    76  // WorkspaceBlockSchema is the top level schema for all workspace resources
    77  var WorkspaceBlockSchema = &hcl.BodySchema{
    78  	Attributes: []hcl.AttributeSchema{},
    79  	Blocks: []hcl.BlockHeaderSchema{
    80  		{
    81  			Type:       string(modconfig.BlockTypeMod),
    82  			LabelNames: []string{"name"},
    83  		},
    84  		{
    85  			Type:       modconfig.BlockTypeVariable,
    86  			LabelNames: []string{"name"},
    87  		},
    88  		{
    89  			Type:       modconfig.BlockTypeQuery,
    90  			LabelNames: []string{"name"},
    91  		},
    92  		{
    93  			Type:       modconfig.BlockTypeControl,
    94  			LabelNames: []string{"name"},
    95  		},
    96  		{
    97  			Type:       modconfig.BlockTypeBenchmark,
    98  			LabelNames: []string{"name"},
    99  		},
   100  		{
   101  			Type:       modconfig.BlockTypeDashboard,
   102  			LabelNames: []string{"name"},
   103  		},
   104  		{
   105  			Type:       modconfig.BlockTypeCard,
   106  			LabelNames: []string{"name"},
   107  		},
   108  		{
   109  			Type:       modconfig.BlockTypeChart,
   110  			LabelNames: []string{"name"},
   111  		},
   112  		{
   113  			Type:       modconfig.BlockTypeFlow,
   114  			LabelNames: []string{"name"},
   115  		},
   116  		{
   117  			Type:       modconfig.BlockTypeGraph,
   118  			LabelNames: []string{"name"},
   119  		},
   120  		{
   121  			Type:       modconfig.BlockTypeHierarchy,
   122  			LabelNames: []string{"name"},
   123  		},
   124  		{
   125  			Type:       modconfig.BlockTypeImage,
   126  			LabelNames: []string{"name"},
   127  		},
   128  		{
   129  			Type:       modconfig.BlockTypeInput,
   130  			LabelNames: []string{"name"},
   131  		},
   132  		{
   133  			Type:       modconfig.BlockTypeTable,
   134  			LabelNames: []string{"name"},
   135  		},
   136  		{
   137  			Type:       modconfig.BlockTypeText,
   138  			LabelNames: []string{"name"},
   139  		},
   140  		{
   141  			Type:       modconfig.BlockTypeNode,
   142  			LabelNames: []string{"name"},
   143  		},
   144  		{
   145  			Type:       modconfig.BlockTypeEdge,
   146  			LabelNames: []string{"name"},
   147  		},
   148  		{
   149  			Type: modconfig.BlockTypeLocals,
   150  		},
   151  		{
   152  			Type:       modconfig.BlockTypeCategory,
   153  			LabelNames: []string{"name"},
   154  		},
   155  	},
   156  }
   157  
   158  // DashboardBlockSchema is only used to validate the blocks of a Dashboard
   159  var DashboardBlockSchema = &hcl.BodySchema{
   160  	Blocks: []hcl.BlockHeaderSchema{
   161  		{
   162  			Type:       modconfig.BlockTypeInput,
   163  			LabelNames: []string{"name"},
   164  		},
   165  		{
   166  			Type:       modconfig.BlockTypeParam,
   167  			LabelNames: []string{"name"},
   168  		},
   169  		{
   170  			Type: modconfig.BlockTypeWith,
   171  		},
   172  		{
   173  			Type: modconfig.BlockTypeContainer,
   174  		},
   175  		{
   176  			Type: modconfig.BlockTypeCard,
   177  		},
   178  		{
   179  			Type: modconfig.BlockTypeChart,
   180  		},
   181  		{
   182  			Type: modconfig.BlockTypeBenchmark,
   183  		},
   184  		{
   185  			Type: modconfig.BlockTypeControl,
   186  		},
   187  		{
   188  			Type: modconfig.BlockTypeFlow,
   189  		},
   190  		{
   191  			Type: modconfig.BlockTypeGraph,
   192  		},
   193  		{
   194  			Type: modconfig.BlockTypeHierarchy,
   195  		},
   196  		{
   197  			Type: modconfig.BlockTypeImage,
   198  		},
   199  		{
   200  			Type: modconfig.BlockTypeTable,
   201  		},
   202  		{
   203  			Type: modconfig.BlockTypeText,
   204  		},
   205  	},
   206  }
   207  
   208  // DashboardContainerBlockSchema is only used to validate the blocks of a DashboardContainer
   209  var DashboardContainerBlockSchema = &hcl.BodySchema{
   210  	Blocks: []hcl.BlockHeaderSchema{
   211  		{
   212  			Type:       modconfig.BlockTypeInput,
   213  			LabelNames: []string{"name"},
   214  		},
   215  		{
   216  			Type:       modconfig.BlockTypeParam,
   217  			LabelNames: []string{"name"},
   218  		},
   219  		{
   220  			Type: modconfig.BlockTypeContainer,
   221  		},
   222  		{
   223  			Type: modconfig.BlockTypeCard,
   224  		},
   225  		{
   226  			Type: modconfig.BlockTypeChart,
   227  		},
   228  		{
   229  			Type: modconfig.BlockTypeBenchmark,
   230  		},
   231  		{
   232  			Type: modconfig.BlockTypeControl,
   233  		},
   234  		{
   235  			Type: modconfig.BlockTypeFlow,
   236  		},
   237  		{
   238  			Type: modconfig.BlockTypeGraph,
   239  		},
   240  		{
   241  			Type: modconfig.BlockTypeHierarchy,
   242  		},
   243  		{
   244  			Type: modconfig.BlockTypeImage,
   245  		},
   246  		{
   247  			Type: modconfig.BlockTypeTable,
   248  		},
   249  		{
   250  			Type: modconfig.BlockTypeText,
   251  		},
   252  	},
   253  }
   254  
   255  var BenchmarkBlockSchema = &hcl.BodySchema{
   256  	Attributes: []hcl.AttributeSchema{
   257  		{Name: "children"},
   258  		{Name: "description"},
   259  		{Name: "documentation"},
   260  		{Name: "tags"},
   261  		{Name: "title"},
   262  		// for report benchmark blocks
   263  		{Name: "width"},
   264  		{Name: "base"},
   265  		{Name: "type"},
   266  		{Name: "display"},
   267  	},
   268  }
   269  
   270  // QueryProviderBlockSchema schema for all blocks satisfying QueryProvider interface
   271  // NOTE: these are just the blocks/attributes that are explicitly decoded
   272  // other query provider properties are implicitly decoded using tags
   273  var QueryProviderBlockSchema = &hcl.BodySchema{
   274  	Attributes: []hcl.AttributeSchema{
   275  		{Name: "args"},
   276  	},
   277  	Blocks: []hcl.BlockHeaderSchema{
   278  		{
   279  			Type:       "param",
   280  			LabelNames: []string{"name"},
   281  		},
   282  		{
   283  			Type:       "with",
   284  			LabelNames: []string{"name"},
   285  		},
   286  	},
   287  }
   288  
   289  // NodeAndEdgeProviderSchema is used to decode graph/hierarchy/flow
   290  // (EXCEPT categories)
   291  var NodeAndEdgeProviderSchema = &hcl.BodySchema{
   292  	Attributes: []hcl.AttributeSchema{
   293  		{Name: "args"},
   294  	},
   295  	Blocks: []hcl.BlockHeaderSchema{
   296  		{
   297  			Type:       "param",
   298  			LabelNames: []string{"name"},
   299  		},
   300  		{
   301  			Type:       "category",
   302  			LabelNames: []string{"name"},
   303  		},
   304  		{
   305  			Type:       "with",
   306  			LabelNames: []string{"name"},
   307  		},
   308  		{
   309  			Type: modconfig.BlockTypeNode,
   310  		},
   311  		{
   312  			Type: modconfig.BlockTypeEdge,
   313  		},
   314  	},
   315  }
   316  
   317  var ParamDefBlockSchema = &hcl.BodySchema{
   318  	Attributes: []hcl.AttributeSchema{
   319  		{Name: "description"},
   320  		{Name: "default"},
   321  	},
   322  }
   323  
   324  var VariableBlockSchema = &hcl.BodySchema{
   325  	Attributes: []hcl.AttributeSchema{
   326  		{
   327  			Name: "description",
   328  		},
   329  		{
   330  			Name: "default",
   331  		},
   332  		{
   333  			Name: "type",
   334  		},
   335  		{
   336  			Name: "sensitive",
   337  		},
   338  	},
   339  	Blocks: []hcl.BlockHeaderSchema{
   340  		{
   341  			Type: "validation",
   342  		},
   343  	},
   344  }