forked from p15670423/monkey
Added setting project to GCPHandler
This commit is contained in:
parent
45fa7570ef
commit
11a1578893
|
@ -1,2 +1,2 @@
|
||||||
ISLAND_SERVER_ADDRESS = "1.2.3.4"
|
ISLAND_SERVER_ADDRESS = "1.2.3.4"
|
||||||
ISLAND_SERVER_URL_FORMAT = "https://{IP}/{resource}".format(IP=ISLAND_SERVER_ADDRESS)
|
ISLAND_SERVER_URL = "https://{IP}/".format(IP=ISLAND_SERVER_ADDRESS)
|
||||||
|
|
|
@ -4,13 +4,19 @@ import subprocess
|
||||||
class GCPHandler(object):
|
class GCPHandler(object):
|
||||||
|
|
||||||
AUTHENTICATION_COMMAND = "gcloud auth activate-service-account --key-file=%s"
|
AUTHENTICATION_COMMAND = "gcloud auth activate-service-account --key-file=%s"
|
||||||
|
SET_PROPERTY_PROJECT = "gcloud config set project %s"
|
||||||
MACHINE_STARTING_COMMAND = "gcloud compute instances start %s --zone=%s"
|
MACHINE_STARTING_COMMAND = "gcloud compute instances start %s --zone=%s"
|
||||||
MACHINE_STOPPING_COMMAND = "gcloud compute instances stop %s --zone=%s"
|
MACHINE_STOPPING_COMMAND = "gcloud compute instances stop %s --zone=%s"
|
||||||
|
|
||||||
def __init__(self, key_path="../gcp_keys/gcp_key.json", zone="europe-west3-a"):
|
def __init__(self, key_path="../gcp_keys/gcp_key.json", zone="europe-west3-a", project_id="guardicore-22050661"):
|
||||||
self.zone = zone
|
self.zone = zone
|
||||||
try:
|
try:
|
||||||
|
# pass the key file to gcp
|
||||||
subprocess.call(GCPHandler.get_auth_command(key_path), shell=True)
|
subprocess.call(GCPHandler.get_auth_command(key_path), shell=True)
|
||||||
|
print("GCP Handler passed key")
|
||||||
|
# set project
|
||||||
|
subprocess.call(GCPHandler.get_set_project_command(project_id), shell=True)
|
||||||
|
print("GCP Handler set project")
|
||||||
print("GCP Handler initialized successfully")
|
print("GCP Handler initialized successfully")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("GCP Handler failed to initialize: %s." % e)
|
print("GCP Handler failed to initialize: %s." % e)
|
||||||
|
@ -32,3 +38,7 @@ class GCPHandler(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_auth_command(key_path):
|
def get_auth_command(key_path):
|
||||||
return GCPHandler.AUTHENTICATION_COMMAND % key_path
|
return GCPHandler.AUTHENTICATION_COMMAND % key_path
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_set_project_command(project):
|
||||||
|
return GCPHandler.SET_PROPERTY_PROJECT % project
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from .gcp_machine_handlers import GCPHandler
|
from .gcp_machine_handlers import GCPHandler
|
||||||
|
|
||||||
|
@ -6,6 +7,13 @@ import requests
|
||||||
from config import *
|
from config import *
|
||||||
|
|
||||||
|
|
||||||
|
def generic_blackbox_test_case(config_file_path, analyzers):
|
||||||
|
load_config_into_server(config_file_path)
|
||||||
|
run_local_monkey_on_island()
|
||||||
|
for analyzer in analyzers:
|
||||||
|
assert analyzer.analyze_test_results()
|
||||||
|
|
||||||
|
|
||||||
class TestMonkeyBlackbox(unittest.TestCase):
|
class TestMonkeyBlackbox(unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -18,15 +26,19 @@ class TestMonkeyBlackbox(unittest.TestCase):
|
||||||
GCPHandler().stop_machines("elastic-4")
|
GCPHandler().stop_machines("elastic-4")
|
||||||
print("Killing all GCP machines...")
|
print("Killing all GCP machines...")
|
||||||
|
|
||||||
def generic_blackbox_test_case(self, config_file_path, analyzers):
|
def test_ssh_exec(self):
|
||||||
self.load_config_into_server(config_file_path)
|
conf_file_name = "ssh.conf"
|
||||||
self.run_local_monkey_on_island()
|
generic_blackbox_test_case(get_conf_file_path(conf_file_name), [])
|
||||||
for analyzer in analyzers:
|
|
||||||
assert analyzer.analyze_test_results()
|
|
||||||
|
|
||||||
def load_config_into_server(self, config_file_path):
|
|
||||||
|
def run_local_monkey_on_island():
|
||||||
|
print("Trying to run local monkey on {}".format(ISLAND_SERVER_ADDRESS))
|
||||||
|
print(ISLAND_SERVER_URL + "api")
|
||||||
|
|
||||||
|
|
||||||
|
def load_config_into_server(config_file_path):
|
||||||
print("uploading {} to {}".format(config_file_path, ISLAND_SERVER_ADDRESS))
|
print("uploading {} to {}".format(config_file_path, ISLAND_SERVER_ADDRESS))
|
||||||
|
|
||||||
def run_local_monkey_on_island(self):
|
|
||||||
print("Trying to run local monkey on {}".format(ISLAND_SERVER_ADDRESS))
|
def get_conf_file_path(conf_file_name):
|
||||||
print(requests.get(ISLAND_SERVER_URL_FORMAT.format(resource="api"), verify=False).text)
|
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "island_configs", conf_file_name)
|
||||||
|
|
Loading…
Reference in New Issue