Skip to content

Commit

Permalink
Merge pull request #4 from Aquaveo/api_csrf_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
msouff authored Mar 13, 2023
2 parents 66efbdd + 9f1c960 commit 4ce23f6
Show file tree
Hide file tree
Showing 42 changed files with 1,559 additions and 749 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
2 changes: 2 additions & 0 deletions conda.recipes/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% set data = load_setup_py_data(setup_file='../setup.py', from_recipe_dir=True) %}
{% set tethys_install_data = load_file_data('../install.yml') %}
{% set name = data.get('name')|replace("tethysapp-", "")|lower %}

package:
Expand All @@ -10,6 +11,7 @@ about:
description: {{ data.get('description')}}
license: {{ data.get('license')}}
dev_url: {{ data.get('url') }}
tethys_version: {{ tethys_install_data.get('tethys_version') }}

source:
path: ..
Expand Down
6 changes: 4 additions & 2 deletions install.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: 1.0.0
version: 1.2.0
tethys_version: ">=4.0.0"
name: app_store

requirements:
Expand All @@ -7,8 +8,9 @@ requirements:
- conda-forge
packages:
- pygithub
- gitpython=3.1.18
- gitpython==3.1.18
- requests
- semver

post:
- setup_tethys_channel.sh
10 changes: 8 additions & 2 deletions setup_tethys_channel.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash

tethys settings --set CHANNEL_LAYERS.default.BACKEND channels.layers.InMemoryChannelLayer
echo "Websocket Channel configured for Tethys App Store"
tethys settings --get | grep -q "'CHANNEL_LAYERS'"
if [ $? == 0 ];
then
echo "Websocket Channel layer has been already set for the app store"
else
tethys settings --set CHANNEL_LAYERS.default.BACKEND channels.layers.InMemoryChannelLayer
echo "Websocket Channel configured for Tethys App Store"
fi
76 changes: 5 additions & 71 deletions tethysapp/app_store/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tethys_sdk.base import TethysAppBase, url_map_maker
from tethys_sdk.base import TethysAppBase
from tethys_sdk.app_settings import CustomSetting
from tethys_sdk.permissions import Permission, PermissionGroup

Expand All @@ -9,82 +9,18 @@ class AppStore(TethysAppBase):
"""

name = 'Tethys App Store'
index = 'app_store:home'
index = 'home'
icon = 'app_store/images/appicon.png'
package = 'app_store'
root_url = 'app-store'
color = '#2b7ac0'
description = 'The Tethys App Store enables you to discover, install, manage and configure Tethys Applications for your Tethys portal.'
description = 'The Tethys App Store enables you to discover, install, manage and configure Tethys Applications '
'for your Tethys portal.'
tags = 'Tethys,AppStore,Conda,Github'
enable_feedback = True
feedback_emails = ["[email protected]"]

def url_maps(self):
"""
Add controllers
"""
UrlMap = url_map_maker(self.root_url)

url_maps = (
UrlMap(
name='home',
url='app-store',
controller='app_store.controllers.home'
),
UrlMap(
name='get_resources',
url='app-store/get_resources',
controller='app_store.controllers.get_resources'
),
UrlMap(
name='install_notifications',
url='app-store/install/notifications',
controller='app_store.controllers.notificationsConsumer',
protocol='websocket'
),
UrlMap(
name='install_git',
url='app-store/install/git',
controller='app_store.controllers.run_git_install',
),
UrlMap(
name='git_get_status',
url='app-store/install/git/status',
controller='app_store.controllers.get_status',
),
UrlMap(
name='git_get_logs',
url='app-store/install/git/logs',
controller='app_store.controllers.get_logs',
), UrlMap(
name='install_git_override',
url='app-store/install/git_override',
controller='app_store.controllers.run_git_install_override',
),
UrlMap(
name='git_get_status_override',
url='app-store/install/git/status_override',
controller='app_store.controllers.get_status_override',
),
UrlMap(
name='git_get_logs_override',
url='app-store/install/git/logs_override',
controller='app_store.controllers.get_logs_override',
),
UrlMap(
name='scaffold_app',
url='app-store/scaffold',
controller='app_store.controllers.scaffold_command',
),
UrlMap(
name='scaffold_submit',
url='app-store/scaffold_submit',
controller='app_store.controllers.run_submit_nursery_app',
)

)

return url_maps
controller_modules = ['controllers', 'notifications', 'git_install_handlers', 'scaffold_handler', ]

def permissions(self):
"""
Expand Down Expand Up @@ -113,5 +49,3 @@ def custom_settings(self):
required=False
),
)

return custom_settings
4 changes: 2 additions & 2 deletions tethysapp/app_store/application_files/getChannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
channelString = channelString + " -c " + channel
buildCommand = "conda build" + channelString + " --output-folder . ."
print(buildCommand)
except Exception as e:
except Exception:
# print(e)
print("conda build -c conda-forge --output-folder . .")
print("conda build -c conda-forge --output-folder . .")
13 changes: 8 additions & 5 deletions tethysapp/app_store/application_files/main.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Publish

on: push

# on: push
on:
push:
branches:
- 'tethysapp_warehouse_release'
jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -10,14 +13,14 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
python-version: '3.x'
- name: Install dependencies
run: python -m pip install --upgrade pyyaml
- name: Gen Build Command
run: |
python ./conda.recipes/getChannels.py > build_command.txt
- name: publish-to-conda
uses: rfun/conda-package-publish-action@master
uses: tethysapp/conda-package-publish-action@master
with:
subDir: "conda.recipes"
subDir: 'conda.recipes'
AnacondaToken: ${{ secrets.ANACONDA_TOKEN }}
32 changes: 24 additions & 8 deletions tethysapp/app_store/application_files/main_template.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: Publish

on: push

# on: push
on:
push:
branches:
- 'tethysapp_warehouse_release'
jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -10,16 +13,16 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
python-version: '3.x'
- name: Install dependencies
run: python -m pip install --upgrade pyyaml
- name: Gen Build Command
run: |
python ./conda.recipes/getChannels.py > build_command.txt
- name: publish-to-conda
uses: rfun/conda-package-publish-action@master
uses: tethysapp/conda-package-publish-action@master
with:
subDir: "conda.recipes"
subDir: 'conda.recipes'
AnacondaToken: $${{ secrets.ANACONDA_TOKEN }}
- name: Send mail
uses: dawidd6/action-send-mail@v2
Expand All @@ -28,8 +31,21 @@ jobs:
server_port: 465
username: $${{secrets.EMAIL_USERNAME}}
password: $${{secrets.EMAIL_PASSWORD}}
subject: "$subject"
subject: '$subject'
# Literal body:
body: '$buildMsg'
to: $email
from: Tethys App Warehouse
- name: Send mail for failure
uses: dawidd6/action-send-mail@v2
if: failure()
with:
server_address: smtp.gmail.com
server_port: 465
username: $${{secrets.EMAIL_USERNAME}}
password: $${{secrets.EMAIL_PASSWORD}}
subject: 'Tethys App Store: Build Failed for test_app_store_aquaveo'
# Literal body:
body: "$buildMsg"
body: $${{ github.workflow }} of the application at github repository $${{ github.repository }} has failed. Check the logs of the publish job at $${{ github.server_url }}/$${{ github.repository }}/actions/runs/$${{ github.run_id }}
to: $email
from: Tethys App Warehouse
from: Tethys App Warehouse
2 changes: 1 addition & 1 deletion tethysapp/app_store/application_files/meta_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ about:
author: {{ data.get('author')}}
description: {{ data.get('description')}}
license: "$metadataObj"
dev_url: {{ data.get('url') }}
dev_url: {{ data.get('dev_url') }}

outputs:
- name: {{ name }}
14 changes: 14 additions & 0 deletions tethysapp/app_store/application_files/setup_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os


def find_resource_files(directory, relative_to=None):
paths = []
for (path, directories, filenames) in os.walk(directory):
Expand All @@ -9,4 +10,17 @@ def find_resource_files(directory, relative_to=None):
else:
paths.append(os.path.join('..', path, filename))
return paths

def find_resource_files_of_type(resource_type, app_package, app_root):
relative_to = f"{app_root}/{app_package}"
resources = find_resource_files(f"{relative_to}/{resource_type}", relative_to)
return resources


def find_all_resource_files(app_package, app_root):
resources = find_resource_files_of_type("templates", app_package, app_root)
resources += find_resource_files_of_type("public", app_package, app_root)
resources += find_resource_files_of_type("workspaces", app_package, app_root)
resources += find_resource_files_of_type("scripts", app_package, app_root)

return resources
26 changes: 9 additions & 17 deletions tethysapp/app_store/begin_install.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import os
import yaml
import time
import json
import importlib
import sys
import subprocess
import asyncio
import functools

from django.core.cache import cache
from conda.cli.python_api import run_command as conda_run, Commands

from subprocess import call

from .app import AppStore as app
from .helpers import *
from .helpers import check_all_present, get_app_instance_from_path, logger, send_notification
from .resource_helpers import get_resource


Expand Down Expand Up @@ -97,7 +90,7 @@ def detect_app_dependencies(app_name, app_version, channel_layer, notification_m
for setting in custom_settings() or []:
setting = {"name": getattr(setting, "name"),
"description": getattr(setting, "description"),
"default": getattr(setting, "default"),
"default": str(getattr(setting, "default")),
}
custom_settings_json.append(setting)

Expand All @@ -115,8 +108,8 @@ def detect_app_dependencies(app_name, app_version, channel_layer, notification_m
def conda_install(app_metadata, app_version, channel_layer):

start_time = time.time()
send_notification(
"Conda install may take a couple minutes to complete depending on how complicated the environment is. Please wait....", channel_layer)
send_notification("Mamba install may take a couple minutes to complete depending on how complicated the "
"environment is. Please wait....", channel_layer)

latest_version = app_metadata['metadata']['versions'][-1]
if not app_version:
Expand Down Expand Up @@ -150,21 +143,20 @@ def conda_install(app_metadata, app_version, channel_layer):
if(check_all_present(str_output, ['All requested packages already installed.'])):
send_notification("Application package is already installed in this conda environment.",
channel_layer)
if(check_all_present(str_output, ['Conda Install Complete'])):
if(check_all_present(str_output, ['Mamba Install Complete'])):
break
if(check_all_present(str_output, ['Found conflicts!'])):
send_notification("Conda install found conflicts."
send_notification("Mamba install found conflicts."
"Please try running the following command in your terminal's"
"conda environment to attempt a manual installation : "
"conda install -c " + app_metadata['metadata']['channel'] + " " + app_name,
"mamba install -c " + app_metadata['metadata']['channel'] + " " + app_name,
channel_layer)

send_notification("Conda install completed in %.2f seconds." % (time.time() - start_time), channel_layer)
send_notification("Mamba install completed in %.2f seconds." % (time.time() - start_time), channel_layer)


def begin_install(installData, channel_layer):
def begin_install(installData, channel_layer, app_workspace):

app_workspace = app.get_app_workspace()
resource = get_resource(installData["name"], app_workspace)

send_notification("Starting installation of app: " + resource['name'], channel_layer)
Expand Down
Loading

0 comments on commit 4ce23f6

Please sign in to comment.