Skip to content

Commit

Permalink
Pass Auth-Token in the Header Request for the service Instance creati…
Browse files Browse the repository at this point in the history
…on (#64)
  • Loading branch information
himanshuvar authored and wisererik committed Jun 11, 2019
1 parent 11d4f3b commit d872fe0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 13 additions & 0 deletions orchestration/api/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
def instance_ops(tenant_id=''):
c = Connector().morph()
content = request.get_json()
AUTH_TOKEN = request.headers.get('X-Auth-Token')

# TODO: Need to check, When orchestration APIs authentication
# is implemented
if AUTH_TOKEN == '' or AUTH_TOKEN is None:
err_msg = 'Bad Request. Authentication Token is missing'
return jsonify(err_msg), Apiconstants.HTTP_ERR_BAD_REQUEST

if tenant_id == '':
err_msg = 'bad URL. tenant id is empty'
Expand Down Expand Up @@ -91,6 +98,7 @@ def instance_ops(tenant_id=''):
logger.info("no user_id provided. Exception [%s]", str(e))

content['parameters']['tenant_id'] = tenant_id
content['parameters']['auth_token'] = AUTH_TOKEN
try:
rc, ret = c.execute_action(content)
if(rc != Apiconstants.HTTP_CREATED):
Expand Down Expand Up @@ -120,6 +128,7 @@ def instance_ops(tenant_id=''):
service_map['created_at'] = service_obj['created_at']
service_map['updated_at'] = service_obj['updated_at']
service_map['input'] = ret_json['parameters']
del service_map['input']['auth_token']

wf_hash = {}
wf_hash['id'] = ret_json['id']
Expand Down Expand Up @@ -250,6 +259,8 @@ def wf_ops(tenant_id='', instance_id=''):
status, output = _update_status_and_output(service['id'])
service['status'] = status
service['output'] = output
service['service_id'] = service['service_definition_id']
del service['service_definition_id']
else:
try:
ret = get_service(None, instance_id)
Expand All @@ -261,6 +272,8 @@ def wf_ops(tenant_id='', instance_id=''):
status, output = _update_status_and_output(instance_id)
ret['status'] = status
ret['output'] = output
ret['service_id'] = ret['service_definition_id']
del ret['service_definition_id']

logger.debug("returning list of workflows: %s" % (ret))
return jsonify(ret), 200
Expand Down
1 change: 1 addition & 0 deletions orchestration/api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def get_services(tenant_id='', service_id=''):
def add_services(tenant_id=''):
payload = request.get_json()
service_data = json.loads(json.dumps(payload))
service_data['tenant_id'] = tenant_id
wf_def_sources = service_data['workflows']

# Validate the request sent
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/api/test_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

def test_post_instance(client):
type_mime = 'application/json'
header = {'Content-Type': type_mime, 'Accept': type_mime}
header = {'Content-Type': type_mime, 'Accept': type_mime,
'X-Auth-Token': 'abcde'}
data = {
"service_id": "26ab0773-fc5a-4211-a8e9-8e61ff16fa42",
"action": "opensds.migration-bucket",
Expand All @@ -32,8 +33,7 @@ def test_post_instance(client):
"description": "Migration_test_orchestration",
"destBackend": "hw-backend",
"srcBucketName": "aws-orchestrate",
"destBucketName": "hw-orchestrate",
"auth_token": "abcde"
"destBucketName": "hw-orchestrate"
}
}
url = '/v1beta/xyz/orchestration/instances'
Expand Down

0 comments on commit d872fe0

Please sign in to comment.