private async Task <VisionDescribeRequest> MergeProperties(VisionDescribeRequest operation, IVisionBinding config, VisionDescribeAttribute attr) { var visionOperation = new VisionDescribeRequest { Url = attr.VisionUrl ?? operation.Url, Key = attr.VisionKey ?? operation.Key, SecureKey = attr.SecureKey ?? attr.SecureKey, AutoResize = attr.AutoResize, MaxCandidates = operation.MaxCandidates, ImageUrl = string.IsNullOrEmpty(operation.ImageUrl) ? attr.ImageUrl : operation.ImageUrl, ImageBytes = operation.ImageBytes, }; if (string.IsNullOrEmpty(visionOperation.Key) && string.IsNullOrEmpty(visionOperation.SecureKey)) { _log.LogWarning(VisionExceptionMessages.KeyMissing); throw new ArgumentException(VisionExceptionMessages.KeyMissing); } if (!string.IsNullOrEmpty(visionOperation.SecureKey)) { HttpClient httpClient = this._config.Client.GetHttpClientInstance(); visionOperation.Key = await KeyVaultServices.GetValue(visionOperation.SecureKey, httpClient); } return(visionOperation); }
private async Task <VisionDomainRequest> MergeProperties(VisionDomainRequest operation, IVisionBinding config, VisionDomainAttribute attr) { //Attributes do not allow for enum types so we have to validate //the string passed into the attribute to ensure it matches //a valid VisionDomainOption. VisionDomainOptions attrDomain = VisionDomainOptions.None; if (!string.IsNullOrEmpty(attr.Domain)) { var valid = Enum.TryParse <VisionDomainOptions>(attr.Domain, out attrDomain); if (!valid) { var message = string.Format(VisionExceptionMessages.InvalidDomainName, attr.Domain); _log.LogWarning(message); throw new ArgumentException(message); } } else { if (operation.Domain == VisionDomainOptions.None) { var message = string.Format(VisionExceptionMessages.InvalidDomainName, "None"); _log.LogWarning(message); throw new ArgumentException(message); } } var visionOperation = new VisionDomainRequest { Url = attr.VisionUrl ?? operation.Url, Key = attr.VisionKey ?? operation.Key, SecureKey = attr.SecureKey ?? attr.SecureKey, AutoResize = attr.AutoResize, Domain = attrDomain == VisionDomainOptions.None ? operation.Domain : attrDomain, ImageUrl = string.IsNullOrEmpty(operation.ImageUrl) ? attr.ImageUrl : operation.ImageUrl, ImageBytes = operation.ImageBytes, }; if (string.IsNullOrEmpty(visionOperation.Key) && string.IsNullOrEmpty(visionOperation.SecureKey)) { _log.LogWarning(VisionExceptionMessages.KeyMissing); throw new ArgumentException(VisionExceptionMessages.KeyMissing); } if (!string.IsNullOrEmpty(visionOperation.SecureKey)) { HttpClient httpClient = this._config.Client.GetHttpClientInstance(); visionOperation.Key = await KeyVaultServices.GetValue(visionOperation.SecureKey, httpClient); } return(visionOperation); }