# Path: stoq/exceptions.py
# class StoqException(Exception):
#     pass
# 
# class StoqPluginException(Exception):
#     pass


import os
import sys
import logging
import requests
import subprocess
from tempfile import NamedTemporaryFile
from .exceptions import StoqException, StoqPluginException
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.



log = logging.getLogger()


class StoqPluginInstaller:

    DEFAULT_REPO = 'git+https://github.com/PUNCH-Cyber/stoq-plugins-public.git@v3'

    @staticmethod
    def install(
        plugin_path: str, install_dir: str, upgrade: bool, github: bool
    ) -> None:
        if github:
            if plugin_path.startswith('git+http'):
                pass
            elif plugin_path.startswith('stoq:'):
                plugin_name = plugin_path.split(':')[1]
                plugin_path = f'{StoqPluginInstaller.DEFAULT_REPO}#egg={plugin_name}&subdirectory={plugin_name}'
            else:

# Path: stoq/exceptions.py
# class StoqException(Exception):
#     pass
# 
# class StoqPluginException(Exception):
#     pass


# Path: stoq/installer.py
import os
import sys
import logging
import requests
import subprocess
from tempfile import NamedTemporaryFile
from .exceptions import StoqException, StoqPluginException

#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.



log = logging.getLogger()


class StoqPluginInstaller:

    DEFAULT_REPO = 'git+https://github.com/PUNCH-Cyber/stoq-plugins-public.git@v3'

    @staticmethod
    def install(
        plugin_path: str, install_dir: str, upgrade: bool, github: bool
    ) -> None:
        if github:
            if plugin_path.startswith('git+http'):
                pass
            elif plugin_path.startswith('stoq:'):
                plugin_name = plugin_path.split(':')[1]
                plugin_path = f'{StoqPluginInstaller.DEFAULT_REPO}#egg={plugin_name}&subdirectory={plugin_name}'
            else:

                raise StoqException('Invalid Github repository specified.')