Skip to content

Commit

Permalink
Implemented registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Chelsea486MHz committed Jan 4, 2024
1 parent 3f63742 commit 3ca02df
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
29 changes: 21 additions & 8 deletions compute/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
# Initialize Flask
app = Flask(__name__)

# Register to the manager node
manager = os.environ.get('MANAGER_ENDPOINT')
print('Attempting registration with manager node at {}...'.format(manager))
response = requests.post('{}/api/manager/register'.format(manager),
headers={'Authorization': os.environ.get('TOKEN')},
json={'compute_endpoint': os.environ.get('ENDPOINT')},
timeout=5)
if not response.json().get('success'):
print('FATAL: Failed to register with the manager node.')
exit(1)
else:
print('Registered.')


def authenticate(request, type='any'):
# Convert type to integer
Expand Down Expand Up @@ -61,56 +74,56 @@ def api_common_type():
def api_compute_update():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/compute/configure', methods=['POST'])
def api_compute_configure():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/compute/assign', methods=['POST'])
def api_compute_assign():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/compute/potential/gravity', methods=['POST'])
def api_compute_potential_gravity():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/compute/potential/electrostatic', methods=['POST'])
def api_compute_potential_electrostatic():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/compute/force/gravity', methods=['POST'])
def api_compute_force_gravity():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/compute/force/electrostatic', methods=['POST'])
def api_compute_force_electrostatic():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/compute/integrate', methods=['POST'])
def api_compute_integrate():
if not authenticate(request, 'manager'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


if __name__ == '__main__':
Expand Down
13 changes: 7 additions & 6 deletions deployments/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ services:
- auth
- manager
environment:
AUTH_ENDPOINT: 'http://auth:5000'
MANAGER_ENDPOINT: 'http://manager:5000'
TOKEN: 'Kq5AfYtpYkcGbPnm0z2I_SIRGRem-zKmXA5rnPguUIB7y2DNQTW1KIYouV9IaHH6'
ENDPOINT: 'http://compute:5000' # How this node can be reached
AUTH_ENDPOINT: 'http://auth:5000' # Where to reach the Stargazer authentication gateway
MANAGER_ENDPOINT: 'http://manager:5000' # Where to reach the Stargazer manager
TOKEN: 'Kq5AfYtpYkcGbPnm0z2I_SIRGRem-zKmXA5rnPguUIB7y2DNQTW1KIYouV9IaHH6' # Compute token unique to this node used to authenticate with the manager

auth:
image: chelsea486mhz/stargazer-auth
restart: unless-stopped
environment:
USER_TOKEN: 'DrERUGbWdDltQmkii0Mswney_dgDnUKFAwMC-TYB-C2zMnOuQeHgPtsHhBWzgoIg'
USER_TOKEN: 'DrERUGbWdDltQmkii0Mswney_dgDnUKFAwMC-TYB-C2zMnOuQeHgPtsHhBWzgoIg' # User token

manager:
image: chelsea486mhz/stargazer-manager
restart: unless-stopped
depends_on:
- auth
environment:
AUTH_ENDPOINT: 'http://auth:5000'
TOKEN: '3gEy0rWMRqXfJw9aLKzzSuhXggxGTLL4bYsTt-VdmFcmOWQ_ZCwTswvZM6kNVg2r'
AUTH_ENDPOINT: 'http://auth:5000' # Where to reach the Stargazer authentication gateway
TOKEN: '3gEy0rWMRqXfJw9aLKzzSuhXggxGTLL4bYsTt-VdmFcmOWQ_ZCwTswvZM6kNVg2r' # Manager token unique to this node
8 changes: 4 additions & 4 deletions manager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ def api_common_type():
def api_manager_register():
if not authenticate(request, 'compute'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/manager/unregister', methods=['POST'])
def api_manager_unregister():
if not authenticate(request, 'compute'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/manager/configure', methods=['POST'])
def api_manager_configure():
if not authenticate(request, 'user'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


@app.route('/api/manager/simulate', methods=['POST'])
def api_manager_simulate():
if not authenticate(request, 'user'):
return 'Unauthorized', 401
return response
return jsonify({'success': True}), 200


if __name__ == '__main__':
Expand Down

0 comments on commit 3ca02df

Please sign in to comment.