Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DCSG2900-ThreatTotal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Johannes Barstad
DCSG2900-ThreatTotal
Commits
05c2efcb
Commit
05c2efcb
authored
2 years ago
by
Odin K. Henriksen
Browse files
Options
Downloads
Patches
Plain Diff
Added a new check to see if filehash data is complete or not, to provide better cached results
parent
6ac6ada2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/hash-intelligence.go
+27
-11
27 additions, 11 deletions
api/hash-intelligence.go
with
27 additions
and
11 deletions
api/hash-intelligence.go
+
27
−
11
View file @
05c2efcb
...
...
@@ -16,6 +16,7 @@ func HashIntelligence(c *gin.Context) {
var
hashInt
[]
byte
var
err
error
var
completeInt
bool
hash
:=
strings
.
TrimSpace
(
c
.
Query
(
"hash"
))
...
...
@@ -28,21 +29,23 @@ func HashIntelligence(c *gin.Context) {
fmt
.
Println
(
"No Cache hit"
)
// Perform the request
hashInt
,
err
=
hashSearch
(
hash
)
hashInt
,
err
,
completeInt
=
hashSearch
(
hash
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"Error "
:
"Invalid response from third party API's."
})
return
}
// Add the data to the database
response
,
err
:=
utils
.
Conn
.
Do
(
"SETEX"
,
"hash:"
+
hash
,
utils
.
CacheDurationHash
,
hashInt
)
if
err
!=
nil
{
fmt
.
Println
(
"Error adding data to redis:"
+
err
.
Error
())
logging
.
Logerror
(
err
,
"Error adding data to redis, hash-intelligence"
)
if
completeInt
{
// Add the data to the database
response
,
err
:=
utils
.
Conn
.
Do
(
"SETEX"
,
"hash:"
+
hash
,
utils
.
CacheDurationHash
,
hashInt
)
if
err
!=
nil
{
fmt
.
Println
(
"Error adding data to redis:"
+
err
.
Error
())
logging
.
Logerror
(
err
,
"Error adding data to redis, hash-intelligence"
)
}
}
fmt
.
Println
(
response
)
fmt
.
Println
(
response
)
}
}
else
{
...
...
@@ -76,7 +79,7 @@ func HashIntelligence(c *gin.Context) {
c
.
Data
(
http
.
StatusOK
,
"application/json"
,
hashInt
)
}
func
hashSearch
(
hash
string
)
(
data
[]
byte
,
err
error
)
{
func
hashSearch
(
hash
string
)
(
data
[]
byte
,
err
error
,
complete
bool
)
{
var
wg
sync
.
WaitGroup
var
responseData
[
2
]
utils
.
FrontendResponse2
...
...
@@ -98,12 +101,25 @@ func hashSearch(hash string) (data []byte, err error) {
utils
.
SetResultHash
(
resultPointer
,
len
(
responseData
))
complete
=
checkIfIntelligenceCompleteHash
(
resultResponse
,
len
(
responseData
))
hashInt
,
err
:=
json
.
Marshal
(
resultResponse
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
logging
.
Logerror
(
err
,
""
)
return
nil
,
err
return
nil
,
err
,
complete
}
return
hashInt
,
nil
,
complete
}
func
checkIfIntelligenceCompleteHash
(
jsonData
utils
.
ResultFrontendResponse
,
size
int
)
(
complete
bool
)
{
complete
=
true
for
i
:=
0
;
i
<=
size
-
1
;
i
++
{
if
jsonData
.
FrontendResponse
[
i
]
.
EN
.
Status
==
"Awaiting analysis"
||
jsonData
.
FrontendResponse
[
i
]
.
EN
.
Status
==
"Error"
{
complete
=
false
}
}
return
hashInt
,
nil
return
complete
}
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