github.com/crowdsecurity/crowdsec@v1.6.1/scripts/test_env.ps1 (about)

     1  #this is is straight up conversion of test_env.sh, not pretty but does the job
     2  
     3  param (
     4      [string]$base = ".\tests",
     5      [switch]$help = $false
     6  )
     7  
     8  function show_help() {
     9      Write-Output ".\test_env.ps1 -d tests #creates test env in .\tests"
    10  }
    11  
    12  function create_tree() {
    13  	$null = New-Item -ItemType Directory $data_dir
    14  	$null = New-Item -ItemType Directory $log_dir
    15  	$null = New-Item -ItemType Directory $config_dir
    16  	$null = New-Item -ItemType Directory $parser_dir
    17  	$null = New-Item -ItemType Directory $parser_s00
    18  	$null = New-Item -ItemType Directory $parser_s01
    19  	$null = New-Item -ItemType Directory $parser_s02
    20  	$null = New-Item -ItemType Directory $scenarios_dir
    21  	$null = New-Item -ItemType Directory $postoverflows_dir
    22  	$null = New-Item -ItemType Directory $cscli_dir
    23  	$null = New-Item -ItemType Directory $hub_dir
    24      $null = New-Item -ItemType Directory $config_dir\$notif_dir
    25  	$null = New-Item -ItemType Directory $base\$plugins_dir
    26  }
    27  
    28  function copy_file() {
    29      $null = Copy-Item ".\config\profiles.yaml" $config_dir
    30  	$null = Copy-Item  ".\config\simulation.yaml" $config_dir
    31  	$null = Copy-Item ".\cmd\crowdsec\crowdsec.exe" $base
    32  	$null = Copy-Item ".\cmd\crowdsec-cli\cscli.exe" $base
    33  	$null = Copy-Item -Recurse ".\config\patterns" $config_dir
    34  	$null = Copy-Item ".\config\acquis.yaml" $config_dir
    35  	$null = New-Item -ItemType File $config_dir\local_api_credentials.yaml
    36  	$null = New-Item -ItemType File $config_dir\online_api_credentials.yaml
    37  	#envsubst < "./config/dev.yaml" > $BASE/dev.yaml
    38      Copy-Item .\config\dev.yaml $base\dev.yaml
    39      $plugins | ForEach-Object {
    40          Copy-Item .\cmd\notification-$_\notification-$_.exe $base\$plugins_dir\notification-$_.exe
    41  		Copy-Item .\cmd\notification-$_\$_.yaml $config_dir\$notif_dir\$_.yaml
    42      }
    43  }
    44  
    45  function setup() {
    46  	& $base\cscli.exe -c "$config_file" hub update
    47  	& $base\cscli.exe -c "$config_file" collections install crowdsecurity/linux crowdsecurity/windows
    48  }
    49  
    50  function setup_api() {
    51  	& $base\cscli.exe -c "$config_file" machines add test -p testpassword -f $config_dir\local_api_credentials.yaml --force
    52  }
    53  
    54  if ($help) {
    55      show_help
    56      exit 0;
    57  }
    58  
    59  $null = New-Item -ItemType Directory $base
    60  
    61  $base=(Resolve-Path $base).Path
    62  $data_dir="$base\data"
    63  $log_dir="$base\logs\"
    64  $config_dir="$base\config"
    65  $config_file="$base\dev.yaml"
    66  $cscli_dir="$config_dir\crowdsec-cli"
    67  $parser_dir="$config_dir\parsers"
    68  $parser_s00="$parser_dir\s00-raw"
    69  $parser_s01="$parser_dir\s01-parse"
    70  $parser_s02="$parser_dir\s02-enrich"
    71  $scenarios_dir="$config_dir\scenarios"
    72  $postoverflows_dir="$config_dir\postoverflows"
    73  $hub_dir="$config_dir\hub"
    74  $plugins=@("http", "slack", "splunk", "email", "sentinel")
    75  $plugins_dir="plugins"
    76  $notif_dir="notifications"
    77  
    78  
    79  Write-Output "Creating test tree in $base"
    80  create_tree
    81  Write-Output "Tree created"
    82  Write-Output "Copying files"
    83  copy_file
    84  Write-Output "Files copied"
    85  Write-Output "Setting up configuration"
    86  $cur_path=$pwd
    87  Set-Location $base
    88  setup_api
    89  setup
    90  Set-Location $cur_path