blob: 6786c9864989f6a2fd8c9c1688f502be2cd8f2a9 [file] [log] [blame]
Matteo Scandoload0c1752018-08-09 15:47:16 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import json
17import time
18import os
19import sys
20from synchronizers.new_base.eventstep import EventStep
Matteo Scandolode8cfa82018-10-16 13:49:05 -070021from synchronizers.new_base.modelaccessor import model_accessor
22from helpers import AttHelpers
Matteo Scandoload0c1752018-08-09 15:47:16 -070023
24class SubscriberAuthEventStep(EventStep):
25 topics = ["authentication.events"]
26 technology = "kafka"
27
28 def __init__(self, *args, **kwargs):
29 super(SubscriberAuthEventStep, self).__init__(*args, **kwargs)
30
Matteo Scandoload0c1752018-08-09 15:47:16 -070031 def process_event(self, event):
32 value = json.loads(event.value)
33
Matteo Scandolode8cfa82018-10-16 13:49:05 -070034 onu_sn = AttHelpers.get_onu_sn(value)
35 si = AttHelpers.get_si_by_sn(onu_sn)
Matteo Scandoload0c1752018-08-09 15:47:16 -070036 if not si:
Matteo Scandolode8cfa82018-10-16 13:49:05 -070037 self.log.exception("authentication.events: Cannot find att-workflow-driver service instance for this event", kafka_event=value)
38 raise Exception("authentication.events: Cannot find att-workflow-driver service instance for this event")
Matteo Scandoload0c1752018-08-09 15:47:16 -070039
40 si.authentication_state = value["authenticationState"];
Matteo Scandolode8cfa82018-10-16 13:49:05 -070041 si.save(update_fields=["authentication_state", "updated"], always_update_timestamp=True)