Skip to content

Instantly share code, notes, and snippets.

@openstacker
Last active March 26, 2017 21:22
Show Gist options
  • Save openstacker/1c1bcc887cef4603148f4633e1cae006 to your computer and use it in GitHub Desktop.
Save openstacker/1c1bcc887cef4603148f4633e1cae006 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Zaqar CORS wsgi example</title>
<meta charset='utf-8' />
<link rel='stylesheet' href='http://yui.yahooapis.com/pure/0.6.0/pure-nr-min.css' />
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.4.min.js'></script>
<script type='text/javascript'>
// Parameters:
var username = 'admin';
var password = 'passw0rd';
var server_url = 'ws://localhost:8888/';
var project_id = '45be7723376146469997771fb383a9a8';
var client_id = '31209ff3-ba03-4cec-b4ca-655f4899f8f4';
log_info = function(msg) {
var node = document.createElement('div');
var date = new Date().toUTCString();
msg = date + " " + msg;
node.appendChild(document.createTextNode(msg));
$('#log').append(node);
}
list_queues = function(token) {
$.ajax({
'type': 'GET',
'url': 'http://localhost:8888/v2/health',
'headers': {
'X-Auth-Token': token,
'Client-ID': client_id
},
'dataType': 'json',
'contentType': 'application/json',
'success': function(data, code, response) {
alert(response);
},
'error': function(data, code, errorThrown) {
if (errorThrown) {
log_info("Keystone error: " + errorThrown);
} else {
log_info("Failed to connect to Zaqar.");
}
}
});
}
login = function() {
data = {
'auth': {
'identity': {
'methods': ['password'],
'password': {
'user': {
'name': username,
'domain': {'id': 'default'},
'password': password,
}
}
},
"scope": {
"project": {
"id": project_id
}
}
}
}
$.ajax({
'type': 'POST',
'url': 'http://localhost:5000/v3/auth/tokens',
'data': JSON.stringify(data),
'contentType': 'application/json',
'dataType': 'json',
'success': function(data, code, response) {
var token = response.getResponseHeader('X-Subject-Token')
if (token == null){
log_info("Connected to Keystone, but no 'X-Subject-Token' "
+ "header was provided. Keystone's CORS filter is probably "
+ "not configured to expose this header.");
} else {
log_info("Got token from Keystone. " +
"Getting queues list from Zaqar.");
log_info(token);
list_queues(token);
};
},
'error': function(data, code, errorThrown) {
if (errorThrown) {
log_info("Keystone error: " + errorThrown);
} else {
log_info("Failed to connect to Keystone. Keystone is either" +
" offline, or CORS is not enabled in Keystone.");
}
}
});
return false;
}
</script>
</head>
<body>
<div>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_title">
<h4>Logs</h4>
<div class="clearfix"></div>
</div>
<div class="x_content">
<ul id="log" class="to_do"></ul>
</div>
</div>
</div>
<script>
$(document).ready(function () {
login();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment