code: def build_ports_dict(nsg, direction_key, ip_protocol):
          
          rules = nsg['properties']['securityRules']
          rules = sorted(rules, key=lambda k: k['properties']['priority'])
          ports = {}
  
          for rule in rules:
              # Skip rules with different direction
              if not StringUtils.equal(direction_key, rule['properties']['direction']):
                  continue
  
              # Check the protocol: possible values are 'TCP', 'UDP', '*' (both)
              # Skip only if rule and ip_protocol are 'TCP'/'UDP' pair.
              protocol = rule['properties']['protocol']
              if not StringUtils.equal(protocol, "*") and \
                 not StringUtils.equal(ip_protocol, "*") and \
                 not StringUtils.equal(protocol, ip_protocol):
                  continue
  
              IsAllowed = StringUtils.equal(rule['properties']['access'], 'allow')
              ports_set = PortsRangeHelper.get_ports_set_from_rule(rule)
  
              for p in ports_set:
                  if p not in ports:
                      ports[p] = IsAllowed
  
          return ports
docs: Build entire ports array filled with True (Allow), False (Deny) and None(default - Deny)
              based on the provided Network Security Group object, direction and protocol.