Exemplo n.º 1
0
    def push(brick_directory):
        project_id = StorageService.get_project_id(brick_directory)
        brick_id = StorageService.get_brick_id(brick_directory)

        if brick_id:
            BrickController.update(brick_directory, project_id, brick_id)
        else:
            BrickController.create(brick_directory, project_id)
Exemplo n.º 2
0
 def create_template_brick(project_id, brick_directory_name, brick_name):
     file_dir_path = pathlib.Path(__file__).parent.absolute()
     current_dir_path = pathlib.Path().absolute()
     cookiecutter(f'{file_dir_path}/{TEMPLATE_STORAGE_PATH}',
                  no_input=True,
                  output_dir=f'{current_dir_path}',
                  extra_context={
                      'brick_directory_name': brick_directory_name,
                      'brick_name': brick_name,
                  })
     StorageService.save_project_id(brick_directory_name, project_id)
Exemplo n.º 3
0
    def login(email, password):
        data = {
            'email': email,
            'password': password,
        }
        try:
            response = requests.post(url=AUTH_SIGN_IN_URL, data=data)

            if response.status_code == requests.codes.ok:
                response_data = response.json()
                access_token = response_data.get('accessToken', '')
                StorageService.save_token(access_token)
                show_message('Successfully logged in')
            elif response.status_code == requests.codes.unauthorized:
                AuthController.logout()
            else:
                show_error("Can't sign in. Email or password are incorrect")
        except Exception as e:
            show_error(e)
Exemplo n.º 4
0
    def get_projects():
        token = StorageService.get_token()
        params = {'token': token}
        response = requests.get(url=GET_PROJECTS_URL, params=params)

        if response.status_code == requests.codes.ok:
            projects = response.json()
            ShowDataService.show_projects(projects)
        elif response.status_code == requests.codes.unauthorized:
            AuthController().logout()
            show_error("Please log in to get projects")
Exemplo n.º 5
0
    def delete(brick_directory):
        project_id = StorageService.get_project_id(brick_directory)
        brick_id = StorageService.get_brick_id(brick_directory)
        token = StorageService.get_token()
        params = {'token': token}

        try:
            url = DELETE_PROJECT_BRICK_URL.replace(':project_id',
                                                   project_id).replace(
                                                       ':brick_id', brick_id)
            response = requests.delete(url=url, params=params)

            if response.status_code == requests.codes.ok:
                StorageService.delete_brick(brick_directory)
                BrickService.remove_brick_directory(brick_directory)
                show_message('Brick successfully deleted!')
            elif response.status_code == requests.codes.unauthorized:
                AuthController.logout()
                show_error("Please log in to delete brick")
            else:
                show_error("Can't delete brick")
        except Exception as e:
            show_error(e)
Exemplo n.º 6
0
    def create(brick_directory, project_id):
        brick_file_path = BrickService.pack_brick(brick_directory)
        token = StorageService.get_token()
        params = {'token': token}

        try:
            files = {'upload': open(brick_file_path, 'rb')}
            url = POST_PROJECT_BRICKS_URL.replace(':project_id', project_id)
            response = requests.post(url=url, files=files, params=params)

            if response.status_code == requests.codes.ok:
                show_message('Brick successfully added!')
                brick_id = str(response.json()['brick']['id'])
                StorageService.save_brick_id(brick_directory,
                                             brick_id=brick_id)
            elif response.status_code == requests.codes.unauthorized:
                AuthController.logout()
                show_error("Please log in to push brick")
            else:
                show_error("Can't create brick")
        except Exception as e:
            show_error(e)
        finally:
            BrickService.remove_brick_file(brick_file_path)
Exemplo n.º 7
0
def env(url):
    StorageService.save_api_base_url(url)
Exemplo n.º 8
0
 def logout():
     StorageService.remove_token()
Exemplo n.º 9
0
 def init_bricks_repository():
     StorageService.create_storage()
Exemplo n.º 10
0
from datrics.services.storage_service import StorageService

# Routes
AUTH_SIGN_IN_ROUTE = 'auth/sign-in'
GET_PROJECTS_ROUTE = 'project'
PROJECT_BRICK_CREATE_ROUTE = 'project/:project_id/bricks'
PROJECT_BRICK_UPDATE_ROUTE = 'project/:project_id/bricks/:brick_id'
PROJECT_BRICK_DELETE_ROUTE = 'project/:project_id/bricks/:brick_id'

# URLs
PROD_BASE_API_URL = 'https://api.app.datrics.ai/api/v1'
saved_base_api_url = StorageService.get_api_base_url()
BASE_API_URL = PROD_BASE_API_URL if len(
    saved_base_api_url) == 0 else saved_base_api_url
# BASE_API_URL = 'http://localhost:3000/api/v1'
AUTH_SIGN_IN_URL = f'{BASE_API_URL}/{AUTH_SIGN_IN_ROUTE}'
GET_PROJECTS_URL = f'{BASE_API_URL}/{GET_PROJECTS_ROUTE}'
POST_PROJECT_BRICKS_URL = f'{BASE_API_URL}/{PROJECT_BRICK_CREATE_ROUTE}'
PATCH_PROJECT_BRICK_URL = f'{BASE_API_URL}/{PROJECT_BRICK_UPDATE_ROUTE}'
DELETE_PROJECT_BRICK_URL = f'{BASE_API_URL}/{PROJECT_BRICK_DELETE_ROUTE}'