Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python:
- '2.7'
install:
- sudo apt-get install linux-headers-$(uname -r) dkms gcc-multilib g++-multilib
- pip install pyyaml requests
- pip install pyyaml requests requests_toolbelt
script:
- bash test/start_agent.sh
- bash test/test_monitor_apis.sh
Expand Down
40 changes: 40 additions & 0 deletions examples/get_anchore_users_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
#
# Get a specific anchore user account
#

import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdScanningClient


def usage():
print('usage: %s <sysdig-token>' % sys.argv[0])
print('You can find your token at https://secure.sysdig.com/#/settings/user')
sys.exit(1)


#
# Parse arguments
#
if len(sys.argv) != 2:
usage()

sdc_token = sys.argv[1]

#
# Instantiate the SDC client
#
sdclient = SdScanningClient(sdc_token, 'https://secure.sysdig.com')

ok, res = sdclient.get_anchore_users_account()

#
# Return the result
#
if ok:
print("Anchore User Info %s" % res)
else:
print(res)
sys.exit(1)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests
pyaml
requests_toolbelt
61 changes: 44 additions & 17 deletions sdcclient/_scanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import re
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
import time

try:
Expand Down Expand Up @@ -54,23 +55,6 @@ def add_image(self, image, force=False, dockerfile=None, annotations={}, autosub

return [True, res.json()]

def import_image(self, image_data):
'''**Description**
Import an image from the scanner export

**Arguments**
- image_data: A JSON with the image information.

**Success Return Value**
A JSON object representing the image that was imported.
'''
url = self.url + "/api/scanning/v1/anchore/imageimport"
res = requests.post(url, data=json.dumps(image_data), headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]

return [True, res.json()]

def get_image(self, image, show_history=False):
'''**Description**
Find the image with the tag <image> and return its json description
Expand Down Expand Up @@ -323,6 +307,49 @@ def get_pdf_report(self, image, tag=None, date=None):

return [True, res.content]

def import_image(self, infile):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any example (maybe not just using this function) to show how this functionality can be used? I think it can expose very interesting use cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davideschiera this function is part of the inline-scan solution which is currently in a bash script. This function essentially implements the import image API being used in the script here https://github.com/sysdiglabs/secure-inline-scan/blob/inline-scan/inline_scan.sh#L463

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can an example (similar to examples/get_anchore_users_account.py) show how to import an image and then do something with it (eg. scan it)?

I was imagine something like that, but I'm not sure if it can be meaningful or useful.

'''**Description**
Import an image archive

**Arguments**
- infile: An image archive file

**Success Return Value**
A JSON object representing the image that was imported.
'''
try:
m = MultipartEncoder(
fields={'archive_file': (infile, open(infile, 'rb'), 'text/plain')}
)
url = self.url+"/api/scanning/v1/import/images"

headers = {'Authorization': 'Bearer ' + self.token, 'Content-Type': m.content_type}
res = requests.post(url, data=m, headers=headers)
if not self._checkResponse(res):
return [False, self.lasterr]

return [True, res.json()]

except Exception as err:
print(err)

def get_anchore_users_account(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can this function be useful? Asking only because I have not much context about it (it may be useful to add more color in the description for other users as well).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is needed to fetch the username for running inline-scan. The script uses this API here https://github.com/sysdiglabs/secure-inline-scan/blob/inline-scan/inline_scan.sh#L434

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: get_anchore_user_account or get_anchore_user_account_details may be more appropriate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'''**Description**
Get the anchore user account.

**Arguments**
- None

**Success Return Value**
A JSON object containing user account information.
'''
url = self.url + "/api/scanning/v1/anchore/account"
res = requests.get(url, headers=self.hdrs, verify=self.ssl_verify)
if not self._checkResponse(res):
return [False, self.lasterr]

return [True, res.json()]

def add_registry(self, registry, registry_user, registry_pass, insecure=False, registry_type="docker_v2", validate=True):
'''**Description**
Add image registry
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
author_email='info@sysdig.com',
license='MIT',
packages=['sdcclient'],
install_requires=['requests', 'pyaml'],
install_requires=['requests', 'pyaml', 'requests_toolbelt'],
zip_safe=False)