Skip to content

Commit cdd2abb

Browse files
committed
feat: webhook support read body from file
1 parent 5789fae commit cdd2abb

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

console/atest-desktop/forge.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ module.exports = {
5151
ui: {
5252
"enabled": true,
5353
"chooseDirectory": true
54+
},
55+
beforeCreate: (msiCreator) => {
56+
// Add installation directory to system PATH
57+
msiCreator.wixTemplate = msiCreator.wixTemplate.replace(
58+
'</Product>',
59+
` <Property Id="ARPINSTALLLOCATION" Value="[INSTALLDIR]" />
60+
<CustomAction Id="AddToPath" Property="PATH" Value="[INSTALLDIR]" Execute="immediate" />
61+
<CustomAction Id="RemoveFromPath" Property="PATH" Value="[INSTALLDIR]" Execute="immediate" />
62+
63+
<InstallExecuteSequence>
64+
<Custom Action="AddToPath" After="InstallFiles">NOT Installed</Custom>
65+
<Custom Action="RemoveFromPath" Before="RemoveFiles">REMOVE="ALL"</Custom>
66+
</InstallExecuteSequence>
67+
68+
<Component Id="PathComponent" Guid="*" Directory="INSTALLDIR">
69+
<Environment Id="PATH" Name="PATH" Value="[INSTALLDIR]" Permanent="no" Part="last" Action="set" System="yes" />
70+
</Component>
71+
72+
</Product>`
73+
);
5474
}
5575
}
5676
}

pkg/mock/in_memory.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,15 @@ func runWebhook(ctx context.Context, objCtx interface{}, wh *Webhook) (err error
580580
}
581581
}
582582

583+
if wh.Request.BodyFromFile != "" {
584+
if data, readErr := os.ReadFile(wh.Request.BodyFromFile); readErr != nil {
585+
memLogger.Error(readErr, "failed to read file", "file", wh.Request.BodyFromFile)
586+
return
587+
} else {
588+
wh.Request.Body = string(data)
589+
}
590+
}
591+
583592
var payload io.Reader
584593
payload, err = render.RenderAsReader("mock webhook server payload", wh.Request.Body, wh)
585594
if err != nil {

pkg/mock/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ type Item struct {
2929
}
3030

3131
type Request struct {
32-
Protocol string `yaml:"protocol" json:"protocol"`
33-
Path string `yaml:"path" json:"path"`
34-
Method string `yaml:"method" json:"method"`
35-
Header map[string]string `yaml:"header" json:"header"`
36-
Body string `yaml:"body" json:"body"`
32+
Protocol string `yaml:"protocol" json:"protocol"`
33+
Path string `yaml:"path" json:"path"`
34+
Method string `yaml:"method" json:"method"`
35+
Header map[string]string `yaml:"header" json:"header"`
36+
Body string `yaml:"body" json:"body"`
37+
BodyFromFile string `yaml:"bodyFromFile" json:"bodyFromFile"`
3738
}
3839

3940
type RequestWithAuth struct {

0 commit comments

Comments
 (0)