poshbotio / PoshBot

Powershell-based bot framework
MIT License
537 stars 108 forks source link

Middleware Configurations are not Importing #133

Closed Bizarrorollins closed 5 years ago

Bizarrorollins commented 5 years ago

Middleware Configurations set in a Poshbot Configuration file are not being loaded using the Get-PoshBotConfiguration command

Expected Behavior

Middleware Configuration should be imported and set within $config.middlewareconfiguration

Current Behavior

Any middleware configurations appear to be ignored and need to be loaded separately from the configuration file setup

Possible Solution

Steps to Reproduce (for bugs)

PS> cat c:\poshbot\config\config.psd1
....
  MiddlewareConfiguration = @{
    PostResponseHooks = @()
    PreExecuteHooks = @()
    PostReceiveHooks = @()
    PreReceiveHooks = @()
    PostExecuteHooks = @(@{
      Name = 'logging'
      Path = 'C:\poshbot\middleware\logging.ps1'
    })
    PreResponseHooks = @()
  }
....

PS> $config = Get-PoshBotConfiguration -Path c:\poshbot\config\config.psd1
PS> $config.middlewareconfiguration

PreReceiveHooks   : {}
PostReceiveHooks  : {}
PreExecuteHooks   : {}
PostExecuteHooks  : {}
PreResponseHooks  : {}
PostResponseHooks : {}

PS> $logs = New-PoshBotMiddlewareHook -Name Logs -Path c:\poshbot\middleware\logging.ps1
PS> $config.MiddlewareConfiguration.Add($logs,'PostExecute')
PS> $config.middlewareconfiguration

PreReceiveHooks   : {}
PostReceiveHooks  : {}
PreExecuteHooks   : {}
PostExecuteHooks  : {Logs}
PreResponseHooks  : {}
PostResponseHooks : {}

Context

I have added a new step in my startup script which performs the middleware configuration, but this should be enabled during initial import

Your Environment

devblackops commented 5 years ago

@Bizarrorollins When defining the middleware hooks in the configuration file, you'll need to use the following names, just drop Hooks from the end. Notes that these can also be an array of hashtables like in the PostExecute example below.

MiddlewareConfiguration = @{
    PreResponse = @{
      Name = 'preresponse'
      Path = 'C:\poshbot\middleware\preresponse.ps1'
    }
    PostResponse = @{
      Name = 'postresponse'
      Path = 'C:\poshbot\middleware\postresponse.ps1'
    }
    PostReceive = @{
      Name = 'postreceive'
      Path = 'C:\poshbot\middleware\postreceive.ps1'
    }
    PreExecute = @{
      Name = 'preexecute'
      Path = 'C:\poshbot\middleware\preexecute.ps1'
    }
    PreReceive = @{
      Name = 'dropuser'
      Path = 'C:\poshbot\middleware\prereceive.ps1'
    }
    PostExecute = @(
      @{
        Name = 'postexecute'
        Path = 'C:\poshbot\middleware\postexecute.ps1'
      }
      @{
        Name = 'postexecute2'
        Path = 'C:\poshbot\middleware\postexecute2.ps1'
      }
    )
  }
Bizarrorollins commented 5 years ago

Oh Ok. I will give that a try. I should mention that the configuration file was not generated by hand and this created using Save-PoshBotConfiguration although admittedly it may have originally been created using a pre-0.11.1 version of the module.