public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "TrackEventFeatureFlag")] HttpRequestMessage req, ExecutionContext context, TraceWriter log) { try { telemetry.Context.Operation.Id = context.InvocationId.ToString(); telemetry.Context.Operation.Name = "TrackEventFeatureFlag"; var startTime = DateTime.Now; var timer = System.Diagnostics.Stopwatch.StartNew(); int apiversion = Helpers.GetHeaderValue(req, "api-version"); var data = req.Content.ReadAsStringAsync().Result; //Gettings parameters in Body request var formValues = data.Split('&') .Select(value => value.Split('=')) .ToDictionary(pair => Uri.UnescapeDataString(pair[0]).Replace("+", " "), pair => Uri.UnescapeDataString(pair[1]).Replace("+", " ")); #region display log for debug log.Info(data); //for debug #endregion var account = formValues["account"]; var customEvent = formValues["customevent"]; var appSettingExtCert = (apiversion < 2) ? formValues["appsettingextcert"] : string.Empty; //"RollUpBoard_ExtensionCertificate" var ExtCertKey = (apiversion >= 2) ? formValues["extcertkey"] : string.Empty; bool useKeyVault = (apiversion >= 2); //get the token passed in the header request string tokenuserId = Helpers.TokenIsValid(req, useKeyVault, appSettingExtCert, ExtCertKey, log); if (tokenuserId != null) { var userkey = LaunchDarklyServices.FormatUserKey(tokenuserId, account); LaunchDarklyServices.TrackFeatureFlag(_ldclient, userkey, customEvent); return(req.CreateResponse(HttpStatusCode.OK, "The custom event had be successfuly tracked")); } else { telemetry.TrackTrace("The token is not valid"); return(req.CreateResponse(HttpStatusCode.Unauthorized, "The token is not valid")); } } catch (Exception ex) { telemetry.TrackException(ex); return(req.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "GetUserFeatureFlag")] HttpRequestMessage req, ExecutionContext context, TraceWriter log) { try { telemetry.Context.Operation.Id = context.InvocationId.ToString(); telemetry.Context.Operation.Name = "GetUserFeatureFlag"; var startTime = DateTime.Now; var timer = System.Diagnostics.Stopwatch.StartNew(); int apiversion = Helpers.GetHeaderValue(req, "api-version"); var data = await req.Content.ReadAsStringAsync(); //Gettings parameters in Body request var formValues = data.Split('&') .Select(value => value.Split('=')) .ToDictionary(pair => Uri.UnescapeDataString(pair[0]).Replace("+", " "), pair => Uri.UnescapeDataString(pair[1]).Replace("+", " ")); #region display log for debug log.Info(data); //for debug #endregion var account = formValues["account"]; var appSettingExtCert = formValues["appsettingextcert"]; //"RollUpBoard_ExtensionCertificate" string launchDarklySDKkey = (apiversion == 1) ? formValues["ldkey"] : string.Empty; string LDproject = (apiversion >= 2) ? formValues["ldproject"] : "roll-up-board"; string LDenv = (apiversion >= 2) ? formValues["ldenv"] : "production"; //get the token passed in the header request string issuedToken = Helpers.GetUserTokenInRequest(req); string extcert = Helpers.GetExtCertificatEnvName(appSettingExtCert, apiversion); var tokenuserId = CheckVSTSToken.checkTokenValidity(issuedToken, extcert); //Check the token, and compare with the VSTS UserId if (tokenuserId != null) { var userkey = LaunchDarklyServices.FormatUserKey(tokenuserId, account); Dictionary <string, bool> userFlags = new Dictionary <string, bool>(); // LD SDK performance review if (apiversion == 2) { LaunchDarklyServices.GetUserFeatureFlags(_ldclient, userkey, ref userFlags); } else { userFlags = await LaunchDarklyServices.GetUserFeatureFlagsv1(LDproject, LDenv, userkey); } if (userFlags != null) { return(req.CreateResponse(HttpStatusCode.OK, userFlags)); //return the users flags } else { telemetry.TrackTrace("flags is null"); return(req.CreateResponse(HttpStatusCode.InternalServerError, "User flags is null")); } } else { telemetry.TrackTrace("The token is not valid"); return(req.CreateResponse(HttpStatusCode.Unauthorized, "The token is not valid")); } } catch (Exception ex) { telemetry.TrackException(ex); return(req.CreateResponse(HttpStatusCode.InternalServerError, ex)); } }