blob: 2d9f4d7ae0213b5b789508e08665b7613bb76551 [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
Scott Baker71d20472019-02-01 12:05:35 -080020from xossynchronizer.event_steps.eventstep import EventStep
Matteo Scandolode8cfa82018-10-16 13:49:05 -070021from helpers import AttHelpers
Matteo Scandoload0c1752018-08-09 15:47:16 -070022
23class SubscriberAuthEventStep(EventStep):
24 topics = ["authentication.events"]
25 technology = "kafka"
26
27 def __init__(self, *args, **kwargs):
28 super(SubscriberAuthEventStep, self).__init__(*args, **kwargs)
29
Matteo Scandoload0c1752018-08-09 15:47:16 -070030 def process_event(self, event):
31 value = json.loads(event.value)
32
Scott Baker71d20472019-02-01 12:05:35 -080033 onu_sn = AttHelpers.get_onu_sn(self.model_accessor, self.log, value)
34 si = AttHelpers.get_si_by_sn(self.model_accessor, self.log, onu_sn)
Matteo Scandoload0c1752018-08-09 15:47:16 -070035 if not si:
Matteo Scandolode8cfa82018-10-16 13:49:05 -070036 self.log.exception("authentication.events: Cannot find att-workflow-driver service instance for this event", kafka_event=value)
37 raise Exception("authentication.events: Cannot find att-workflow-driver service instance for this event")
Matteo Scandoload0c1752018-08-09 15:47:16 -070038
Matteo Scandolo9c6541f2019-03-01 10:12:44 -080039 self.log.info("authentication.events: Got event for subscriber", event_value=value, onu_sn=onu_sn, si=si)
40
Matteo Scandoload0c1752018-08-09 15:47:16 -070041 si.authentication_state = value["authenticationState"];
Andy Bavier0d631eb2018-10-17 18:05:04 -070042 si.save_changed_fields(always_update_timestamp=True)