Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 16 | import json |
Scott Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame] | 17 | from xossynchronizer.event_steps.eventstep import EventStep |
Matteo Scandolo | de8cfa8 | 2018-10-16 13:49:05 -0700 | [diff] [blame] | 18 | from helpers import AttHelpers |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 19 | |
Scott Baker | c2a633d | 2019-04-01 19:27:41 -0700 | [diff] [blame] | 20 | |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 21 | class SubscriberAuthEventStep(EventStep): |
| 22 | topics = ["authentication.events"] |
| 23 | technology = "kafka" |
| 24 | |
| 25 | def __init__(self, *args, **kwargs): |
| 26 | super(SubscriberAuthEventStep, self).__init__(*args, **kwargs) |
| 27 | |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 28 | def process_event(self, event): |
| 29 | value = json.loads(event.value) |
| 30 | |
Scott Baker | 71d2047 | 2019-02-01 12:05:35 -0800 | [diff] [blame] | 31 | onu_sn = AttHelpers.get_onu_sn(self.model_accessor, self.log, value) |
| 32 | si = AttHelpers.get_si_by_sn(self.model_accessor, self.log, onu_sn) |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 33 | if not si: |
Scott Baker | c2a633d | 2019-04-01 19:27:41 -0700 | [diff] [blame] | 34 | self.log.exception( |
| 35 | "authentication.events: Cannot find att-workflow-driver service instance for this event", |
| 36 | kafka_event=value) |
Matteo Scandolo | de8cfa8 | 2018-10-16 13:49:05 -0700 | [diff] [blame] | 37 | raise Exception("authentication.events: Cannot find att-workflow-driver service instance for this event") |
Matteo Scandolo | ad0c175 | 2018-08-09 15:47:16 -0700 | [diff] [blame] | 38 | |
Matteo Scandolo | 9c6541f | 2019-03-01 10:12:44 -0800 | [diff] [blame] | 39 | self.log.info("authentication.events: Got event for subscriber", event_value=value, onu_sn=onu_sn, si=si) |
| 40 | |
Scott Baker | c2a633d | 2019-04-01 19:27:41 -0700 | [diff] [blame] | 41 | si.authentication_state = value["authenticationState"] |
Andy Bavier | 0d631eb | 2018-10-17 18:05:04 -0700 | [diff] [blame] | 42 | si.save_changed_fields(always_update_timestamp=True) |