Skip to content
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
36 changes: 36 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Ruff (linter)

on: [ pull_request, push ]

jobs:
ruff:
runs-on: ubuntu-latest

steps:
- name: Run Cimon
uses: cycodelabs/cimon-action@v0
with:
client-id: ${{ secrets.CIMON_CLIENT_ID }}
secret: ${{ secrets.CIMON_SECRET }}
prevent: true
allowed-hosts: >
files.pythonhosted.org
install.python-poetry.org
pypi.org

- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Setup Poetry
uses: snok/install-poetry@v1

- name: Install dependencies
run: poetry install

- name: Run linter check
run: poetry run ruff check .
16 changes: 9 additions & 7 deletions cycode/cli/auth/auth_command.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import click
import traceback

from cycode.cli.models import CliResult, CliErrors, CliError
from cycode.cli.printers import ConsolePrinter
import click

from cycode.cli.auth.auth_manager import AuthManager
from cycode.cli.exceptions.custom_exceptions import AuthProcessError, HttpUnauthorizedError, NetworkError
from cycode.cli.models import CliError, CliErrors, CliResult
from cycode.cli.printers import ConsolePrinter
from cycode.cli.user_settings.credentials_manager import CredentialsManager
from cycode.cli.exceptions.custom_exceptions import AuthProcessError, NetworkError, HttpUnauthorizedError
from cycode.cyclient import logger
from cycode.cyclient.cycode_token_based_client import CycodeTokenBasedClient


@click.group(invoke_without_command=True)
@click.group(
invoke_without_command=True, short_help='Authenticates your machine to associate CLI with your cycode account'
)
@click.pass_context
def authenticate(context: click.Context):
"""Authenticates your machine to associate CLI with your cycode account"""
if context.invoked_subcommand is not None:
# if it is a subcommand do nothing
# if it is a subcommand, do nothing
return

try:
Expand Down
13 changes: 7 additions & 6 deletions cycode/cli/auth/auth_manager.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import time
import webbrowser
from requests import Request
from typing import Optional

from requests import Request

from cycode.cli.exceptions.custom_exceptions import AuthProcessError
from cycode.cli.utils.string_utils import generate_random_string, hash_string_to_sha256
from cycode.cli.user_settings.configuration_manager import ConfigurationManager
from cycode.cli.user_settings.credentials_manager import CredentialsManager
from cycode.cli.utils.string_utils import generate_random_string, hash_string_to_sha256
from cycode.cyclient import logger
from cycode.cyclient.auth_client import AuthClient
from cycode.cyclient.models import ApiToken, ApiTokenGenerationPollingResponse
from cycode.cyclient import logger


class AuthManager:
CODE_VERIFIER_LENGTH = 101
POLLING_WAIT_INTERVAL_IN_SECONDS = 3
POLLING_TIMEOUT_IN_SECONDS = 180
FAILED_POLLING_STATUS = "Error"
COMPLETED_POLLING_STATUS = "Completed"
FAILED_POLLING_STATUS = 'Error'
COMPLETED_POLLING_STATUS = 'Completed'

configuration_manager: ConfigurationManager
credentials_manager: CredentialsManager
Expand Down Expand Up @@ -56,7 +57,7 @@ def redirect_to_login_page(self, code_challenge: str, session_id: str):
def get_api_token(self, session_id: str, code_verifier: str) -> Optional[ApiToken]:
api_token = self.get_api_token_polling(session_id, code_verifier)
if api_token is None:
raise AuthProcessError("getting api token is completed, but the token is missing")
raise AuthProcessError('getting api token is completed, but the token is missing')
return api_token

def get_api_token_polling(self, session_id: str, code_verifier: str) -> Optional[ApiToken]:
Expand Down
53 changes: 26 additions & 27 deletions cycode/cli/ci_integrations.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
import os

import click


def github_action_range():
before_sha = os.getenv("BEFORE_SHA")
push_base_sha = os.getenv("BASE_SHA")
pr_base_sha = os.getenv("PR_BASE_SHA")
default_branch = os.getenv("DEFAULT_BRANCH")
head_sha = os.getenv("GITHUB_SHA")
ref = os.getenv("GITHUB_REF")

click.echo(f"{before_sha}, {push_base_sha}, {pr_base_sha}, {default_branch}, {head_sha}, {ref}")
before_sha = os.getenv('BEFORE_SHA')
push_base_sha = os.getenv('BASE_SHA')
pr_base_sha = os.getenv('PR_BASE_SHA')
default_branch = os.getenv('DEFAULT_BRANCH')
head_sha = os.getenv('GITHUB_SHA')
ref = os.getenv('GITHUB_REF')

click.echo(f'{before_sha}, {push_base_sha}, {pr_base_sha}, {default_branch}, {head_sha}, {ref}')
if before_sha and before_sha != NO_COMMITS:
return f"{before_sha}..."
return f'{before_sha}...'

return "..."
return '...'

# if pr_base_sha and pr_base_sha != FIRST_COMMIT:
# return f"{pr_base_sha}..."
#
# if push_base_sha and push_base_sha != "null":
# return f"{push_base_sha}..."


def circleci_range():
before_sha = os.getenv("BEFORE_SHA")
current_sha = os.getenv("CURRENT_SHA")
commit_range = f"{before_sha}...{current_sha}"
click.echo(f"commit range: {commit_range}")
before_sha = os.getenv('BEFORE_SHA')
current_sha = os.getenv('CURRENT_SHA')
commit_range = f'{before_sha}...{current_sha}'
click.echo(f'commit range: {commit_range}')

if not commit_range.startswith('...'):
return commit_range

commit_sha = os.getenv("CIRCLE_SHA1", "HEAD")
commit_sha = os.getenv('CIRCLE_SHA1', 'HEAD')

return f'{commit_sha}~1...'


def gitlab_range():
before_sha = os.getenv("CI_COMMIT_BEFORE_SHA")
commit_sha = os.getenv("CI_COMMIT_SHA", "HEAD")
before_sha = os.getenv('CI_COMMIT_BEFORE_SHA')
commit_sha = os.getenv('CI_COMMIT_SHA', 'HEAD')

if before_sha and before_sha != NO_COMMITS:
return f"{before_sha}..."
return f'{before_sha}...'

return f"{commit_sha}"
return f'{commit_sha}'


def get_commit_range():
if os.getenv("GITHUB_ACTIONS"):
if os.getenv('GITHUB_ACTIONS'):
return github_action_range()
elif os.getenv("CIRCLECI"):
if os.getenv('CIRCLECI'):
return circleci_range()
elif os.getenv("GITLAB_CI"):
if os.getenv('GITLAB_CI'):
return gitlab_range()
else:
raise click.ClickException("CI framework is not supported")

raise click.ClickException('CI framework is not supported')


NO_COMMITS = "0000000000000000000000000000000000000000"
NO_COMMITS = '0000000000000000000000000000000000000000'
Loading