/// <summary> /// Initializes the resource provider application. /// </summary> /// <param name="httpConfiguration">The default HttpConfiguration object for this application.</param> /// <param name="serviceConfiguration">The service configuration object containing resource provider settings.</param> /// <param name="eventSource">The event source used for logging resource provider operations.</param> public static void Initialize( HttpConfiguration httpConfiguration, ResourceProviderServiceConfiguration serviceConfiguration, ICommonEventSource eventSource) { ArgumentValidator.ValidateNotNull("httpConfiguration", httpConfiguration); ArgumentValidator.ValidateNotNull("serviceConfiguration", serviceConfiguration); ArgumentValidator.ValidateNotNull("eventSource", eventSource); httpConfiguration.Filters.Add(new ResourceProviderExceptionFilterAttribute(eventSource)); // Ensure use of the JsonMediaTypeFormatter provided by the RP SDK, which guarantees the correct // JSON serialization settings for ARM interoperability. httpConfiguration.Formatters.Clear(); httpConfiguration.Formatters.Add(JsonExtensions.JsonMediaTypeFormatter); var manifest = ManifestFactory.CreateResourceProviderManifest(serviceConfiguration); ResourceProviderManager.RegisterCredentialAuthorization( httpConfiguration: httpConfiguration, eventSource: eventSource, manifestEndpointCredential: serviceConfiguration.Manifest.ManifestEndpointCredential, providerManifests: new ResourceProviderManifest[] { manifest }); ResourceProviderManager.RegisterEventsController( httpConfiguration: httpConfiguration, providerManifest: manifest, eventSource: eventSource, eventsConnectionString: serviceConfiguration.EventsConnectionString.ConnectionString, eventSchemaName: serviceConfiguration.EventsSchemaName); // TODO: Enable Azure Gallery item controller, when publishing a gallery item. //ResourceProviderManager.RegisterGalleryController( // httpConfiguration: httpConfiguration, // providerManifest: manifest, // galleryItemsResources: null); ResourceProviderManager.RegisterProviderManifestController( httpConfiguration: httpConfiguration, manifestEndpointUri: serviceConfiguration.BaseEndpoint.AbsoluteUri, eventSource: eventSource, providerManifest: manifest); // Create the resource provider storage. var resourceProviderStorage = new DefaultResourceProviderStorage( connectionStrings: new string[] { serviceConfiguration.StorageConnectionString }, eventSource: eventSource); // Create and initialize the handler configurations for each registered resource type. var resourceHandlers = new ResourceTypeHandlerConfiguration[] { ResourceTypeHandlerConfiguration.CreateResourceGroupWideResourceTypeHandlerConfiguration( resourceTypeName: new ResourceTypeName(ManifestFactory.Namespace, ManifestFactory.RootResourceTypeName), apiVersions: new string[] { serviceConfiguration.ApiVersion }, resourceProviderStorage: resourceProviderStorage, eventSource: eventSource, managedResourceTypeRequestHandler: new RootResourceTypeRequestHandler(resourceProviderStorage)), ResourceTypeHandlerConfiguration.CreateResourceGroupWideResourceTypeHandlerConfiguration( resourceTypeName: new ResourceTypeName(ManifestFactory.Namespace, ManifestFactory.RootResourceTypeName, ManifestFactory.NestedResourceTypeName), apiVersions: new string[] { serviceConfiguration.ApiVersion }, resourceProviderStorage: resourceProviderStorage, eventSource: eventSource, managedResourceTypeRequestHandler: new NestedResourceTypeRequestHandler(resourceProviderStorage)) }; ResourceProviderManager.RegisterResourceProvider( httpConfiguration: httpConfiguration, eventSource: eventSource, providerStorage: resourceProviderStorage, providerNamespace: manifest.Namespace, resourceTypeHandlerConfigurationCollection: resourceHandlers); ResourceProviderManager.RegisterUsageController( httpConfiguration: httpConfiguration, providerManifest: manifest, handler: null, eventSource: eventSource, usageConnectionString: serviceConfiguration.UsageConnectionString.ConnectionString, usageSchemaName: serviceConfiguration.UsageSchemaName); }
/// <summary> /// Populate the resource provider manifest for the resource provider. /// </summary> /// <param name="serviceConfiguration">The service configuration object containing resource provider settings.</param> /// <returns>The resource provider manifest used to specify service configuration.</returns> public static ResourceProviderManifest CreateResourceProviderManifest( ResourceProviderServiceConfiguration serviceConfiguration) { ArgumentValidator.ValidateNotNull("serviceConfiguration", serviceConfiguration); // TODO: In order to report Usage data correctly, populate the metered resource Ids with // unique identifiers for each meter which will be reported by Usage. string[] meteredResourceIds = null; var manifest = new ResourceProviderManifest { ProviderVersion = serviceConfiguration.ApiVersion, Namespace = ManifestFactory.Namespace, BaseAdminApiEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpoint.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, AuthenticationUsername = serviceConfiguration.Manifest.AdminEndpointUserName, AuthenticationPassword = serviceConfiguration.Manifest.AdminEndpointPassword, Enabled = true }, AdminResourceTypes = new ResourceType[] { new ResourceType { Name = "AdminResource" } }, BaseTenantApiEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpoint.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, AuthenticationUsername = serviceConfiguration.Manifest.TenantEndpointUserName, AuthenticationPassword = serviceConfiguration.Manifest.TenantEndpointPassword, Enabled = true }, TenantResourceTypes = new ResourceType[] { new ResourceType { Name = "rootResources", MeteredResourceIds = meteredResourceIds }, new ResourceType { Name = "rootResources/nestedResources", MeteredResourceIds = meteredResourceIds } }, QuotaApiEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpoint.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, AuthenticationUsername = serviceConfiguration.Manifest.QuotaEndpointUserName, AuthenticationPassword = serviceConfiguration.Manifest.QuotaEndpointPassword, Enabled = true }, EventApiEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpoint.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, AuthenticationUsername = serviceConfiguration.Manifest.EventEndpointUserName, AuthenticationPassword = serviceConfiguration.Manifest.EventEndpointPassword, Enabled = true }, GalleryApiEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpoint.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, AuthenticationUsername = serviceConfiguration.Manifest.GalleryEndpointUserName, AuthenticationPassword = serviceConfiguration.Manifest.GalleryEndpointPassword, Enabled = true }, UsageApiEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpoint.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, AuthenticationUsername = serviceConfiguration.Manifest.UsageEndpointUserName, AuthenticationPassword = serviceConfiguration.Manifest.UsageEndpointPassword, Enabled = true }, AdminExtensionName = "JWTestExtensionResourceProviderAdminExtension", AdminExtensionEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpointAdminExtension.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, Enabled = true }, TenantExtensionName = "JWTestExtensionResourceProviderExtension", TenantExtensionEndpoint = new ResourceProviderEndpoint { ApiVersion = serviceConfiguration.ApiVersion, EndpointUri = serviceConfiguration.BaseEndpointTenantExtension.AbsoluteUri, Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout, Enabled = true } }; return(manifest); }