public async Task <ActionResult> UpdateApiSettings(UpdateApiModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_UpdateApi", model));
            }

            if (!await IsSettingsUnlocked())
            {
                ModelState.AddModelError("Error", Resources.User.securityUnlockTokenExpiredError);
                return(PartialView("_UpdateApi", model));
            }

            var result = await UserSecurityWriter.UpdateApiSettings(User.Identity.GetUserId(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(PartialView("_UpdateApi", model));
            }

            await UserSyncService.SyncUser(User.Identity.GetUserId());

            await ApiKeyStore.UpdateApiAuthKey(model);

            return(PartialView("_UpdateApi", model));
        }
Example #2
0
        /// <summary>
        /// Read keys from ApiKeyStore -> Keys
        /// </summary>
        public static IServiceCollection ConfigureApiKeyStore(this IServiceCollection collection, IConfiguration configuration)
        {
            var storeSection = configuration.GetSection("ApiKeyStore");
            var apiKeys      = storeSection.GetValue <string>("Keys");

            ApiKeyStore.ConfigureStore(apiKeys);
            return(collection);
        }
Example #3
0
 public LambdaApiHandler(ApiKeyStore apiKeys, string baseUrl, DataSet dataSet)
 {
     ApiName       = "Lambda Labs";
     ApiKeys       = apiKeys;
     BaseUrl       = baseUrl;
     DataSet       = dataSet;
     TimingResults = new List <TimingModel>();
 }
Example #4
0
 public AnimetricsApiHandler(ApiKeyStore apiKeys, string baseUrl, string galleryId, DataSet dataSet)
 {
     ApiName       = "Animetrics FaceR";
     ApiKeys       = apiKeys;
     BaseUrl       = baseUrl;
     GalleryId     = galleryId;
     DataSet       = dataSet;
     TimingResults = new List <TimingModel>();
 }
Example #5
0
        static void Main(string[] args)
        {
            // Get desired data set size from the user
            Console.Write("Enter the desired target data set size: ");
            int dataSetSize;

            if (int.TryParse(Console.ReadLine(), out dataSetSize) == false)
            {
                dataSetSize = 8;
                Console.WriteLine("Unable to parse input. Using default data set size of {0}", dataSetSize.ToString());
            }

            // Setup API key stores
            ApiKeyStore amazonAccessKeys  = new ApiKeyStore(new[] { "AKIAJJKYA2TLOIPHNNVA" });
            ApiKeyStore amazonPrivateKeys = new ApiKeyStore(new[] { "BBN6C1W3Lx0bo+mOgmD7xjlfstoA3qKA8ppIr38A" });
            ApiKeyStore azureKeys         = new ApiKeyStore(new[] { "d6ba90bf1de54bf4a050c46eb1f73ab4" });
            ApiKeyStore animetricsKeys    = new ApiKeyStore(new[] { "UINlGk5i5lmsha6RTFLEbd1XL65Ap1Y5kq2jsnuaYrGkAyQcCg" });
            ApiKeyStore lambdaKeys        = new ApiKeyStore(new[] { "UINlGk5i5lmsha6RTFLEbd1XL65Ap1Y5kq2jsnuaYrGkAyQcCg" });

            // Setup DataSet
            DataSet dataSet = new DataSet("capstone-dataset", "AKIAJJKYA2TLOIPHNNVA", "BBN6C1W3Lx0bo+mOgmD7xjlfstoA3qKA8ppIr38A", dataSetSize);

            // Setup SubSets
            List <SubSet> subSets = new List <SubSet>();

            subSets.Add(new SubSet(dataSet.TargetImages.Keys.ToList(), dataSet.SourceImages.Keys.ToList())); // Add all dataset images to a subset

            //Setup the various APIs
            List <BaseApiHandler> apiList = new List <BaseApiHandler>();

            apiList.Add(new AmazonApiHandler(amazonAccessKeys, amazonPrivateKeys, dataSet, "testcollection"));
            apiList.Add(new AzureApiHandler(azureKeys, "https://australiaeast.api.cognitive.microsoft.com/face/v1.0", "", "test-person-group", dataSet));
            //apiList.Add(new AnimetricsApiHandler(animetricsKeys, "https://animetrics.p.mashape.com/", "test_gallery", dataSet));
            //apiList.Add(new LambdaApiHandler(lambdaKeys, "https://lambda-face-recognition.p.mashape.com/", dataSet));

            subSets.ForEach((subset) =>
            {
                Console.WriteLine("Running APIs for subset %1", subset.SubSetId);
                apiList.ForEach((api) =>
                {
                    Console.WriteLine("Testing {0} API.", api.ApiName);
                    Task apiRun = api.RunApi();
                    apiRun.Wait();
                    Console.WriteLine("API {0} Complete. Exporting results...", api.ApiName);
                    api.ExportResults("C:\\Api Output\\" + DateTime.Now.Date.ToShortDateString() + "-" + dataSetSize);
                    Console.WriteLine("Export Complete.", api.ApiName);
                });
            });

            Console.WriteLine("Press Any Key To Continue...");
            Console.ReadKey();
        }
Example #6
0
 public AzureApiHandler(ApiKeyStore apiKeys, string region, string config, string personGroupId, DataSet dataSet)
 {
     ApiName         = "Azure";
     ApiKeys         = apiKeys;
     Region          = region;
     Client          = new FaceServiceClient(ApiKeys.GetCurrentKey(), Region);
     DataSet         = dataSet;
     PersonGroupId   = personGroupId;
     TargetFaceList  = new List <Face>();
     SourceFaceList  = new List <Face>();
     SourceMatchList = new List <IdentifyResult>();
     TimingResults   = new List <TimingModel>();
 }
Example #7
0
 public AmazonApiHandler(ApiKeyStore accessKeys, ApiKeyStore secretKeys, DataSet dataSet, string collectionName)
 {
     ApiName        = "Amazon Rekognition";
     AccessKeys     = accessKeys;
     SecretKeys     = secretKeys;
     CollectionName = collectionName;
     Credentials    = new BasicAWSCredentials(AccessKeys.GetCurrentKey(), SecretKeys.GetCurrentKey());
     Client         = new AmazonRekognitionClient(Credentials, new AmazonRekognitionConfig {
         RegionEndpoint = RegionEndpoint.USWest2
     });
     DataSet       = dataSet;
     IndexedFaces  = new List <IndexFacesResponse>();
     MatchResults  = new List <SearchFacesByImageResponse>();
     TimingResults = new List <TimingModel>();
 }
Example #8
0
        public async Task <ActionResult> UpdateUserApiSettings(UserApiModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_ApiPartial", model));
            }

            var user = await UserManager.FindByIdAsync(User.Id());

            var oldKey = user.ApiKey;

            user.ApiKey       = model.Key;
            user.ApiSecret    = model.Secret;
            user.IsApiEnabled = model.IsEnabled;

            await UserManager.UpdateAsync(user);

            ApiKeyStore.InvalidateApiKey(oldKey);
            ApiKeyStore.GetApiAuthKey(user.ApiKey);

            return(PartialView("_ApiPartial", model));
        }