You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@warble.apache.org by hu...@apache.org on 2018/06/26 15:21:07 UTC

[incubator-warble-server] branch master updated (57f2a89 -> eb3d105)

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git.


    from 57f2a89  regen openapi yaml
     new d574eab  bork if node/agent wasn't found
     new 55b0234  switch clients (agents/nodes) to their own sub-class
     new 0649d7f  Add API endpoint for node status checks
     new 9cd8ea1  remove debug line
     new 0a1040a  fix node finding and saving
     new 61c8188  add API endpoint for modifying a node
     new eb3d105  regen openapi yaml

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 api/pages/node/{register.py => modify.py}          | 62 ++++++++++-------
 api/pages/node/{register.py => status.py}          | 59 +++++-----------
 api/plugins/registry.py                            | 10 +--
 api/plugins/session.py                             | 15 ++--
 api/yaml/openapi.yaml                              | 80 ++++++++++++++++++++++
 .../openapi/components/schemas/NodeDetails.yaml    | 43 ++++++++++++
 6 files changed, 189 insertions(+), 80 deletions(-)
 copy api/pages/node/{register.py => modify.py} (50%)
 copy api/pages/node/{register.py => status.py} (51%)
 create mode 100644 api/yaml/openapi/components/schemas/NodeDetails.yaml


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org


[incubator-warble-server] 02/07: switch clients (agents/nodes) to their own sub-class

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit 55b0234f7d10ca95375d8b0fb02a6b9329b1b29a
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 09:49:12 2018 -0500

    switch clients (agents/nodes) to their own sub-class
    
    this way we can just check:
    if session.client: dostuff()
    or
    if session.user: dohumanstuff()
---
 api/plugins/session.py | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/api/plugins/session.py b/api/plugins/session.py
index bb3a406..d302b45 100644
--- a/api/plugins/session.py
+++ b/api/plugins/session.py
@@ -29,6 +29,7 @@ import traceback
 import http.cookies
 import uuid
 import time
+import plugins.registry
 
 class WarbleSession(object):
 
@@ -67,6 +68,7 @@ class WarbleSession(object):
         """
         self.config = config
         self.user = None
+        self.client = None
         self.DB = DB
         self.headers = [('Content-Type', 'application/json')]
         self.cookie = None
@@ -141,15 +143,10 @@ class WarbleSession(object):
         elif 'HTTP_APIKEY' in environ:
             cookie = environ['HTTP_APIKEY']
             if re.match(r"^[-a-f0-9]+$", cookie): # Validate cookie, must follow UUID4 specs
-                registry_conn = self.DB.sqlite.open('nodes.db')
-                rc = registry_conn.cursor()
-                rc.execute("SELECT * FROM `registry` WHERE `apikey` = ? LIMIT 1", (cookie,))
-                ndoc = rc.fetchone()
-                if ndoc:
-                    self.user = {k:ndoc[k] for k in ndoc.keys()}
-                    self.user['human'] = False
-                    self.user['userid'] = 'node:%s' % ndoc['id']
-                    self.user['userlevel'] = 'robbit'
+                try:
+                    self.client = plugins.registry.node(self, cookie)
+                except:
+                    pass
         if not cookie:
             cookie = self.newCookie()
         self.cookie = cookie


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org


[incubator-warble-server] 07/07: regen openapi yaml

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit eb3d105762663e36447f605f00e8b3020f1f5cf5
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 10:20:51 2018 -0500

    regen openapi yaml
---
 api/yaml/openapi.yaml | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/api/yaml/openapi.yaml b/api/yaml/openapi.yaml
index 7d96aff..f18c53c 100644
--- a/api/yaml/openapi.yaml
+++ b/api/yaml/openapi.yaml
@@ -73,6 +73,47 @@ components:
       - hostname
       - pubkey
       - version
+    NodeDetails:
+      properties:
+        description:
+          description: A description of the node
+          example: This is the internal node in DC1
+          type: string
+        enabled:
+          description: Whether the node is enabled or paused
+          example: true
+          type: boolean
+        hostname:
+          description: The node's own perceived hostname
+          example: foo1.warble.xyz
+          type: string
+        id:
+          description: the numeric ID of the node to modify
+          example: 42
+          type: integer
+        ip:
+          description: The IP generally associated with this client
+          type: string
+        lastping:
+          description: The last UNIX timestamp of activity from the client
+          type: integer
+        location:
+          description: Physical location of the node
+          example: DC1, Chicago, Illinois
+          type: string
+        pubkey:
+          description: The node's self-generated public RSA key, PEM-encoded
+          type: string
+        verified:
+          description: Whether the node is verified as ours or not
+          example: true
+          type: boolean
+        version:
+          description: The version of Warble the node is running
+          example: 0.1.0
+          type: string
+      required:
+      - id
     Timeseries:
       properties:
         interval:
@@ -338,6 +379,29 @@ paths:
                 $ref: '#/components/schemas/Error'
           description: unexpected error
       summary: Create a new account
+  /api/node/modify:
+    post:
+      requestBody:
+        content:
+          application/json:
+            schema:
+              $ref: '#/components/schemas/NodeDetails'
+        description: Node details to modify
+        required: true
+      responses:
+        '200':
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ActionCompleted'
+          description: Node successfully modified on server
+        default:
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Error'
+          description: unexpected error
+      summary: Modifies base data of a node in the registry
   /api/node/register:
     post:
       requestBody:
@@ -361,6 +425,22 @@ paths:
                 $ref: '#/components/schemas/Error'
           description: unexpected error
       summary: Registers a new node with the Warble server
+  /api/node/status:
+    get:
+      responses:
+        '200':
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/NodeDetails'
+          description: Node status
+        default:
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Error'
+          description: unexpected error
+      summary: Displays the current status of a node
   /api/session:
     delete:
       requestBody:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org


[incubator-warble-server] 01/07: bork if node/agent wasn't found

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit d574eab19b351c72b3c03ad31dbb2cf1b19cf52e
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 09:48:21 2018 -0500

    bork if node/agent wasn't found
---
 api/plugins/registry.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/api/plugins/registry.py b/api/plugins/registry.py
index 42ae0a3..4050fd6 100644
--- a/api/plugins/registry.py
+++ b/api/plugins/registry.py
@@ -76,7 +76,8 @@ class node(object):
                 self.version = doc['version']
                 self.key = plugins.crypto.loads(self.pem)
                 self.fingerprint = plugins.crypto.fingerprint(self.pem)
-        
+            else:
+                raise Exception("No such node found in registry")
         # new node from scratch?
         else:
             self.apikey = str(uuid.uuid4())


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org


[incubator-warble-server] 03/07: Add API endpoint for node status checks

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit 0649d7f4a61d7b414ff2f257b57affb455a1edf0
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 10:07:28 2018 -0500

    Add API endpoint for node status checks
    
    Used for the node software to check if the node is enabled/verified or
    not
---
 api/pages/node/status.py                           | 68 ++++++++++++++++++++++
 .../openapi/components/schemas/NodeDetails.yaml    | 43 ++++++++++++++
 2 files changed, 111 insertions(+)

diff --git a/api/pages/node/status.py b/api/pages/node/status.py
new file mode 100644
index 0000000..8100526
--- /dev/null
+++ b/api/pages/node/status.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+########################################################################
+# OPENAPI-URI: /api/node/status
+########################################################################
+# get:
+#   responses:
+#     '200':
+#       content:
+#         application/json:
+#           schema:
+#             $ref: '#/components/schemas/NodeDetails'
+#       description: Node status
+#     default:
+#       content:
+#         application/json:
+#           schema:
+#             $ref: '#/components/schemas/Error'
+#       description: unexpected error
+#   summary: Displays the current status of a node
+# 
+########################################################################
+
+
+
+
+
+"""
+This is the node status handler for Apache Warble
+"""
+
+import json
+import plugins.crypto
+import plugins.registry
+
+def run(API, environ, indata, session):
+    
+    method = environ['REQUEST_METHOD']
+    
+    # Modifying a node?
+    if method == "GET":
+        if session.client: 
+            yield json.dumps({
+                'id': session.client.id,
+                'enabled': session.client.enabled,
+                'verified': session.client.verified
+                }, indent = 2)
+            return
+        else:
+            raise API.exception(404, "Unknown API Key passed by client")
+
+    # Finally, if we hit a method we don't know, balk!
+    yield API.exception(400, "I don't know this request method!!")
+    
diff --git a/api/yaml/openapi/components/schemas/NodeDetails.yaml b/api/yaml/openapi/components/schemas/NodeDetails.yaml
new file mode 100644
index 0000000..5534cdc
--- /dev/null
+++ b/api/yaml/openapi/components/schemas/NodeDetails.yaml
@@ -0,0 +1,43 @@
+########################################################################
+# NodeDetails                                                          #
+########################################################################
+properties:
+  id:
+    description: the numeric ID of the node to modify
+    example: 42
+    type: integer
+  verified:
+    description: Whether the node is verified as ours or not
+    example: true
+    type: boolean
+  enabled:
+    description: Whether the node is enabled or paused
+    example: true
+    type: boolean
+  hostname:
+    description: The node's own perceived hostname
+    example: foo1.warble.xyz
+    type: string
+  pubkey:
+    description: The node's self-generated public RSA key, PEM-encoded
+    type: string
+  version:
+    description: The version of Warble the node is running
+    type: string
+    example: 0.1.0
+  description:
+    description: A description of the node
+    type: string
+    example: This is the internal node in DC1
+  location:
+    description: Physical location of the node
+    type: string
+    example: DC1, Chicago, Illinois
+  ip:
+    description: The IP generally associated with this client
+    type: string
+  lastping:
+    description: The last UNIX timestamp of activity from the client
+    type: integer
+required:
+  - id


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org


[incubator-warble-server] 05/07: fix node finding and saving

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit 0a1040a4d0923d1c21fc6ea0356404f7fb3cbe79
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 10:20:23 2018 -0500

    fix node finding and saving
    
    - re must be done on a string, not a number
    - save location as well
---
 api/plugins/registry.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/api/plugins/registry.py b/api/plugins/registry.py
index 1f8c39a..dd62117 100644
--- a/api/plugins/registry.py
+++ b/api/plugins/registry.py
@@ -50,7 +50,7 @@ class node(object):
             doc = None
             nc = self.conn.cursor()
             # Load by API Key?
-            if re.match(r"^[a-f0-9]+-[a-f0-9-]+$", nodeid):
+            if isinstance(nodeid, str) and re.match(r"^[a-f0-9]+-[a-f0-9-]+$", nodeid):
                 self.apikey = nodeid
                 nc.execute("SELECT * FROM `registry` WHERE `apikey` = ? LIMIT 1", (self.apikey,))
                 doc = nc.fetchone()
@@ -93,8 +93,8 @@ class node(object):
                 )
         # Save an existing node?
         else:
-            nc.execute("UPDATE `registry` SET `hostname` = ?, `apikey` = ?, `pubkey` = ?, `verified` = ?, `enabled` = ?, `ip` = ?, `lastping` = ?, `version` = ? WHERE `id` = ? LIMIT 1",
-                    (self.hostname, self.apikey, self.pem, 1 if self.verified else 0, 1 if self.enabled else 0, self.ip, self.lastping, self.version, self.id,)
+            nc.execute("UPDATE `registry` SET `hostname` = ?, `apikey` = ?, `pubkey` = ?, `location`= ?, `verified` = ?, `enabled` = ?, `ip` = ?, `lastping` = ?, `version` = ? WHERE `id` = ? LIMIT 1",
+                    (self.hostname, self.apikey, self.pem, self.location, 1 if self.verified else 0, 1 if self.enabled else 0, self.ip, self.lastping, self.version, self.id,)
                 )
         self.conn.commit()
     


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org


[incubator-warble-server] 06/07: add API endpoint for modifying a node

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit 61c81887aca13a6e66f9d319a47415283b0c2c9c
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 10:20:35 2018 -0500

    add API endpoint for modifying a node
---
 api/pages/node/modify.py | 107 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/api/pages/node/modify.py b/api/pages/node/modify.py
new file mode 100644
index 0000000..de321a6
--- /dev/null
+++ b/api/pages/node/modify.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+########################################################################
+# OPENAPI-URI: /api/node/modify
+########################################################################
+# post:
+#   requestBody:
+#     content:
+#       application/json:
+#         schema:
+#           $ref: '#/components/schemas/NodeDetails'
+#     description: Node details to modify
+#     required: true
+#   responses:
+#     '200':
+#       content:
+#         application/json:
+#           schema:
+#             $ref: '#/components/schemas/ActionCompleted'
+#       description: Node successfully modified on server
+#     default:
+#       content:
+#         application/json:
+#           schema:
+#             $ref: '#/components/schemas/Error'
+#       description: unexpected error
+#   summary: Modifies base data of a node in the registry
+# 
+########################################################################
+
+
+
+
+
+"""
+This is the node modification handler for Apache Warble
+"""
+
+import json
+import re
+import time
+import plugins.crypto
+import plugins.registry
+import base64
+
+def run(API, environ, indata, session):
+    
+    method = environ['REQUEST_METHOD']
+    
+    # Modifying a node?
+    if method == "POST":
+        # Super users only!
+        if not session.user or session.user['userlevel'] != 'superuser':
+            raise API.exception(403, "You need to be logged in as super user to perform this action")
+        
+        
+        # Try finding the node in the registry
+        nodeid = indata['id']
+        node = None
+        try:
+            node = plugins.registry.node(session, nodeid)
+        except:
+            raise API.exception(404, "Could not find a node by this ID to modify.")
+        
+        # Save any changes we get
+        if 'verified' in indata:
+            node.verified = indata['verified']
+        if 'enabled' in indata:
+            node.enabled = indata['enabled']
+        if 'hostname' in indata and indata['hostname']:
+            node.hostname = indata['hostname']
+        if 'pubkey' in indata and indata['pubkey']:
+            # Verify that PEM works:
+            try:
+                plugins.crypto.loads(indata['pubkey'])
+            except:
+                raise API.exception(400, "Could not save changes: Bad PEM payload passed!")
+            node.pubkey = indata['pubkey']
+        if 'description' in indata and indata['description']:
+            node.description = indata['description']
+        if 'location' in indata and indata['location']:
+            node.location = indata['location']
+        
+        # All done, save node and exit
+        node.save()
+        del node # just to be sure
+        
+        yield json.dumps({"okay": True, "message": "Changes saved"}, indent = 2)
+        return
+
+    # Finally, if we hit a method we don't know, balk!
+    yield API.exception(400, "I don't know this request method!!")
+    


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org


[incubator-warble-server] 04/07: remove debug line

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-warble-server.git

commit 9cd8ea17aa23073b03ac520d0c5a5f6dd3d3c9d5
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Jun 26 10:10:32 2018 -0500

    remove debug line
---
 api/plugins/registry.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/api/plugins/registry.py b/api/plugins/registry.py
index 4050fd6..1f8c39a 100644
--- a/api/plugins/registry.py
+++ b/api/plugins/registry.py
@@ -30,7 +30,6 @@ class node(object):
     
     def __init__(self, session, nodeid = None):
         """ Loads a node from the registry or inits a new one """
-        print("registered node")
         self._data = {}
         self.session = session
         self.conn = session.DB.sqlite.open('nodes.db')


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@warble.apache.org
For additional commands, e-mail: commits-help@warble.apache.org