1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
# This software is distributed under the terms and conditions of the 'Apache-2.0'
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
import os
import json
import copy
from uuid import uuid4
from oslo_log import log as logging
from oslo_config import cfg
from moon_utilities import exceptions
from moon_db.core import PDPManager
from moon_utilities.misc import get_uuid_from_name
from moon_utilities.security_functions import call
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
class PDP(object):
def __init__(self):
self.manager = PDPManager
def get_pdp(self, ctx, args=None):
try:
data = self.manager.get_pdp(user_id=ctx["user_id"], pdp_id=ctx.get("id"))
except Exception as e:
LOG.error(e, exc_info=True)
return {"result": False,
"error": str(e),
"ctx": ctx, "args": args}
return {"pdps": data}
def add_pdp(self, ctx, args):
try:
data = self.manager.add_pdp(user_id=ctx["user_id"], pdp_id=None, value=args)
except Exception as e:
LOG.error(e, exc_info=True)
return {"result": False,
"error": str(e),
"ctx": ctx, "args": args}
return {"pdps": data}
def delete_pdp(self, ctx, args):
try:
data = self.manager.delete_pdp(user_id=ctx["user_id"], pdp_id=ctx.get("id"))
except Exception as e:
LOG.error(e, exc_info=True)
return {"result": False,
"error": str(e),
"ctx": ctx, "args": args}
return {"result": True}
def update_pdp(self, ctx, args):
try:
data = self.manager.update_pdp(user_id=ctx["user_id"], pdp_id=ctx.get("id"), value=args)
call("orchestrator", method="add_container",
ctx={"id": ctx.get("id"), "pipeline": data[ctx.get("id")]['security_pipeline']})
except Exception as e:
LOG.error(e, exc_info=True)
return {"result": False,
"error": str(e),
"ctx": ctx, "args": args}
return {"pdps": data}
|