Beispiel #1
0
    def _get_details(self,
                     *,
                     json_payload: {} = None) -> None:  # todo: handle paging
        if json_payload:
            json_body = json_payload
        else:
            json_body = bss_api.get_subscription_by_subscription_id(
                self.environment, self.id)

        self.part_number = json_body.get("PartNumber")
        self.id = json_body.get("Id")
        self.part_quantity = json_body.get("EntitlementQuantity")
        self.customer_id = json_body.get("CustomerId")
        self.state = json_body.get("SubscriptionState")
        self.available_numbers_of_seats = json_body.get(
            "NumberOfAvailableSeats")
        self.modified = parse_time(json_body.get("Modified"))
        self.created = parse_time(json_body.get("Created"))
        self.duration_length = json_body.get("DurationLength")
        self.duration_unit = json_body.get("DurationUnits")
        self.entitlement_quantity_available = json_body.get(
            "EntitlementQuantityAvailable")
        self.max_number_of_seats = json_body.get("MaxNumberOfSeats")
        self.is_automatically_renewed = json_body.get("IsAutomaticallyRenewed")
        self.purchase_date = parse_time(json_body.get("PurchaseDate"))
        self.is_trial = json_body.get("IsTrial")
        self.deleted = json_body.get("Deleted")
        self.is_beta = json_body.get("IsBeta")
        self.is_free = json_body.get("IsFree")
        self.parent_subscription_id = json_body.get("ParentSubscriptionId")
        self.billing_frequency = json_body.get("BillingFrequency")
        self.expiration_date = parse_time(json_body.get("ExpirationDate"))
        self.effective_date = parse_time(json_body.get("EffectiveDate"))
Beispiel #2
0
    def _cleanup(self,
                 *,
                 environment="",
                 customer_id=0,
                 part_number="",
                 id=0,
                 part_quantity=0,
                 state=State.UNSET.value,
                 available_seats=0,
                 modified="01/01/1970 00:00:00",
                 created="01/01/1970 00:00:00",
                 duration_length=0,
                 duration_unit=0,
                 entitlement_quantity_available=0,
                 max_number_of_seats=0,
                 is_automatically_renewed=False,
                 purchase_date="01/01/1970 00:00:00",
                 is_trial=False,
                 deleted=False,
                 is_beta=False,
                 is_free=False,
                 parent_subscription_id=0,
                 billing_frequency="",
                 effective_date="01/01/1970 00:00:00",
                 expiration_date="01/01/1970 00:00:00") -> None:
        self.environment: str = environment
        self.part_number: str = part_number
        self.id: int = id
        self.customer_id: int = customer_id
        self.part_quantity: int = part_quantity

        self.state: State = state
        self.available_numbers_of_seats: int = available_seats
        self.modified: datetime = parse_time(modified)
        self.created: datetime = parse_time(created)
        self.duration_length: int = duration_length
        self.duration_unit: int = duration_unit

        self.entitlement_quantity_available: int = entitlement_quantity_available
        self.max_number_of_seats: int = max_number_of_seats
        self.is_automatically_renewed: bool = is_automatically_renewed
        self.purchase_date: datetime = parse_time(purchase_date)
        self.is_trial: bool = is_trial
        self.deleted: bool = deleted
        self.is_beta: bool = is_beta
        self.is_free: bool = is_free
        self.parent_subscription_id: int = parent_subscription_id
        self.billing_frequency: str = billing_frequency

        self.effective_date: datetime = parse_time(effective_date)
        self.expiration_date: datetime = parse_time(expiration_date)
Beispiel #3
0
    def __init__(self,
                 environment: str,
                 *,
                 customer_id: int = 0,
                 org_name: str = "",
                 owner: str = 0,
                 modified: datetime = "01/01/1970 00:00:00",
                 is_guest: bool = False,
                 created: datetime = "01/01/1970 00:00:00",
                 subscriber_state: str = bss_enums.State.UNSET.value,
                 party_role_type=None,
                 deleted: datetime = "01/01/1970 00:00:00",
                 role_set=None,
                 id: int = 0,
                 email: str = "",
                 given_name: str = "",
                 family_name: str = "",
                 name_prefix: str = "",
                 name_suffix: str = "",
                 security_realm: bss_enums.State = "",
                 employee_number: str = ""):

        self.environment: str = environment
        self.email: str = email
        self.given_name: str = given_name
        self.family_name: str = family_name
        self.id: int = id
        self.org_name: str = org_name
        self.owner: int = owner
        self.modified: datetime = parse_time(modified)
        self.is_guest: bool = is_guest
        self.created: datetime = parse_time(created)
        self.state: str = bss_enums.State(subscriber_state).value
        self.party_role_type = party_role_type
        self.deleted: bool = deleted
        self.customer_id: int = customer_id
        self.role_set = role_set

        self.name_prefix: str = name_prefix
        self.name_suffix: str = name_suffix
        self.security_realm: str = security_realm
        self.employee_number: str = employee_number

        self.seat_set: {Seat} = {}
        self.entitlements: [int] = []
Beispiel #4
0
 def __int__(self):
     self.owner: int = 0
     self.modified: datetime = parse_time("01/01/1970 00:00:00")
     self.terms_of_use_id: int = 0
     self.vendor_id: int = 0
     self.created: datetime = parse_time("01/01/1970 00:00:00")
     self.seat_state: str = 'SeatState'  # ASSIGNED
     self.subscription_id: int = 0
     self.entitlement_quantity_allocated: int = 0
     self.version: int = 0
     self.provisioning_workflow_id: int = 0
     self.subscriber_id: int = 0
     self.seat_service_product_attribute_set: [] = []  # [],
     self.workflow_id_list: [] = []  # [],
     self.deleted: bool = False
     self.id: int = 0
     self.terms_of_user_id: int = 0
     self.has_accepted_terms_of_use: bool = True
Beispiel #5
0
    def _get_details_by_id(self,
                           json_body=None) -> None:  # todo: handle paging
        if json_body:
            json_body = json_body
        else:
            json_body = bss_api.get_subscriber_by_id(self.environment, self.id)

        person_json = json_body.get("Person")
        self.email: str = person_json.get("EmailAddress")
        self.given_name: str = person_json.get("GivenName")
        self.family_name: str = person_json.get("FamilyName")
        self.id: int = json_body.get("Id")
        self.org_name: str = person_json.get("OrgName")
        self.owner: int = person_json.get("Owner")
        self.modified: datetime = parse_time(person_json.get("Modified"))
        self.is_guest: bool = json_body.get("IsGuest")
        self.created: datetime = parse_time(person_json.get("Created"))
        self.state: str = bss_enums.State(
            json_body.get("SubscriberState")).value
        self.party_role_type: str = bss_enums.PartyRollType(
            json_body.get("PartyRoleType")).value
        self.deleted: bool = person_json.get("Deleted")
        self.customer_id: int = json_body.get("CustomerId")

        for seat in json_body.get("SeatSet"):
            self.seat_set[seat.get("SubscriptionId")] = Seat.from_json(seat)
            self.entitlements.append(seat.get("SubscriptionId"))
        self.role_set = person_json.get("RoleSet")

        self.name_prefix: str = person_json.get("NamePrefix")
        self.name_suffix: str = person_json.get("NameSuffix")
        self.security_realm: str = bss_enums.SecurityRealm(
            person_json.get("SecurityRealm")).value
        self.employee_number: str = person_json.get("EmployeeNumber")
        self.invited_by: str = json_body.get("InvitedBy")
        self.is_sync_pending: str = json_body.get("IsSyncPending")
        self.is_restricted_use: str = person_json.get("IsRestrictedUse")
        self.language_preference: str = person_json.get("LanguagePreference")
        self.security_realm: str = person_json.get("SecurityRealm")
Beispiel #6
0
 def _get_details_by_id(self, json_body):
     self.owner = json_body.get('Owner', 0)
     self.modified = parse_time(
         json_body.get('Modified', parse_time("01/01/1970 00:00:00")))
     self.terms_of_use_id = json_body.get('TermsOfUseId', 0)
     self.vendor_id = json_body.get('VendorId', 0)
     self.created = parse_time(
         json_body.get('Created', parse_time("01/01/1970 00:00:00")))
     self.seat_state = json_body.get('SeatState', '')  # ASSIGNED
     self.subscription_id = json_body.get('SubscriptionId', 0)
     self.entitlement_quantity_allocated = json_body.get(
         'EntitlementQuantityAllocated', 0)
     self.version = json_body.get('Version', 0)
     self.provisioning_workflow_id = json_body.get('ProvisioningWorkflowId',
                                                   0)
     self.subscriber_id = json_body.get('SubscriberId', 0)
     self.seat_service_product_attribute_set = json_body.get(
         'SeatServiceProductAttributeSet', [])  # [],
     self.workflow_id_list = json_body.get('WorkflowIdList', [])  # [],
     self.deleted = json_body.get('Deleted', 'False')
     self.id = json_body.get('Id', 0)
     self.has_accepted_terms_of_use = json_body.get('HasAcceptedTermsOfUse',
                                                    0)
Beispiel #7
0
 def __init__(self,
              *,
              state_code,
              postal_code,
              city,
              state,
              country,
              country_code,
              address_type,
              modified,
              address_line_1="",
              address_line_2=""):
     self.state_code = state_code
     self.postal_code = postal_code
     self.city = city
     self.modified = parse_time(modified)
     self.address_line_1 = address_line_1
     self.address_line_2 = address_line_2
     self.state = state
     self.country = country
     self.country_code = country_code
     self.address_type: AddressType = AddressType.BILLING  # todo : enum for this.
Beispiel #8
0
    def check_for_updates(self) -> bool:
        """
          Compares current Organization object with live server data and updates if there are differences.

          :returns: **if** an update was made
          :rtype: bool

          :example:
          >>> my_organization.check_for_updates()

        """
        resp = bss_api.get_org_by_id(self.environment, self.id)
        was_updated = False
        organization = resp.get("Customer").get("Organization")
        contact = resp.get("Customer").get("Organization").get("Contact")
        address_set = resp.get("Customer").get("Organization").get(
            "AddressSet")[0]

        logger.info(
            f' check_for_updates : Organization Object ({self.modified}) vs '
            f'JSON ({parse_time(organization.get("Modified"))}) for org_id {self.id} '
            f'on env {self.environment}')
        if self.modified != parse_time(organization.get(
                "Modified")):  # if not equal we're getting the most recent
            self._get_details(component="organization")
            was_updated = True
            logger.info("Organisation was updated")
        logger.info(
            f' check_for_updates : Contact Object ({self.contact.modified}) vs '
            f'JSON ({parse_time(contact.get("Modified"))}) for org_id {self.id} '
            f'on env {self.environment}')
        if self.contact.modified != parse_time(contact.get("Modified")):
            self._get_details(component="contact")
            logger.info("Contact was updated")
            was_updated = True

        if self.address_set.modified != parse_time(
                address_set.get("Modified")):
            self._get_details(component="address_set")
            logger.info(
                f"""AddressSet was updated - {self.address_set.modified}  vs {parse_time(address_set.get("Modified"))}"""
            )
            was_updated = True

        resp = bss_api.get_subscription_list_by_customer_id(
            self.environment, self.id)
        if len(self.subscriptions) == len(resp.get(
                "List")):  # if subscription count doesnt changes - check each
            for subscription in resp.get("List"):
                if self.subscriptions[subscription.get(
                        "Id")].modified == parse_time(
                            subscription.get("Modified")):
                    logger.info(
                        f'check_for_updates Subscription object not modified '
                        f'({self.subscriptions[subscription.get("Id")].modified}) '
                        f'matches json response modified ({parse_time(subscription.get("Modified"))})'
                    )
                else:
                    logger.info("Subscription was updated")
                    self._get_details(
                        self.id
                    )  # get all details. no reason to just get subscriptions.
                    was_updated = True
                    break
        else:
            logger.info(
                f' check_for_updates : Subscription Object'
                f' ({self.subscriptions[resp.get("Id")].modified}) vs '
                f'JSON ({parse_time(resp.get("Modified"))}) for org_id {self.id} '
                f'on env {self.environment}')
            self._get_details(
                self.id
            )  # get all details. no reason to just get subscriptions.
            was_updated = True
            logger.info("SubscriptionCount was updated")
        return was_updated
Beispiel #9
0
    def _get_details(self,
                     *,
                     component: str = "all",
                     json_body: {} = None) -> None:
        """
        Retrieves an organisation on BSS and returns that organisation object.

        :param component: Specify which part of the object to update optiona: all,organization,subscriptions,subscribers
        :param json_body: (Optional) When provided a JSON payload will be used to update Organization object instead of
        making a request.
        :returns: an organisation object
        :raises PermissionError: User is not authorised to execute this request.
        """
        if json_body:
            resp = json_body
        else:
            resp = bss_api.get_org_by_id(self.environment, self.id)
            resp = resp.get("Customer")
        customer = resp
        organization = resp.get("Organization")
        contact = resp.get("Organization").get("Contact")
        address_set = resp.get("Organization").get("AddressSet")
        customer_account_set = customer.get("CustomerAccountSet", [{}])[0]
        if component == "all" or component == "organization":
            self.id = customer.get("Id")  # when retrieving from json
            self.owner = organization.get("Owner")
            self.name = organization.get("OrgName")
            self.created = parse_time(organization.get("Created"))
            self.modified = parse_time(organization.get("Modified"))
            self.industry = organization.get("Industry")
            self.state = bss_enums.State(customer.get("CustomerState")).value
            self.party_type = bss_enums.PartyType(
                organization.get("PartyType")).value
            self.size = organization.get("CompanySize")  # todo : make use
            self.security_realm = bss_enums.SecurityRealm(
                organization.get("SecurityRealm")).value
            self.last_sync_date = parse_time(
                customer.get("LastSyncDate", "01/01/1970 00:00:00"))
            self.vendor_id: int = customer_account_set.get("VendorId")
            self.is_guest: bool = customer.get("IsGuest")
            self.customer_type: str = organization.get("CustomerType")
            self.is_partner: bool = organization.get("IsPartner")

            # IBM Cloud Specific
            self.is_sync_pending: bool = organization.get("IsSyncPending")
            self.last_sync_date: datetime = "01/01/1970 00:00:00"  # Customer.IsSyncPending  ssm only

        if component == "all" or component == "organization":
            self.contact = Contact(
                email_address=contact.get("EmailAddress"),
                family_name=contact.get("FamilyName", ""),
                given_name=contact.get("GivenName", ""),
                ldap_dn=contact.get("DN"),
                created=parse_time(contact.get("Created")),
                employee_number=contact.get("EmployeeNumber", ""),
                modified=parse_time(contact.get("Modified")),
                name_prefix=contact.get("NamePrefix", ""),
                name_suffix=contact.get("NameSuffix", ""),
                deleted=contact.get("Deleted"),
                security_realm=bss_enums.SecurityRealm(
                    contact.get("SecurityRealm")).value,
                time_zone=contact.get("TimeZone"),
                job_title=contact.get("JobTitle", ""),
                mobile_phone=contact.get("MobilePhone", ""),
                work_phone=contact.get("WorkPhone", ""),
                home_phone=contact.get("HomePhone", ""),
                org_id=customer.get("Id"),
                org_name=organization.get("OrgName"),
            )
        if component == "all" or component == "organization":
            if not address_set:  # Address set may be empty - e.g. from SBS
                self.address_set = AddressSet.not_provided(
                    modified=self.modified)
            else:
                self.address_set = AddressSet(
                    state_code=address_set[0].get("StateCode"),
                    postal_code=address_set[0].get("PostalCode"),
                    city=address_set[0].get("City"),
                    state=address_set[0].get("State"),
                    country=address_set[0].get("Country"),
                    country_code=address_set[0].get("CountryCode"),
                    address_type=address_set[0].get("AddressType"),
                    modified=address_set[0].get("Modified"),
                    address_line_1=address_set[0].get("AddressLine1", ""),
                    address_line_2=address_set[0].get("AddressLine2", ""))
        if component == "all" or component == "subscriptions":
            self._retrieve_subscriptions()
        if component == "all" or component == "subscribers":
            self._retrieve_subscribers()