Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Fix/x api key (#191)
Browse files Browse the repository at this point in the history
Fix/x api key
  • Loading branch information
eKatchko authored Dec 12, 2019
2 parents 0f5d75c + ff0caab commit 8b4648e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 24 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

2 changes: 2 additions & 0 deletions .env.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CLOUD_CLIENT_TAG=
FORC_API_KEY=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __pycache__/

# C extensions
*.so

.env
# Distribution / packaging
.Python
build/
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ source NameOfRcFile.sh
~~~

#### Configuration
You can view all existing parameters in the [yaml file](VirtualMachineService/config/config.yml).
You can view (almost) all existing parameters in the [yaml file](VirtualMachineService/config/config.yml).
Also you need to provide the path to your config file as the first param when starting a server.

Furthermore there are some parameters you can set in the [.env.in](.env.in) file, which are read only when starting with docker.
Important: You need to rename .env.in to .env in order for it to be read by docker.
When starting with commandline you will need to export some of them manually.

#### Security Groups
The client expects a security group with the name "defaultSimpleVM" to exist which will be assigned to each machine at startup. Also, each machine will have its own security group when it starts.

Expand Down Expand Up @@ -70,7 +74,7 @@ portal_client_start_server path/to/config.yml
~~~

### Using Docker
Specify in the [.env](.env) file which release should be used by the client.
Specify in the .env file which release should be used by the client.
Then you can start the client with:
```
$ docker-compose up
Expand Down
32 changes: 18 additions & 14 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ def __init__(self, config):
"floating_ip_network"
]
self.AVAIALABILITY_ZONE = cfg["openstack_connection"]["availability_zone"]

if cfg["urls"]["forc_url"]:
self.RE_BACKEND_URL = cfg["urls"]["forc_url"]
self.logger.info(msg="BACKEND URL LOADED {0}".format(self.RE_BACKEND_URL))
else:
# try to initialize forc connection
try:
self.RE_BACKEND_URL = cfg["forc"]["forc_url"]
self.FORC_API_KEY = os.environ["FORC_API_KEY"]
self.logger.info(msg="Forc-Backend url loaded: {0}".format(self.RE_BACKEND_URL))
except Exception as e:
self.logger.exception(e)
self.logger.info("Forc-Backend not loaded.")
self.RE_BACKEND_URL = None
self.FORC_API_KEY = None
if self.USE_GATEWAY:
self.GATEWAY_IP = cfg["openstack_connection"]["gateway_ip"]
self.SSH_FORMULAR = cfg["openstack_connection"]["ssh_port_calc_formular"]
Expand Down Expand Up @@ -773,7 +777,7 @@ def create_backend(self, elixir_id, user_key_url, template, template_version, up
self.logger.exception(e)
return {}
try:
response = req.post(post_url, json=backend_info, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.post(post_url, json=backend_info, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
try:
data = response.json()
except Exception as e:
Expand All @@ -794,7 +798,7 @@ def create_backend(self, elixir_id, user_key_url, template, template_version, up
def get_backends(self):
get_url = "{0}/backends/".format(self.RE_BACKEND_URL)
try:
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
if response.status_code == 401:
return [response.json()]
else:
Expand All @@ -812,7 +816,7 @@ def get_backends(self):
def get_backends_by_owner(self, elixir_id):
get_url = "{0}/backends/byOwner/{1}".format(self.RE_BACKEND_URL, elixir_id)
try:
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
if response.status_code == 401:
return [response.json()]
else:
Expand All @@ -830,7 +834,7 @@ def get_backends_by_owner(self, elixir_id):
def get_backends_by_template(self, template):
get_url = "{0}/backends/byTemplate/{1}".format(self.RE_BACKEND_URL, template)
try:
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
if response.status_code == 401:
return [response.json()]
else:
Expand All @@ -848,7 +852,7 @@ def get_backends_by_template(self, template):
def get_backend_by_id(self, id):
get_url = "{0}/backends/{1}".format(self.RE_BACKEND_URL, id)
try:
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
try:
data = response.json()
except Exception as e:
Expand All @@ -865,7 +869,7 @@ def get_backend_by_id(self, id):
def delete_backend(self, id):
delete_url = "{0}/backends/{1}".format(self.RE_BACKEND_URL, id)
try:
response = req.delete(delete_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.delete(delete_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
if response.status_code != 200:
return str(response.json())
elif response.status_code == 200:
Expand All @@ -887,7 +891,7 @@ def get_templates(self):
get_url = "{0}templates/".format(self.RE_BACKEND_URL)
self.logger.info(get_url)
try:
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
self.logger.info(response.json())
if response.status_code == 401:
return [response.json()]
Expand All @@ -899,7 +903,7 @@ def get_templates(self):
def get_templates_by_template(self, template_name):
get_url = "{0}/templates/{1}".format(self.RE_BACKEND_URL, template_name)
try:
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
if response.status_code == 401:
return [response.json()]
else:
Expand All @@ -910,7 +914,7 @@ def get_templates_by_template(self, template_name):
def check_template(self, template_name, template_version):
get_url = "{0}/templates/{1}/{2}".format(self.RE_BACKEND_URL, template_name, template_version)
try:
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"})
response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY})
if response.status_code == 401:
return [response.json()]
else:
Expand Down
10 changes: 5 additions & 5 deletions VirtualMachineService/ancon/Playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class Playbook(object):
PLAYBOOK_FAILED = "PLAYBOOK_FAILED"

def __init__(self, ip, port, playbooks_information, osi_private_key, public_key, logger, pool):
self.redis = redis.Redis(connection_pool=pool)
self.yaml_exec = ruamel.yaml.YAML()
self.vars_files = []
self.tasks = []
self.redis = redis.Redis(connection_pool=pool) # redis connection
self.yaml_exec = ruamel.yaml.YAML() # yaml writer/reader
self.vars_files = [] # _vars_file.yml to read
self.tasks = [] # task list
self.always_tasks = []
self.logger = logger
self.process = None
self.process = None # init process, returncode, standard output, standard error output
self.returncode = -1
self.stdout = ""
self.stderr = ""
Expand Down
2 changes: 1 addition & 1 deletion VirtualMachineService/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ openstack_connection:
ssh_port_calc_formular: 30000 + x
udp_port_calc_formular: x * 10 + 30000

urls:
forc:
forc_url: https://proxy-dev.bi.denbi.de:5000/
1 change: 1 addition & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- OS_PASSWORD
- OS_USER_DOMAIN_NAME
- OS_PROJECT_DOMAIN_ID
- FORC_API_KEY

volumes:
- ./VirtualMachineService/config/config.yml:/code/VirtualMachineService/config.yml
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- OS_PASSWORD
- OS_USER_DOMAIN_NAME
- OS_PROJECT_DOMAIN_ID
- FORC_API_KEY

volumes:
- ./VirtualMachineService/config/config.yml:/code/VirtualMachineService/config.yml
Expand Down

0 comments on commit 8b4648e

Please sign in to comment.