Exemplo n.º 1
0
        public SdkEvent(EventOptions eventOptions, SecureNativeOptions options)
        {
            if (eventOptions.GetUserId() == null || eventOptions.GetUserId().Length <= 0 || eventOptions.GetUserId().Equals(""))
            {
                throw new SecureNativeInvalidOptionsException("Invalid event structure; User Id is missing");
            }

            if (eventOptions.GetEventType() == null || eventOptions.GetEventType().Length <= 0 || eventOptions.GetEventType().Equals(""))
            {
                throw new SecureNativeInvalidOptionsException("Invalid event structure; Event Type is missing");
            }

            var context     = eventOptions.GetContext() ?? SecureNativeContextBuilder.DefaultContextBuilder().Build();
            var clientToken = EncryptionUtils.Decrypt(context.GetClientToken(), options.GetApiKey());

            Rid        = Guid.NewGuid().ToString();
            EventType  = eventOptions.GetEventType();
            UserId     = eventOptions.GetUserId();
            UserTraits = eventOptions.GetUserTraits();
            Request    = new RequestContextBuilder()
                         .WithCid(clientToken.GetCid())
                         .WithVid(clientToken.GetVid())
                         .WithFp(clientToken.GetFp())
                         .WithIp(context.GetIp())
                         .WithRemoteIp(context.GetRemoteIp())
                         .WithMethod(context.GetMethod())
                         .WithUrl(context.GetUrl())
                         .WitHeaders(context.GetHeaders())
                         .Build();

            Timestamp  = DateUtils.ToTimestamp(eventOptions.GetTimestamp() ?? new DateTime());
            Properties = eventOptions.GetProperties();
        }
Exemplo n.º 2
0
 public SecureNativeHttpClient(SecureNativeOptions options, HttpMessageHandler handler = null)
 {
     _options = options;
     _client  = handler != null ? new HttpClient(handler) : new HttpClient();
     _client.DefaultRequestHeaders.Add(UserAgentHeader, UserAgentHeaderValue);
     _client.DefaultRequestHeaders.Add(VersionHeader, Utils.VersionUtils.GetVersion());
     _client.DefaultRequestHeaders.Add(AuthorizationHeader, options.GetApiKey());
 }
        public void ParseConfigFileCorrectlyTest()
        {
            SecureNativeOptions options = ConfigurationManager.LoadConfig();

            Assert.IsNotNull(options);
            Assert.AreEqual("SOME_API_KEY", options.GetApiKey());
            Assert.AreEqual("SOME_API_URL", options.GetApiUrl());
            Assert.AreEqual(true, options.IsAutoSend());
            Assert.AreEqual(false, options.IsDisabled());
            Assert.AreEqual(FailOverStrategy.FAIL_CLOSED, options.GetFailOverStrategy());
            Assert.AreEqual(1000, options.GetInterval());
            Assert.AreEqual("fatal", options.GetLogLevel());
            Assert.AreEqual(100, options.GetMaxEvents());
            Assert.AreEqual(1500, options.GetTimeout());
            Assert.AreEqual(1, options.GetProxyHeaders().Length);
        }
Exemplo n.º 4
0
        public bool VerifyRequestPayload(HttpWebRequest request)
        {
            if (request.Headers[SignatureUtils.SignatureHeader] == null)
            {
                return(false);
            }
            var requestSignature = request.Headers.GetValues(SignatureUtils.SignatureHeader)?.ToString();

            var res  = (HttpWebResponse)request.GetResponse();
            var sr   = new StreamReader(res.GetResponseStream() !, Encoding.Default);
            var body = sr.ReadToEnd();

            sr.Close();
            res.Close();

            return(SignatureUtils.IsValidSignature(requestSignature, body, _options.GetApiKey()));
        }
Exemplo n.º 5
0
        public Client(SecureNativeOptions options)
        {
            if (string.IsNullOrEmpty(options.GetApiKey()))
            {
                throw new SecureNativeSdkException("You must pass your SecureNative api key");
            }

            var eventManager = new EventManager(options);

            if (options.IsAutoSend())
            {
                eventManager.StartEventsPersist();
            }

            _apiManager = new ApiManager(eventManager, options);

            var logLevel = SecureNativeLogger.GetLogLevel(options.GetLogLevel());

            SecureNativeLogger.InitLogger(logLevel);
        }