Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dummy-engine2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Polaris
engines
dummy-engine2
Commits
35929fde
Commit
35929fde
authored
2 years ago
by
Max Lou
Browse files
Options
Downloads
Patches
Plain Diff
Fix: use api_url argument
parent
6e33c4e0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+4
-4
4 additions, 4 deletions
main.py
utils.py
+8
-9
8 additions, 9 deletions
utils.py
with
12 additions
and
13 deletions
main.py
+
4
−
4
View file @
35929fde
...
...
@@ -6,10 +6,10 @@ from requests import HTTPError
from
utils
import
get_existing_results
,
save_results
def
main
(
analytics_token
):
def
main
(
analytics_token
,
api_url
):
try
:
# Get existing results
existing_results
=
get_existing_results
(
analytics_token
)
existing_results
=
get_existing_results
(
api_url
,
analytics_token
)
my_engine_results
=
existing_results
[
"
my_engine
"
]
...
...
@@ -23,10 +23,10 @@ def main(analytics_token):
]
# Send result to rights engine
save_results
(
analytics_token
,
{
"
result
"
:
result
})
save_results
(
api_url
,
analytics_token
,
{
"
result
"
:
result
})
except
HTTPError
as
error
:
print
(
error
.
response
.
status_code
,
error
.
response
.
text
)
if
__name__
==
"
__main__
"
:
main
(
sys
.
argv
[
1
])
main
(
sys
.
argv
[
1
]
,
sys
.
argv
[
2
]
)
This diff is collapsed.
Click to expand it.
utils.py
+
8
−
9
View file @
35929fde
import
requests
API_URL
=
"
http://127.0.0.1:8003
"
PAGE_SIZE
=
100
def
get_statements_page
(
analytics_token
,
last_object_id
=
None
):
def
get_statements_page
(
api_url
,
analytics_token
,
last_object_id
=
None
):
payload
=
(
{
"
page_size
"
:
PAGE_SIZE
,
"
last_object_id
"
:
last_object_id
}
if
last_object_id
else
{
"
page_size
"
:
PAGE_SIZE
}
)
response
=
requests
.
post
(
f
"
{
API_URL
}
/api/v1/provider/data
"
,
f
"
{
api_url
}
/api/v1/provider/data
"
,
headers
=
{
"
Authorization
"
:
f
"
Basic
{
analytics_token
}
"
},
json
=
payload
,
)
...
...
@@ -21,12 +20,12 @@ def get_statements_page(analytics_token, last_object_id=None):
return
payload
.
get
(
"
statements
"
,
[])
def
get_statements
(
analytics_token
):
def
get_statements
(
api_url
,
analytics_token
):
statements
=
[]
read_all_pages
=
False
last_object_id
=
None
while
not
read_all_pages
:
page_statements
=
get_statements_page
(
analytics_token
,
last_object_id
)
page_statements
=
get_statements_page
(
api_url
,
analytics_token
,
last_object_id
)
statements
.
extend
(
page_statements
)
if
len
(
page_statements
)
==
0
:
read_all_pages
=
True
...
...
@@ -36,9 +35,9 @@ def get_statements(analytics_token):
return
statements
def
get_existing_results
(
analytics_token
):
def
get_existing_results
(
api_url
,
analytics_token
):
response
=
requests
.
get
(
f
"
{
API_URL
}
/api/v1/provider/results
"
,
f
"
{
api_url
}
/api/v1/provider/results
"
,
headers
=
{
"
Authorization
"
:
f
"
Basic
{
analytics_token
}
"
},
)
response
.
raise_for_status
()
...
...
@@ -46,9 +45,9 @@ def get_existing_results(analytics_token):
return
data
def
save_results
(
analytics_token
,
results
):
def
save_results
(
api_url
,
analytics_token
,
results
):
response
=
requests
.
post
(
f
"
{
API_URL
}
/api/v1/provider/store-result
"
,
f
"
{
api_url
}
/api/v1/provider/store-result
"
,
headers
=
{
"
Authorization
"
:
f
"
Basic
{
analytics_token
}
"
},
json
=
results
,
)
...
...
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