public override bool Execute()
        {
            var debug      = string.Equals("true", DebugTask?.Trim(), StringComparison.OrdinalIgnoreCase);
            var promptAuth = string.Equals("true", AlwaysPromptInteractiveAuth?.Trim(), StringComparison.OrdinalIgnoreCase);

            Config.Log.Information = x => Log.LogWarning(x);
            Config.Log.Error       = (ex, m) => Log.LogError("Error while processing secrets from keyvault. " + Environment.NewLine + ex);

            try
            {
                if (debug && !Debugger.IsAttached)
                {
                    Debugger.Launch();
                    Debugger.Break();
                }

                if (promptAuth)
                {
                    Log.LogWarning("KeyVaultBuildTask: Set to always prompting for auth information.");
                }

                var service = SecretServiceBuilder.Create()
                              .AlwaysPromptInteractiveAuth(promptAuth)
                              .WithDirectory(DirectoryId)
                              .WithServicePrincipal(ClientId, Secret);

                if (!string.IsNullOrEmpty(VaultAliases))
                {
                    foreach (var alias in VaultAliases?.Trim().Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        var pair = alias.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                        service.WithVaultAlias(pair.First(), pair.Last());
                        Log.LogWarning("Overriding vault '{0}' with '{1}'", pair.First(), pair.Last());
                    }
                }

                var transformKey = new TransformKeys(service.Build());
                var files        = ConfigFiles.Select(file => file.GetMetadata("Fullpath")).ToArray();

                Parallel.ForEach(files, file =>
                {
                    transformKey.SaveAsFile(file);
                });
            }
            catch (Exception ex)
            {
                TokenCache.DefaultShared.Clear();
                Config.Log.Error(ex, "Error occured processing secrets. ");
                if (debug)
                {
                    Debugger.Break();
                }
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public string CreateOrUpdateBimInfo(EventHandlerEnvironment env)
        {
            var ts = GetTrace(MethodBase.GetCurrentMethod().Name);

            var vault = env.Vault;

            try
            {
                var model = ModelUtility.FromZippedContent(env.Input, JsonConvert.DeserializeObject <MfProjectModel>);//JsonConvert.DeserializeObject<MfProjectModel>(info);
                ts.TraceInformation("输入信息:" + model.Model.Name);
                ts.TraceInformation("楼层个数: " + model.Model.Levels.Count);
                ts.TraceInformation("材料个数: " + model.Model.Materials.Count);
                ts.TraceInformation("视图个数: " + model.Model.Views.Count);
                ts.TraceInformation("类别个数: " + model.Model.Categories.Count);
                ts.TraceInformation("类型个数: " + model.Model.Types.Count);
                ts.TraceInformation(" 族个数: " + model.Model.Families.Count);
                ts.TraceInformation("构件个数: " + model.Model.Elements.Count);
                try
                {
                    var aliases = VaultAliases.GetAliases(vault);
                    var dict    = model.Run(aliases);
                    return(ModelUtility.GetZippedContent(dict, ToJson));
                }
                catch (Exception ex)
                {
                    ts.TraceEvent(TraceEventType.Error, 0, "运行失败:" + ex.Message + "r\n" + ex.StackTrace);
                    return(ModelUtility.GetZippedContent("运行失败:" + ex.Message, s => s.ToString()));
                }
            }
            catch (Exception ex)
            {
                ts.TraceEvent(TraceEventType.Error, 0, "获取信息失败:" + ex.Message + "r\n" + ex.StackTrace);
                return(ModelUtility.GetZippedContent("获取信息失败:" + ex.Message, s => s.ToString()));
            }
            finally
            {
                ts.Close();
            }
        }