X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Futils.py;h=16a47332cf284cba606dc27b5af3e281d902e15a;hp=62892eb09b6004afe305fb4f893b1fba11915b44;hb=7077e2601a209a87f7fe397b35586e7701ca759a;hpb=2f66c4df28308b5b2747bb207e7797932e502436 diff --git a/n2vc/utils.py b/n2vc/utils.py index 62892eb..16a4733 100644 --- a/n2vc/utils.py +++ b/n2vc/utils.py @@ -12,11 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. +import base64 +import re +import binascii from enum import Enum from juju.machine import Machine from juju.application import Application from juju.action import Action from juju.unit import Unit +from n2vc.exceptions import N2VCInvalidCertificate + + +def base64_to_cacert(b64string): + """Convert the base64-encoded string containing the VCA CACERT. + + The input string.... + + """ + try: + cacert = base64.b64decode(b64string).decode("utf-8") + + cacert = re.sub(r"\\n", r"\n", cacert,) + except binascii.Error as e: + raise N2VCInvalidCertificate(message="Invalid CA Certificate: {}".format(e)) + + return cacert class N2VCDeploymentStatus(Enum): @@ -67,36 +87,24 @@ class EntityType(Enum): return cls.get_entity(v) -FinalStatus = Dict( - { - EntityType.MACHINE: Dict({"field": "agent_status", "status": ["started"]}), - EntityType.APPLICATION: Dict( - {"field": "status", "status": ["active", "blocked"]} - ), - EntityType.ACTION: Dict( - {"field": "status", "status": ["completed", "failed", "cancelled"]} - ), - } -) - JujuStatusToOSM = { - EntityType.MACHINE: { + "machine": { "pending": N2VCDeploymentStatus.PENDING, "started": N2VCDeploymentStatus.COMPLETED, }, - EntityType.APPLICATION: { + "application": { "waiting": N2VCDeploymentStatus.RUNNING, "maintenance": N2VCDeploymentStatus.RUNNING, "blocked": N2VCDeploymentStatus.RUNNING, "error": N2VCDeploymentStatus.FAILED, "active": N2VCDeploymentStatus.COMPLETED, }, - EntityType.ACTION: { + "action": { "pending": N2VCDeploymentStatus.PENDING, "running": N2VCDeploymentStatus.RUNNING, "completed": N2VCDeploymentStatus.COMPLETED, }, - EntityType.UNIT: { + "unit": { "waiting": N2VCDeploymentStatus.RUNNING, "maintenance": N2VCDeploymentStatus.RUNNING, "blocked": N2VCDeploymentStatus.RUNNING,