module Inspec::Schema::Primitives

Constants

CONTROL_GROUP

Represents a group of controls within a profile/.rb file

DEPENDENCY

Profile dependencies

GENERATOR

Explains what software ran the inspec profile/made this file. Typically inspec but could in theory be a different software

IMPACT

Within a control file, impacts can be numeric 0-1 or string in [none,low,medium,high,critical] However, when they are output, the string types are automatically converted as follows: none -> 0 to 0.01 low -> 0.01 to 0.4 medium -> 0.4 to 0.7 high -> 0.7 to 0.9 Critical -> 0.9 to 1.0 (inclusive)

INPUT

Attributes/Inputs specify the inputs to a profile.

NULL
NUMBER
OBJECT
Establish basic type shorthands for this schema ########################################

These three are essentially primitives, used as shorthand

PLATFORM

Represents the platform the test was run on

REFERENCE

References an external document

SOURCE_LOCATION

Occurs from “exec –reporter json” and “inspec json” Denotes what file this control comes from, and where within

STATISTICS

Contains statistics of an exec run.

STATISTIC_GROUPING

Bundles several results statistics, representing distinct groups of controls

STATISTIC_ITEM

We use “title” to name the type. and “description” (via the describe function) to describe its particular usage Summary item containing run statistics about a subset of the controls

STATUS

A status for a control

STRING
SUPPORT

Occurs from “inspec exec –reporter json” and “inspec json” Represents a platfrom or group of platforms that this profile supports

TAGS

A controls tags can have any number of properties, and any sorts of values

URL

We might eventually enforce string format stuff on this

Public Class Methods

array(of_type) click to toggle source

Use this function to easily make an array of a type

# File lib/inspec/schema/primitives.rb, line 15
def self.array(of_type)
  {
    "type" => "array",
    "items" => of_type,
  }
end
desc(obj, description) click to toggle source
Establish simple helpers for this schema ########################################

Use this function to easily make described types

# File lib/inspec/schema/primitives.rb, line 10
def self.desc(obj, description)
  obj.merge({ "description" => description })
end
validate_schema(schema) click to toggle source

This function performs some simple validation on schemas, to catch obvious missed requirements

# File lib/inspec/schema/primitives.rb, line 23
def self.validate_schema(schema)
  return if schema["type"] != "object"
  raise "Objects in schema must have a \"required\" property, even if it is empty." unless schema.key?("required")

  return if schema["required"].empty?
  raise "An object with required properties must have a properties hash." unless schema.key?("properties")

  return if Set.new(schema["required"]) <= Set.new(schema["properties"].keys)

  raise "Not all required properties are present."
end