Skip to content

Commit

Permalink
add permissions to restart CEP
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Dec 5, 2023
1 parent d128b07 commit f37a00a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 33 deletions.
33 changes: 19 additions & 14 deletions analytics-service/c8y_agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import logging
import requests
from dotenv import load_dotenv
from c8y_api.app import MultiTenantCumulocityApp
from c8y_api.model import Binary
import json


# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
# import http.client as http_client

# http_client.HTTPConnection.debuglevel = 1
# # You must initialize logging, otherwise you'll not see debug output.
# logging.basicConfig()
# logging.getLogger().setLevel(logging.DEBUG)
# requests_log = logging.getLogger("requests.packages.urllib3")
# requests_log.setLevel(logging.DEBUG)
# requests_log.propagate = True

class C8YAgent:
def __init__(self):
self._logger = logging.getLogger("C8YAgent")
self._logger.setLevel(logging.INFO)
self._logger.setLevel(logging.DEBUG)
load_dotenv()
# c8y
self.c8yapp = MultiTenantCumulocityApp()
Expand All @@ -25,21 +39,12 @@ def upload_extension(self, extension_name, ext_file, request_headers):
return b.id

def restart_cep(self,request_headers):
result = {}
try:
self._logger.info(f"Restarted CEP!")
# self.c8yapp.get_tenant_instance(headers=request_headers).put(resource="/service/cep/restart", json="")
# self.c8yapp.bootstrap_instance.put(resource="/service/cep/restart", json="")
self.c8yapp.bootstrap_instance.put(resource="/service/cep/restart", json={})
self._logger.info(f"Restarting CEP ...")
self.c8yapp.get_tenant_instance(headers=request_headers).put(resource="/service/cep/restart", json={})
except Exception as e:
self._logger.error(f"Ignoring exceptiom!", exc_info=True)
# try:
# self._logger.info(f"Restarted CEP Format 2")
# result = self.c8y_client.put(resource="/service/cep/restart", json={})
# except:
# self._logger.info(f"Restarted CEP Format 3")
# result = self.c8y_client.put(
# resource="/service/cep/restart", json=json.dumps({})
# )
# for keys,values in request_headers.items():
# self._logger.info(f"Headers: {keys} {values}")

self._logger.info(f"Restarted CEP!")
3 changes: 2 additions & 1 deletion analytics-service/cumulocity.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ROLE_OPTION_MANAGEMENT_ADMIN",
"ROLE_INVENTORY_ADMIN",
"ROLE_INVENTORY_READ",
"ROLE_INVENTORY_CREATE"
"ROLE_INVENTORY_CREATE",
"ROLE_CEP_MANAGEMENT_ADMIN"
],
"roles": []
}
16 changes: 6 additions & 10 deletions analytics-service/flask_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
def health():
return '{"status":"UP"}'

# this endpoint was only exposed for test purposes
# @app.route("/service/cep/restart", methods=["PUT"])
# def restart():
# agent.restart_cep(request_headers=request.headers)
# return f"OK", 200

# download the content from github
# params:
# url url of monitor to download
Expand Down Expand Up @@ -90,19 +96,9 @@ def create_extension():
logger.info(f"... in temp dir: {work_temp_dir}")
# step 1: download all monitors
for monitor in monitors:
# organization, repository_name, file_path, file_name = extract_path(
# monitor
# )
# logger.info(
# f"File ( path / file_name ) : ({file_path} / {file_name} )"
# )

# get repository
# repo = gh.get_repo(f"{organization}/{repository_name}")

# get the contents of the file
try:
# file_content = repo.get_contents(file_path).decoded_content
file_name = extract_raw_path(monitor)
monitor_code = requests.get(monitor, allow_redirects=True)

Expand Down
4 changes: 2 additions & 2 deletions analytics-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion analytics-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "analytics-extension",
"version": "2.1.7",
"version": "2.1.8",
"description": "Extends the standard Cumulocity administration web application with a dialog to add Analytics Builder extensions.",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
<table class="table table-condensed table-striped">
<thead>
<tr>
<th>Block Name</th>
<th style="width: 15%">Block Name</th>
<th style="width: 10%">Block Category</th>
<th>Block Description</th>
<th>Block Category</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let block of extension?.analytics">
<td>{{ block.id }}</td>
<td>{{ block.description }}</td>
<td>{{ block.category }}</td>
<td [title]="block.id">{{ block.id }}</td>
<td [title]="block.category">{{ block.category }}</td>
<td [title]="block.description">{{ block.description }}</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit f37a00a

Please sign in to comment.