Example #1
0
 public ArchiveFunctionApp(string name, ArchiveFunctionAppArgs args, CustomResourceOptions options = null) : base(name, Map(name, args), options)
 {
 }
Example #2
0
        private static FunctionAppArgs Map(string name, ArchiveFunctionAppArgs args)
        {
            if (args.AppServicePlanId == null)
            {
                var plan = new Plan(name, new PlanArgs
                {
                    ResourceGroupName = args.ResourceGroupName,
                    Kind = "FunctionApp",
                    Sku  = new PlanSkuArgs
                    {
                        Tier = "Dynamic",
                        Size = "Y1"
                    }
                });
                args.AppServicePlanId = plan.Id;
            }

            if (args.StorageAccount == null)
            {
                args.StorageAccount = new Account(MakeSafeStorageAccountName(name), new AccountArgs
                {
                    ResourceGroupName      = args.ResourceGroupName,
                    AccountReplicationType = "LRS",
                    AccountTier            = "Standard",
                    AccountKind            = "StorageV2"
                });
            }

            if (args.StorageContainer == null)
            {
                args.StorageContainer = new Container(MakeSafeStorageContainerName(name), new ContainerArgs
                {
                    StorageAccountName  = args.StorageAccount.Apply(a => a.Name),
                    ContainerAccessType = "private"
                });
            }

            var mapped = new FunctionAppArgs
            {
                StorageAccountName      = args.StorageAccount.Apply(a => a.Name),
                StorageAccountAccessKey = args.StorageAccount.Apply(a => a.PrimaryAccessKey),
                SiteConfig        = args.SiteConfig,
                ResourceGroupName = args.ResourceGroupName,
                OsType            = args.OsType,
                Name                  = args.Name,
                Location              = args.Location,
                Tags                  = args.Tags,
                Identity              = args.Identity,
                Enabled               = args.Enabled,
                EnableBuiltinLogging  = args.EnableBuiltinLogging,
                DailyMemoryTimeQuota  = args.DailyMemoryTimeQuota,
                ConnectionStrings     = args.ConnectionStrings,
                ClientAffinityEnabled = args.ClientAffinityEnabled,
                AuthSettings          = args.AuthSettings,
                AppSettings           = args.AppSettings,
                AppServicePlanId      = args.AppServicePlanId,
                HttpsOnly             = args.HttpsOnly,
                Version               = args.Version
            };

            var blob = new Blob(name, new BlobArgs
            {
                StorageAccountName   = args.StorageAccount.Apply(a => a.Name),
                StorageContainerName = args.StorageContainer.Apply(a => a.Name),
                Source = args.Archive.Apply(a => a),
                Type   = "Block"
            });

            if (mapped.AppSettings == null)
            {
                mapped.AppSettings = new InputMap <string>();
            }

            mapped.AppSettings.Add("WEBSITE_RUN_FROM_PACKAGE", GetSignedBlobUrl(blob, args.StorageAccount));
            return(mapped);
        }
        private static ArchiveFunctionAppArgs Map(CallbackFunctionAppArgs args)
        {
            var mapped = new ArchiveFunctionAppArgs
            {
                StorageAccount    = args.StorageAccount,
                StorageContainer  = args.StorageContainer,
                SiteConfig        = args.SiteConfig,
                ResourceGroupName = args.ResourceGroupName,
                OsType            = args.OsType,
                Name                  = args.Name,
                Location              = args.Location,
                Tags                  = args.Tags,
                Identity              = args.Identity,
                Enabled               = args.Enabled,
                EnableBuiltinLogging  = args.EnableBuiltinLogging,
                DailyMemoryTimeQuota  = args.DailyMemoryTimeQuota,
                ConnectionStrings     = args.ConnectionStrings,
                ClientAffinityEnabled = args.ClientAffinityEnabled,
                AuthSettings          = args.AuthSettings,
                AppSettings           = args.AppSettings,
                AppServicePlanId      = args.AppServicePlanId,
                HttpsOnly             = args.HttpsOnly,
                Version               = args.Version ?? "~3"
            };


            var archive = new Dictionary <string, AssetOrArchive>
            {
                { "host.json", new StringAsset(
                      args.HostJson != null
                    ? JsonConvert.SerializeObject(args.HostJson)
                    : "{\"version\": \"2.0\", \"logging\": { \"applicationInsights\": { \"samplingExcludedTypes\": \"Request\", \"samplingSettings\": { \"isEnabled\": true } } } }") },
            };


            foreach (var function in args.Functions)
            {
                archive.Add(function.Name + "/function.json", new StringAsset(BuildFunctionJson(function)));

                // TODO: find better way to identify all required assemblies
                foreach (var assembly in Directory.GetFiles(new FileInfo(function.Callback.DeclaringType.Assembly.Location).DirectoryName, "*.dll"))
                {
                    var key = "bin/" + new FileInfo(assembly).Name;
                    if (!archive.ContainsKey(key))
                    {
                        archive.Add(key, new FileAsset(assembly));
                    }
                }
            }

            archive.Add("bin/extensions.json", new StringAsset(BuildExtensionsJson(args)));

            mapped.Archive = new AssetArchive(archive);

            if (mapped.AppSettings == null)
            {
                mapped.AppSettings = new InputMap <string>();
            }

            mapped.AppSettings.Add("FUNCTIONS_EXTENSION_VERSION", "~3");
            mapped.AppSettings.Add("FUNCTIONS_WORKER_RUNTIME", "dotnet");

            return(mapped);
        }