public NautilusService(IOctopusRepository octopusRepository, TextWriter log = null) { if (octopusRepository == null) throw new ArgumentNullException(nameof(octopusRepository)); Octopus = new OctopusProxy(octopusRepository); Log = log ?? TextWriter.Null; }
public void Execute(string[] commandLineArguments) { var remainingArguments = optionGroups.Parse(commandLineArguments); if (remainingArguments.Count > 0) throw new CommandException("Unrecognized command arguments: " + string.Join(", ", remainingArguments)); if (string.IsNullOrWhiteSpace(serverBaseUrl)) throw new CommandException("Please specify the Octopus Server URL using --server=http://your-server/"); if (string.IsNullOrWhiteSpace(apiKey)) throw new CommandException("Please specify your API key using --apiKey=ABCDEF123456789. Learn more at: https://github.com/OctopusDeploy/Octopus-Tools"); var credentials = ParseCredentials(username, password); var endpoint = new OctopusServerEndpoint(serverBaseUrl, apiKey, credentials); repository = repositoryFactory.CreateRepository(endpoint); if (enableDebugging) { repository.Client.SendingOctopusRequest += request => log.Debug(request.Method + " " + request.Uri); } ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => { if (errors == SslPolicyErrors.None) { return true; } var certificate2 = (X509Certificate2) certificate; var warning = "The following certificate errors were encountered when establishing the HTTPS connection to the server: " + errors + Environment.NewLine + "Certificate subject name: " + certificate2.SubjectName.Name + Environment.NewLine + "Certificate thumbprint: " + ((X509Certificate2) certificate).Thumbprint; if (ignoreSslErrors) { log.Warn(warning); log.Warn("Because --ignoreSslErrors was set, this will be ignored."); return true; } log.Error(warning); return false; }; log.Debug("Handshaking with Octopus server: " + serverBaseUrl); var root = repository.Client.RootDocument; log.Debug("Handshake successful. Octopus version: " + root.Version + "; API version: " + root.ApiVersion); var user = repository.Users.GetCurrent(); if (user != null) { log.DebugFormat("Authenticated as: {0} <{1}> {2}", user.DisplayName, user.EmailAddress, user.IsService ? "(a service account)" : ""); } Execute(); }
public OctopusDeploy(string machineName, ConfigSettings config, IOctopusRepository repository, IProcessRunner processRunner, IRegistryEditor registryEditor) { _machineName = machineName; _config = config; _processRunner = processRunner; _registryEditor = registryEditor; _repository = repository; _tentacleInstallPath = _config.TentacleInstallPath; _tentaclePath = Path.Combine(_tentacleInstallPath, "Tentacle", "Tentacle.exe"); }
private VariableSetResource GetVariables(IOctopusRepository octopus) { // Find the project that owns the variables we want to edit var project = octopus.Projects.FindByName(_args.Project); var variableSetLink = project != null ? project.Link("Variables") : octopus.LibraryVariableSets.FindOne(f => f.Name == _args.Project).Link("Variables"); return octopus.VariableSets.Get(variableSetLink); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); // Find the project that owns the variables we want to edit _project = _octopus.Projects.FindByName(Project); if (_project == null) throw new Exception(string.Format("Project '{0}' was not found.", Project)); WriteDebug("Found project" + _project.Id); }
public IImporter Find(string name, IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log) { name = name.Trim().ToLowerInvariant(); var found = (from t in typeof (ImporterLocator).Assembly.GetTypes() where typeof (IImporter).IsAssignableFrom(t) let attribute = (IImporterMetadata) t.GetCustomAttributes(typeof (ImporterAttribute), true).FirstOrDefault() where attribute != null where attribute.Name == name select t).FirstOrDefault(); return found == null ? null : (IImporter) lifetimeScope.Resolve(found, new TypedParameter(typeof (IOctopusRepository), repository), new TypedParameter(typeof (IOctopusFileSystem), fileSystem), new TypedParameter(typeof (ILog), log)); }
public void Load(IPortalApplication portalApplication) { PortalApplication = portalApplication; PortalApplication.Bindings.Add(typeof (Extension.Dto.Job), new JobParameterBinding()); var module = PortalApplication.PortalRepository.ModuleGet("Octopus"); var config = OctopusConfig.Create(module); OctopusRepository = new OctopusRepository(config.ConnectionString); portalApplication.MapRoute("/v6/Job", () => new Job(portalApplication, OctopusRepository)); portalApplication.MapRoute("/v6/Heartbeat", () => new Heartbeat(portalApplication, OctopusRepository.Heartbeat)); portalApplication.AddBinding(typeof(ClusterState), new JsonParameterBinding<ClusterState>()); }
public void Render(IOctopusRepository repository, ILog log, TaskResource resource) { var details = repository.Tasks.GetDetails(resource); if (details.ActivityLog != null) { foreach (var item in details.ActivityLog.Children) { if (log.ServiceMessagesEnabled()) { RenderToTeamCity(item, log); } else { RenderToConsole(item, log, ""); } } } }
public static IOctopusSpaceRepository ForSpace(this IOctopusRepository repo, SpaceResource space) { return(repo.Client.ForSpace(space)); }
public MachineRepository(IOctopusRepository repository) : base(repository, "Machines") { }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); // Find the project that owns the variables we want to get var project = _octopus.Projects.FindByName(Project); if (project == null) { const string msg = "Project '{0}' was not found."; throw new Exception(string.Format(msg, Project)); } var id = project.DeploymentProcessId; _deploymentProcess = _octopus.DeploymentProcesses.Get(id); var steps = from s in _deploymentProcess.Steps where s.Name.Equals(Name, StringComparison.InvariantCultureIgnoreCase) select s; _step = steps.FirstOrDefault(); if (_step == null) throw new Exception(string.Format("Step with name '{0}' was not found.", Name)); }
public EnvironmentRepository(IOctopusRepository repository) : base(repository, "Environments") { }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); WriteDebug("Got connection"); // Find the project that owns the variables we want to edit var project = _octopus.Projects.FindByName(Project); if (project == null) { const string msg = "Project '{0}' was not found."; throw new Exception(string.Format(msg, Project)); } WriteDebug("Found project" + project.Id); // Get the variables for editing _variableSet = _octopus.VariableSets.Get(project.Link("Variables")); WriteDebug("Found variable set" + _variableSet.Id); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); WriteDebug("Connection established"); switch (ParameterSetName) { case "ByProjectName": _projects = _octopus.Projects.FindByNames(Project); break; case "ByProjectId": LoadProjectsByIds(); break; case "ByDeploymentProcessId": break; default: throw new Exception("Unknown ParameterSetName: " + ParameterSetName); } }
public static ProjectChannel ToModel(this ChannelResource resource, IOctopusRepository repository) { return(new ProjectChannel(new ElementIdentifier(resource.Name), resource.Description, resource.IsDefault)); }
public TeamsRepository(IOctopusRepository repository) : base(repository, "Teams") { MinimumCompatibleVersion("2019.1.0"); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); // FIXME: Loading all the projects when you might only // be looking for one, isn't exactly efficient if (!Cache || Utilities.Cache.Projects.IsExpired) _projects = _octopus.Projects.FindAll(); if (Cache) { if (Utilities.Cache.Projects.IsExpired) Utilities.Cache.Projects.Set(_projects); else _projects = Utilities.Cache.Projects.Values; } WriteDebug("Loaded projects"); }
public ProjectExporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILogger log) : base(repository, fileSystem, log) { actionTemplateRepository = new ActionTemplateRepository(repository.Client); }
public static LibraryVariableSet ToModel(this LibraryVariableSetResource resource, IOctopusRepository repository) { var variableSetResource = repository.VariableSets.Get(resource.VariableSetId); return(new LibraryVariableSet( new ElementIdentifier(resource.Name), resource.Description, (LibraryVariableSet.VariableSetContentType)resource.ContentType, variableSetResource.Variables.Select(v => v.ToModel(null, repository)))); }
public ScopedUserRoleRepository(IOctopusRepository repository) : base(repository, "ScopedUserRoles") { MinimumCompatibleVersion("2019.1.0"); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); if (ParameterSetName != "ByName") return; var projectGroup = _octopus.ProjectGroups.FindByName(ProjectGroupName); if (projectGroup == null) throw new Exception(string.Format("Project '{0}' was not found.", ProjectGroupName)); _projectGroupId = projectGroup.Id; }
public static Dictionary <VariableScopeType, IEnumerable <ElementReference> > ToModel(this ScopeSpecification resource, DeploymentProcessResource deploymentProcessResource, IOctopusRepository repository) { return(resource.ToDictionary(kv => (VariableScopeType)kv.Key, kv => kv.Value.Select(id => ResolveReference(kv.Key, id, repository, deploymentProcessResource)).ToArray().AsEnumerable())); }
TeamsRepository(IOctopusRepository repository, SpaceContext userDefinedSpaceContext) : base(repository, "Teams", userDefinedSpaceContext) { MinimumCompatibleVersion("2019.1.0"); }
private static string ResolveId(VariableScopeType key, ElementReference reference, IOctopusRepository repository, DeploymentProcessResource deploymentProcess, ProjectResource project) { switch (key) { case VariableScopeType.Environment: return(repository.Environments.ResolveResourceId(reference)); case VariableScopeType.Machine: return(repository.Machines.ResolveResourceId(reference)); case VariableScopeType.Role: return(reference.Name); case VariableScopeType.Action: return(GetDeploymentAction(deploymentProcess, a => a.Name, reference.Name, nameof(DeploymentActionResource.Name)).Id); case VariableScopeType.Channel: return(repository.Channels.FindByName(project, reference.Name).Id); case VariableScopeType.TenantTag: return(reference.Name); default: throw new InvalidOperationException($"Unsupported ScopeField: {key}"); } }
public static TenantResource UpdateWith(this TenantResource resource, Tenant model, IOctopusRepository repository) { resource.Name = model.Identifier.Name; resource.TenantTags = new ReferenceCollection(model.TenantTags.Select(x => x.Name)); resource.ProjectEnvironments.Clear(); foreach (var projectEnvironment in model.ProjectEnvironments) { var project = repository.Projects.FindByName(projectEnvironment.Key); var envs = new ReferenceCollection(projectEnvironment.Value.Select(x => repository.Environments.FindByName(x).Id)); resource.ProjectEnvironments.Add(project.Id, envs); } return(resource); }
protected BaseImporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log) { this.log = log; this.repository = repository; fileSystemImporter = new FileSystemImporter(fileSystem, log); }
public static Dictionary <string, IEnumerable <string> > ToModel(this IDictionary <string, ReferenceCollection> collection, IOctopusRepository repository) { var projectEnvs = new Dictionary <string, IEnumerable <string> >(); foreach (var pe in collection) { var project = repository.Projects.FindOne(x => x.Id == pe.Key).Name; var envs = pe.Value.Select(e => repository.Environments.FindOne(x => x.Id == e).Name).ToArray(); projectEnvs.Add(project, envs); } return(projectEnvs); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); WriteDebug("Connection established"); if (!Cache || Utilities.Cache.Environments.IsExpired) _environments = _octopus.Environments.FindAll(); if (Cache) { if (Utilities.Cache.Environments.IsExpired) Utilities.Cache.Environments.Set(_environments); else _environments = Utilities.Cache.Environments.Values; } WriteDebug("Loaded environments"); }
public ModelUploader(IOctopusRepository repository) { _repository = repository; }
public OctopusProxy(IOctopusRepository octopusRepository) { if (octopusRepository == null) throw new ArgumentNullException(nameof(octopusRepository)); Repository = octopusRepository; }
public MachineRoleRepository(IOctopusRepository repository) { this.repository = repository; }
public MachinePolicyRepository(IOctopusRepository repository) : base(repository, "MachinePolicies") { }
protected BaseExporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log) { this.log = log; this.repository = repository; fileSystemExporter = new FileSystemExporter(fileSystem, log); }
public ReleaseExporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log) : base(repository, fileSystem, log) { }
public UserRolesRepository(IOctopusRepository repository) : base(repository, "UserRoles") { }
public void Execute(string[] commandLineArguments) { var remainingArguments = optionGroups.Parse(commandLineArguments); if (remainingArguments.Count > 0) { throw new CommandException("Unrecognized command arguments: " + string.Join(", ", remainingArguments)); } if (string.IsNullOrWhiteSpace(serverBaseUrl)) { throw new CommandException("Please specify the Octopus Server URL using --server=http://your-server/"); } if (string.IsNullOrWhiteSpace(apiKey)) { throw new CommandException("Please specify your API key using --apiKey=ABCDEF123456789. Learn more at: https://github.com/OctopusDeploy/Octopus-Tools"); } var credentials = ParseCredentials(username, password); var endpoint = new OctopusServerEndpoint(serverBaseUrl, apiKey, credentials); repository = repositoryFactory.CreateRepository(endpoint); if (enableDebugging) { repository.Client.SendingOctopusRequest += request => log.Debug(request.Method + " " + request.Uri); } ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => { if (errors == SslPolicyErrors.None) { return(true); } var certificate2 = (X509Certificate2)certificate; var warning = "The following certificate errors were encountered when establishing the HTTPS connection to the server: " + errors + Environment.NewLine + "Certificate subject name: " + certificate2.SubjectName.Name + Environment.NewLine + "Certificate thumbprint: " + ((X509Certificate2)certificate).Thumbprint; if (ignoreSslErrors) { log.Warn(warning); log.Warn("Because --ignoreSslErrors was set, this will be ignored."); return(true); } log.Error(warning); return(false); }; log.Debug("Handshaking with Octopus server: " + serverBaseUrl); var root = repository.Client.RootDocument; log.Debug("Handshake successful. Octopus version: " + root.Version + "; API version: " + root.ApiVersion); var user = repository.Users.GetCurrent(); if (user != null) { log.DebugFormat("Authenticated as: {0} <{1}> {2}", user.DisplayName, user.EmailAddress, user.IsService ? "(a service account)" : ""); } Execute(); }
private void LoadProjectVariableSet(IOctopusRepository octopus) { // Find the project that owns the variables we want to get var project = octopus.Projects.FindByName(Project); if (project == null) { throw new Exception(string.Format("Project '{0}' was not found.", Project)); } // Get the variable set _variableSets.Add(octopus.VariableSets.Get(project.Link("Variables"))); }
public static IOctopusSystemRepository ForSystem(this IOctopusRepository repo) { return(repo.Client.ForSystem()); }
public static IEnumerable <Variable> ToModel(this VariableSetResource resource, DeploymentProcessResource deploymentProcessResource, IOctopusRepository repository) { return(resource.Variables.Select(v => v.ToModel(deploymentProcessResource, repository))); }
public static ScopeSpecification UpdateWith(this ScopeSpecification resource, IReadOnlyDictionary <VariableScopeType, IEnumerable <ElementReference> > model, IOctopusRepository repository, DeploymentProcessResource deploymentProcess, ProjectResource project) { resource.Clear(); foreach (var kv in model) { resource.Add((ScopeField)kv.Key, new ScopeValue(kv.Value.Select(reference => ResolveId(kv.Key, reference, repository, deploymentProcess, project)))); } return(resource); }
public static VariableSetResource UpdateWith(this VariableSetResource resource, IVariableSet model, IOctopusRepository repository, DeploymentProcessResource deploymentProcess, ProjectResource project) { resource.Variables = model.Variables.Select(v => new VariableResource().UpdateWith(v, repository, deploymentProcess, project)).ToList(); return(resource); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); // Find the project that owns the variables we want to edit var project = _octopus.Projects.FindByName(Project); if (project == null) throw new Exception(string.Format("Project '{0}' was not found.", Project)); // Get the variables for editing _variableSet = _octopus.VariableSets.Get(project.Link("Variables")); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); _roles = _octopus.MachineRoles.GetAllRoleNames(); }
private void LoadLibraryVariableSetByIds(IOctopusRepository octopus) { // Find the library variable sets that owns the variables we want to get foreach (var id in VariableSetId) { var idForClosure = id; var variableSet = octopus.LibraryVariableSets.FindOne(vs => vs.Id == idForClosure); if (variableSet == null) WriteWarning(string.Format("Library variable set with id '{0}' was not found.", id)); else _variableSets.Add(octopus.VariableSets.Get(variableSet.Link("Variables"))); } }
private void LoadLibraryVariableSetByNames(IOctopusRepository octopus) { // Find the library variable sets that owns the variables we want to get foreach (var name in VariableSet) { var nameForClosure = name; var variableSet = octopus.LibraryVariableSets.FindOne(vs => vs.Name.Equals(nameForClosure, StringComparison.InvariantCultureIgnoreCase)); if (variableSet == null) WriteWarning(string.Format("Library variable set '{0}' was not found.", name)); else _variableSets.Add(octopus.VariableSets.Get(variableSet.Link("Variables"))); } }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); var libraryVariableSet = _octopus.LibraryVariableSets.FindOne( v => v.Name.Equals(VariableSet, StringComparison.InvariantCultureIgnoreCase)); if (libraryVariableSet == null) throw new Exception(string.Format("Library variable set '{0}' was not found.", VariableSet)); _variableSet = _octopus.VariableSets.Get(libraryVariableSet.Link("Variables")); WriteDebug("Found variable set" + _variableSet.Id); }
public ProjectExporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log) : base(repository, fileSystem, log) { actionTemplateRepository = new ActionTemplateRepository(repository.Client); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); // Find the project that owns the variables we want to get var project = _octopus.Projects.FindByName(Project); if (project == null) { const string msg = "Project '{0}' was not found."; throw new Exception(string.Format(msg, Project)); } var id = project.DeploymentProcessId; _deploymentProcess = _octopus.DeploymentProcesses.Get(id); }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); if (ParameterSetName != "ByName") return; if (Environment.Length != 1) throw new Exception(string.Format("Only 1 Environment is currently supported, you specified {0}", Environment.Length)); var environmentIds = new List<string>(); foreach (var environment in Environment) { var e = _octopus.Environments.FindByName(environment); if (e == null) throw new Exception(string.Format("Environment '{0}' was not found.", environment)); environmentIds.Add(e.Id); } EnvironmentId = environmentIds.ToArray(); }
public ReleaseImporter(IOctopusRepository repository, IOctopusFileSystem fileSystem, ILog log) : base(repository, fileSystem, log) { }
public LicensesRepository(IOctopusRepository repository) : base(repository, "CurrentLicense") { }
public ProjectTriggerRepository(IOctopusRepository repository) : base(repository, "ProjectTriggers") { }
//private List<ReleaseResource> _releases; /// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); switch (ParameterSetName) { case "ByProject": _project = _octopus.Projects.FindByName(Project); if (_project == null) throw new Exception(string.Format("The project '{0}' was not found.", Project)); break; case "ByProjectId": _project = _octopus.Projects.Get(ProjectId); if (_project == null) throw new Exception(string.Format("A project with the id '{0}' was not found.", ProjectId)); break; } //if (!Cache || Extensions.Cache.Releases.IsExpired) // _releases = _octopus.Projects.GetReleases(_project).Items.ToList(); //if (Cache) //{ // if (Extensions.Cache.Releases.IsExpired) // Extensions.Cache.Releases.Set(_releases); // else // _releases = Extensions.Cache.Releases.Values; //} WriteDebug("Loaded releases"); }
public UserRepository(IOctopusRepository repository) : base(repository, "Users") { invitations = new LegacyInvitationRepository(repository); }
public UserPermissionsRepository(IOctopusRepository repository) : base(repository, null) { }
UserPermissionsRepository(IOctopusRepository repository, SpaceContext userDefinedSpaceContext) : base(repository, null, userDefinedSpaceContext) { }
public Job(IPortalApplication portalApplication, IOctopusRepository repository) : base(portalApplication) { Repository = repository; }
/// <summary> /// BeginProcessing /// </summary> protected override void BeginProcessing() { _octopus = Session.RetrieveSession(this); WriteDebug("Connection established"); }