Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware Configurations are not Importing #133

Closed
Bizarrorollins opened this issue Nov 13, 2018 · 2 comments
Closed

Middleware Configurations are not Importing #133

Bizarrorollins opened this issue Nov 13, 2018 · 2 comments

Comments

@Bizarrorollins
Copy link

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

  • Module version used: PoshBot 0.11.3 / 0.11.1
  • Operating System and PowerShell version: PSVersion 5.1.14393.2515 (Windows 10) / 5.1.14393.2214 (Windows 2016)
@devblackops
Copy link
Member

@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.

  • PreReceive
  • PostReceive
  • PreExecute
  • PostExecute
  • PreResponse
  • PostResponse
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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants