public static TapSecurityJson GetSecurity(this BaseTask baseTask) { baseTask.LogDebug($"Loading {Consts.TapSecurityFile} file"); try { var tapSecurityPath = baseTask.FindTopFileInProjectDir(Consts.TapSecurityFile); TapSecurityJson tapSecurity = null; if (String.IsNullOrEmpty(tapSecurityPath)) { baseTask.Log.LogError($"{Consts.TapSecurityFile} file not found"); return(null); } else { var json = File.ReadAllText(tapSecurityPath); tapSecurity = JsonConvert.DeserializeObject <TapSecurityJson>(json); if ((String.IsNullOrEmpty(tapSecurity.Username) || String.IsNullOrEmpty(tapSecurity.Password)) && String.IsNullOrEmpty(tapSecurity.ServiceUserAccessKey)) { baseTask.Log.LogError($"{Consts.TapSecurityFile} username, password, or service user access key is null, please complete username and password, or service user access key at {tapSecurityPath} and restart build process"); return(null); } else { baseTask.LogDebug($"{Consts.TapSecurityFile} file read from {tapSecurityPath}, Username {tapSecurity.Username}"); return(tapSecurity); } } } catch (Exception ex) { baseTask.Log.LogErrorFromException(ex); } return(null); }
/// <summary> /// Gets the tap config now stored in same json file as BuildConfigurations /// </summary> /// <returns>The tap config.</returns> /// <param name="baseTask">Base task.</param> public static ITaskItem GetTapSettings(this BaseTask baseTask) { try { var tapSettingsPath = baseTask.FindTopFileInProjectDir(Consts.TapSettingFile); if (String.IsNullOrEmpty(tapSettingsPath)) { var tapSettingTaskItem = new TaskItem(MetadataType.TapConfig); tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, Consts.TapEndpoint); tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, Consts.MediaEndpoint); tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, LogLevelConsts.Information); //baseTask.Log.LogMessage($"Tap log level set to {tapConfigTaskItem.GetMetadata(MetadataType.TapLogLevel)}"); return(tapSettingTaskItem); } else { var json = File.ReadAllText(tapSettingsPath); var tapSetting = JsonConvert.DeserializeObject <TapSettingJson>(json); var tapSettingTaskItem = new TaskItem(MetadataType.TapConfig); if (!String.IsNullOrEmpty(tapSetting.LogLevel)) { tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, tapSetting.LogLevel); } else { tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, LogLevelConsts.Information); } if (!String.IsNullOrEmpty(tapSetting.TapEndpoint)) { tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, tapSetting.TapEndpoint); } else { tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, Consts.TapEndpoint); } if (!String.IsNullOrEmpty(tapSetting.MediaEndpoint)) { tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, tapSetting.MediaEndpoint); } else { tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, Consts.MediaEndpoint); } baseTask.LogInformation($"Tap log level set to {tapSettingTaskItem.GetMetadata(MetadataType.TapLogLevel)}"); return(tapSettingTaskItem); } } catch { var tapSettingTaskItem = new TaskItem(MetadataType.TapConfig); tapSettingTaskItem.SetMetadata(MetadataType.TapEndpoint, Consts.TapClientEndpoint); tapSettingTaskItem.SetMetadata(MetadataType.MediaEndpoint, Consts.MediaEndpoint); tapSettingTaskItem.SetMetadata(MetadataType.TapLogLevel, LogLevelConsts.Information); baseTask.Log.LogWarning($"Error trying to read {Consts.TapSettingFile}, returning defaults"); baseTask.LogInformation($"Tap log level set to {tapSettingTaskItem.GetMetadata(MetadataType.TapLogLevel)}"); return(tapSettingTaskItem); } }