Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eric/cus 9 support cli updates #14

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.7
15 changes: 0 additions & 15 deletions Pipfile

This file was deleted.

472 changes: 0 additions & 472 deletions Pipfile.lock

This file was deleted.

12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[build-system]
requires = ["setuptools >= 61.0"]
requires = [
"setuptools >= 61.0",
"requests"
]
build-backend = "setuptools.build_meta"

[project]
name = "socket-sdk-python"
dynamic = ["version"]
requires-python = ">= 3.9"
dependencies = [
'requests'
'requests',
'typing-extensions>=4.12.2'
]
readme = "README.rst"
license = {file = "LICENSE"}
Expand All @@ -34,6 +38,9 @@ classifiers = [
[project.optional-dependencies]
dev = [
"ruff>=0.3.0",
"twine",
"wheel",
"build",
]

[project.urls]
Expand All @@ -57,6 +64,7 @@ include = [
"socketdev.sbom",
"socketdev.settings",
"socketdev.tools",
"socketdev.utils",
]

[tool.setuptools.dynamic]
Expand Down
72 changes: 72 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: true
# with-sources: false
# generate-hashes: false
# universal: false

-e file:.
build==1.2.2.post1
# via socket-sdk-python
certifi==2024.12.14
# via requests
charset-normalizer==3.4.1
# via requests
docutils==0.21.2
# via readme-renderer
idna==3.10
# via requests
jaraco-classes==3.4.0
# via keyring
jaraco-context==6.0.1
# via keyring
jaraco-functools==4.1.0
# via keyring
keyring==25.6.0
# via twine
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
more-itertools==10.6.0
# via jaraco-classes
# via jaraco-functools
nh3==0.2.20
# via readme-renderer
packaging==24.2
# via build
# via twine
pkginfo==1.12.0
# via twine
pygments==2.19.1
# via readme-renderer
# via rich
pyproject-hooks==1.2.0
# via build
readme-renderer==44.0
# via twine
requests==2.32.3
# via requests-toolbelt
# via socket-sdk-python
# via twine
requests-toolbelt==1.0.0
# via twine
rfc3986==2.0.0
# via twine
rich==13.9.4
# via twine
ruff==0.9.1
# via socket-sdk-python
twine==6.0.1
# via socket-sdk-python
typing-extensions==4.12.2
# via socket-sdk-python
urllib3==2.3.0
# via requests
# via twine
wheel==0.45.1
# via socket-sdk-python
72 changes: 72 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: true
# with-sources: false
# generate-hashes: false
# universal: false

-e file:.
build==1.2.2.post1
# via socket-sdk-python
certifi==2024.12.14
# via requests
charset-normalizer==3.4.1
# via requests
docutils==0.21.2
# via readme-renderer
idna==3.10
# via requests
jaraco-classes==3.4.0
# via keyring
jaraco-context==6.0.1
# via keyring
jaraco-functools==4.1.0
# via keyring
keyring==25.6.0
# via twine
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
more-itertools==10.6.0
# via jaraco-classes
# via jaraco-functools
nh3==0.2.20
# via readme-renderer
packaging==24.2
# via build
# via twine
pkginfo==1.12.0
# via twine
pygments==2.19.1
# via readme-renderer
# via rich
pyproject-hooks==1.2.0
# via build
readme-renderer==44.0
# via twine
requests==2.32.3
# via requests-toolbelt
# via socket-sdk-python
# via twine
requests-toolbelt==1.0.0
# via twine
rfc3986==2.0.0
# via twine
rich==13.9.4
# via twine
ruff==0.9.1
# via socket-sdk-python
twine==6.0.1
# via socket-sdk-python
typing-extensions==4.12.2
# via socket-sdk-python
urllib3==2.3.0
# via requests
# via twine
wheel==0.45.1
# via socket-sdk-python
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

VERSION=$(grep -o "__version__.*" socketdev/__init__.py | awk '{print $3}' | sed 's/"//g' | sed "s/'//g" | tr -d '\r')
VERSION=$(grep -o "__version__.*" socketdev/version.py | awk '{print $3}' | sed 's/"//g' | sed "s/'//g" | tr -d '\r')
ENABLE_PYPI_BUILD=$1

if [ -z $ENABLE_PYPI_BUILD ]; then
Expand Down
119 changes: 25 additions & 94 deletions socketdev/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
import requests
import base64

from socketdev.core.classes import Response
from socketdev.core.api import API
from socketdev.dependencies import Dependencies
from socketdev.exceptions import APIKeyMissing, APIFailure, APIAccessDenied, APIInsufficientQuota, APIResourceNotFound
from socketdev.export import Export
from socketdev.fullscans import FullScans
from socketdev.npm import NPM
Expand All @@ -17,106 +14,40 @@
from socketdev.repositories import Repositories
from socketdev.sbom import Sbom
from socketdev.settings import Settings
from socketdev.version import __version__
from socketdev.utils import Utils, IntegrationType, INTEGRATION_TYPES


__version__ = __version__
__author__ = "socket.dev"
__version__ = "1.0.14"
__all__ = ["socketdev"]


global encoded_key
encoded_key: str
__all__ = ["socketdev", "Utils", "IntegrationType", "INTEGRATION_TYPES"]

api_url = "https://api.socket.dev/v0"
request_timeout = 30
log = logging.getLogger("socketdev")
log.addHandler(logging.NullHandler())


def encode_key(token: str):
global encoded_key
encoded_key = base64.b64encode(token.encode()).decode("ascii")


def do_request(
path: str, headers: dict = None, payload: [dict, str] = None, files: list = None, method: str = "GET"
) -> Response:
"""
Shared function for performing the requests against the API.
:param path: String path of the URL
:param headers: Optional dictionary of the headers to include in the request. Defaults to None
:param payload: Optional dictionary or string of the payload to POST. Defaults to None
:param files: Optional list of files to send. Defaults to None
:param method: Optional string of the method for the Request. Defaults to GET
"""

if encoded_key is None or encoded_key == "":
raise APIKeyMissing

if headers is None:
headers = {
"Authorization": f"Basic {encoded_key}",
"User-Agent": f"SocketPythonScript/{__version__}",
"accept": "application/json",
}
url = f"{api_url}/{path}"
try:
response = requests.request(
method.upper(), url, headers=headers, data=payload, files=files, timeout=request_timeout
)
if response.status_code >= 400:
raise APIFailure("Bad Request")
elif response.status_code == 401:
raise APIAccessDenied("Unauthorized")
elif response.status_code == 403:
raise APIInsufficientQuota("Insufficient max_quota for API method")
elif response.status_code == 404:
raise APIResourceNotFound(f"Path not found {path}")
elif response.status_code == 429:
raise APIInsufficientQuota("Insufficient quota for API route")
except Exception as error:
response = Response(text=f"{error}", error=True, status_code=500)
raise APIFailure(response)
return response


class socketdev:
token: str
timeout: int
dependencies: Dependencies
npm: NPM
openapi: OpenAPI
org: Orgs
quota: Quota
report: Report
sbom: Sbom
purl: Purl
fullscans: FullScans
export: Export
repositories: Repositories
settings: Settings
repos: Repos

def __init__(self, token: str, timeout: int = 30):
self.api = API()
self.token = token + ":"
encode_key(self.token)
self.timeout = timeout
socketdev.set_timeout(self.timeout)
self.dependencies = Dependencies()
self.npm = NPM()
self.openapi = OpenAPI()
self.org = Orgs()
self.quota = Quota()
self.report = Report()
self.sbom = Sbom()
self.purl = Purl()
self.fullscans = FullScans()
self.export = Export()
self.repositories = Repositories()
self.repos = Repos()
self.settings = Settings()
self.api.encode_key(self.token)
self.api.set_timeout(timeout)

self.dependencies = Dependencies(self.api)
self.npm = NPM(self.api)
self.openapi = OpenAPI(self.api)
self.org = Orgs(self.api)
self.quota = Quota(self.api)
self.report = Report(self.api)
self.sbom = Sbom(self.api)
self.purl = Purl(self.api)
self.fullscans = FullScans(self.api)
self.export = Export(self.api)
self.repositories = Repositories(self.api)
self.repos = Repos(self.api)
self.settings = Settings(self.api)
self.utils = Utils()

@staticmethod
def set_timeout(timeout: int):
global request_timeout
request_timeout = timeout
# Kept for backwards compatibility
pass
Loading