예제 #1
0
def change():
    connection = connect.AWS()
    connection.session()
    identity_vault_client = connection.identity_vault_client()

    user_profile = request.get_json(silent=True)

    if isinstance(user_profile, str):
        user_profile = json.loads(user_profile)

    logger.info("A json payload was received for user: {}".format(
        user_profile["user_id"]["value"]))

    if config("stream_bypass", namespace="cis", default="false") == "true":
        # Plan on stream integration not working an attempt a write directly to discoverable dynamo.
        # Great for development, seeding the vault, and contingency.
        logger.debug(
            "Stream bypass activated.  Integrating user profile directly to dynamodb for: {}"
            .format(user_profile.get("user_id").get("value")))
        vault = profile.Vault()
        vault.identity_vault_client = identity_vault_client
        result = vault.put_profile(user_profile)
    else:
        publish = operation.Publish()
        result = publish.to_stream(user_profile)
    logger.info("The result of publishing for user: {} is: {}".format(
        user_profile["user_id"]["value"], result))
    return jsonify(result)
예제 #2
0
    def test_publishing_stream_not_found(self):
        from cis_publisher import operation

        o = operation.Publish()

        profile_json = fake_profile.FakeUser().as_dict()

        # send to kinesis
        o._connect()
        o.kinesis_client["arn"] = "foo/foo"
        result = o.to_stream(profile_json)

        assert result.get("status_code") == 500
        assert result.get("sequence_number") is None
예제 #3
0
    def test_super_weird_parititon_key(self):
        from cis_publisher import operation

        o = operation.Publish()
        os.environ["CIS_CONFIG_INI"] = "tests/mozilla-cis-bad.ini"

        # open the full-profile
        profile_json = fake_profile.FakeUser().as_dict()

        # send to kinesis
        o._connect()
        result = o.to_stream(profile_json)

        assert result.get("status_code") == 200
        assert result.get("sequence_number") is not None
예제 #4
0
    def test_publishing_it_should_fail(self):
        from cis_publisher import operation

        o = operation.Publish()

        # open the full-profile
        profile_json = fake_profile.FakeUser().as_dict()

        # modify an attribute
        profile_json["last_name"]["value"] = ["ImBadDataandICannotlie"]

        # send to kinesis
        result = o.to_stream(profile_json)

        assert result.get("status_code") == 400
        assert result.get("sequence_number") is None
예제 #5
0
    def test_publishing_it_should_succeed(self):
        from cis_publisher import operation

        o = operation.Publish()

        # open the full-profile
        profile_json = fake_profile.FakeUser().as_dict()

        # modify an attribute
        profile_json["last_name"]["value"] = "AFakeLastName"

        # send to kinesis
        result = o.to_stream(profile_json)

        assert result.get("status_code") == 200
        assert result.get("sequence_number") is not None
예제 #6
0
    def test_batch_publishing(self):
        from cis_publisher import operation

        o = operation.Publish()
        os.environ["CIS_CONFIG_INI"] = "tests/mozilla-cis-bad.ini"

        profiles = []
        for x in range(0, 10):
            profiles.append(fake_profile.FakeUser().as_dict())

        # send to kinesis
        o._connect()
        results = o.to_stream_batch(profiles)
        for result in results:
            assert result["sequence_number"] is not None
            assert result["status_code"] is not None
예제 #7
0
def changes():
    connection = connect.AWS()
    connection.session()
    identity_vault_client = connection.identity_vault_client()
    profiles = request.get_json(silent=True)

    if config("stream_bypass", namespace="cis", default="false") == "true":
        logger.info("A list of profiles has been received: {}".format(
            len(profiles)))
        vault = profile.Vault(sequence_number=None)
        vault.identity_vault_client = identity_vault_client
        results = vault.put_profiles(profiles)
    else:
        logger.info("A json list of payloads was received totaling: {}".format(
            len(profiles)))
        publish = operation.Publish()
        results = publish.to_stream_batch(profiles)
    logger.info(
        "The result of the attempt to publish the profiles was: {}".format(
            results))
    return jsonify(results)