Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bram Hagens
api
Commits
115c5bf6
Commit
115c5bf6
authored
5 years ago
by
Dean
Browse files
Options
Downloads
Patches
Plain Diff
version 1.7.1: add fileWebhook feature
parent
4b8ebb54
No related branches found
Branches containing commit
Tags
v1.4.0
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config.sample.toml
+9
-0
9 additions, 0 deletions
config.sample.toml
lib/routes/uploadpomf.go
+28
-0
28 additions, 0 deletions
lib/routes/uploadpomf.go
main.go
+4
-0
4 additions, 0 deletions
main.go
with
41 additions
and
0 deletions
config.sample.toml
+
9
−
0
View file @
115c5bf6
...
...
@@ -20,3 +20,12 @@ tempLocation = "/var/data/buckets/_temp"
storageLocation
=
"/var/data/buckets/data"
quarantineLocation
=
"/var/data/buckets/_quarantine"
[fileWebhook]
# URL will receive POST with JSON body containing only a `sha256_hash` key for each NEW file
enable
=
false
url
=
"http://localhost:3100/scan"
[ratelimiter]
enable
=
true
redisURL
=
"redis://localhost:6379/0"
This diff is collapsed.
Click to expand it.
lib/routes/uploadpomf.go
+
28
−
0
View file @
115c5bf6
package
routes
import
(
"bytes"
"crypto/md5"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"io"
"net/http"
"os"
...
...
@@ -68,6 +70,11 @@ type fullResponse struct {
Files
[]
fileResponse
`json:"files"`
}
// fileWebhookRequest represents the data submitted in a file webhook request.
type
fileWebhookRequest
struct
{
SHA256Hash
string
`json:"sha256_hash"`
}
// UploadPomf handles Pomf multipart/form-data upload requests.
func
UploadPomf
(
associateObjectsWithUser
bool
)
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -270,6 +277,27 @@ func UploadPomf(associateObjectsWithUser bool) func(http.ResponseWriter, *http.R
Name
:
file
.
Filename
,
})
}
// Fire fileWebhook in goroutine
if
viper
.
GetBool
(
"fileWebhook.enable"
)
{
go
func
()
{
reqData
:=
fileWebhookRequest
{
hex
.
EncodeToString
(
sha256Bytes
)}
m
,
err
:=
json
.
Marshal
(
reqData
)
if
err
!=
nil
{
log
.
Warn
()
.
Err
(
err
)
.
Msg
(
"failed to marshal reqData in fileWebhook goroutine"
)
return
}
buf
:=
bytes
.
NewBuffer
(
m
)
resp
,
err
:=
http
.
Post
(
viper
.
GetString
(
"fileWebhook.url"
),
"application/json"
,
buf
)
if
err
!=
nil
{
log
.
Warn
()
.
Err
(
err
)
.
Msg
(
"failed to send request in fileWebhook goroutine"
)
return
}
if
resp
.
StatusCode
<
200
||
resp
.
StatusCode
>
399
{
log
.
Warn
()
.
Msgf
(
"got unexpected status code from fileWebhook url: %v"
,
resp
.
StatusCode
)
}
}()
}
}
else
{
// Delete temporary file
err
=
os
.
Remove
(
tempPath
)
...
...
This diff is collapsed.
Click to expand it.
main.go
+
4
−
0
View file @
115c5bf6
...
...
@@ -73,6 +73,7 @@ func init() {
viper
.
SetDefault
(
"ratelimiter.listObjectsCost"
,
ratelimiter
.
ListObjectsCost
)
viper
.
SetDefault
(
"ratelimiter.objectCost"
,
ratelimiter
.
ObjectCost
)
viper
.
SetDefault
(
"ratelimiter.deleteObjectCost"
,
ratelimiter
.
DeleteObjectCost
)
viper
.
SetDefault
(
"fileWebhook.enable"
,
false
)
// Load configuration file
viper
.
SetConfigType
(
"toml"
)
...
...
@@ -138,6 +139,9 @@ func init() {
if
viper
.
GetBool
(
"ratelimiter.enable"
)
&&
viper
.
GetString
(
"ratelimiter.redisURL"
)
==
""
{
log
.
Fatal
()
.
Msg
(
"Configuration: ratelimiter.redisURL is required when ratelimiter is enabled"
)
}
if
viper
.
GetBool
(
"fileWebhook.enable"
)
&&
viper
.
GetString
(
"fileWebhook.url"
)
==
""
{
log
.
Fatal
()
.
Msg
(
"Configuration: fileWebhook.url is required when fileWebhook is enabled"
)
}
}
func
main
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment