A simplified interface to commonly-used parts of the API. Functionality not exposed by this interface can be accessed using IOctopusRepository.Client.
Create using: var repository = new OctopusRepository(new OctopusServerEndpoint("http://myoctopus/"));
Inheritance: IOctopusRepository
 public OctopusAuthenticationProxy(IOptions<AppSettings> settings)
 {
     if (settings == null) throw new ArgumentNullException(nameof(settings));
     
     var endpoint = new OctopusServerEndpoint(settings.Value.OctopusServerAddress);
     _repository = new OctopusRepository(endpoint);
 }
 public int Run()
 {
     var octopusRepository = new OctopusRepository(new OctopusServerEndpoint(OctopusServerAddress, OctopusApiKey));
     var nautilusService = new NautilusService(octopusRepository, Console.Out);
     
     try 
     {
         Run(nautilusService);
     }
     catch (NautilusException ex)
     {
         Console.Error.WriteLine(ex.Message);
         if (!String.IsNullOrEmpty(ex.MessageDetails))
         {
             Console.Error.WriteLine(ex.MessageDetails);
         }
         if (ex.InnerException != null)
         {
             Console.Error.WriteLine(ex.InnerException.ToString());
         }
         
         return ex.ErrorCode;
     }
     
     return 0;
 }
 public ProjectAccess(OctopusUri octopusUri,ApiKey apiKey)
 {
     _octopusUri = octopusUri;
     _apiKey = apiKey;
     _octopusServerEndpoint = new OctopusServerEndpoint(_octopusUri.ToString(),_apiKey);
     _octopusRepo = new OctopusRepository(_octopusServerEndpoint);
 }
Example #4
0
        /// <summary>
        /// ProcessRecord
        /// </summary>
        protected override void ProcessRecord()
        {
            var octopusServerEndpoint = new OctopusServerEndpoint(Server, ApiKey);
            var octopus = new OctopusRepository(octopusServerEndpoint);

            SessionState.PSVariable.Set("OctopusRepository", octopus);
        }
Example #5
0
        public CommandBase(IConfiguration config)
        {
            _config = config;

            var factory = new OctopusClientFactory();
            var client = factory.CreateClient(new OctopusServerEndpoint(_config.OctopusHost + "api", _config.OctopusApiKey));
            _repo = new OctopusRepository(client);
        }
        public OctopusProxy(IOptions<AppSettings> settings, IHttpContextAccessor httpContextAccessor)
        {
            if (settings == null) throw new ArgumentNullException(nameof(settings));

            var apiKey = httpContextAccessor.HttpContext.User.GetOctopusApiKey();
            
            var endpoint = new OctopusServerEndpoint(settings.Value.OctopusServerAddress, apiKey);
            _repository = new OctopusRepository(endpoint);
        }
        private OctopusConnector()
        {
            User = ConfigurationManager.AppSettings["octopus-user"];
            Pass = ConfigurationManager.AppSettings["octopus-pass"];
            Server = ConfigurationManager.AppSettings["octopus-server"];
            ApiKey = ConfigurationManager.AppSettings["octopus-key"];

            endpoint = new OctopusServerEndpoint(Server, ApiKey);
            repository = new OctopusRepository(endpoint);
        }
Example #8
0
        internal OctopusClient(OctopusServerEndpoint serverEndpoint, string requestingTool, OctopusClientOptions options = default)
        {
            this.serverEndpoint = serverEndpoint;
            options ??= new OctopusClientOptions();

            httpRouteExtractor   = new HttpRouteExtractor(options.ScanForHttpRouteTypes);
            cookieOriginUri      = BuildCookieUri(serverEndpoint);
            octopusCustomHeaders = new OctopusCustomHeaders(requestingTool);
            Repository           = new OctopusRepository(this);
        }
        public bool ValidateApiKey(string userName, string apiKey)
        {
            var repository = new OctopusRepository(new OctopusServerEndpoint(_octopusServerAddress, apiKey));

            UserResource user;
            try
            {
                user = repository.Users.GetCurrent();
            }
            catch (OctopusSecurityException)
            {
                return false;
            }

            return user.Username == userName;
        }
        public OctopusDeployVersion FindCurrentlyDeployedProductionVersion(string projectName, string environmentName)
        {
            var endpoint = new OctopusServerEndpoint(_octopusDeploySettings.SevrerUrl, _octopusDeploySettings.ApiKey);
            var repository = new OctopusRepository(endpoint);

            string[] projectIdList = new string[1];
            string[] environments = new string[1];

            projectIdList[0] = repository.Projects.FindByName(projectName).Id;
            environments[0] = repository.Environments.FindByName(environmentName).Id;

            var productionDeployments = repository.Deployments.FindAll(projectIdList, environments);

            var releaseId = productionDeployments.Items.First().ReleaseId;
            var release = repository.Releases.FindOne(x => x.Id == releaseId);
            var version = new OctopusDeployVersion() {DateReleaseCreated = release.Assembled.DateTime, VersionNumber = release.Version};

            return version;
        }
		public VariableDictionary Get(OctopusConfigurationProviderOptions options)
		{
			var variableDictionary = new VariableDictionary();

			var endpoint = new OctopusServerEndpoint(options.ServerAddress.ToString(), options.ApiKey);
			var repository = new OctopusRepository(endpoint);

			var project = repository.Projects.FindByName(options.ProjectName);
			if (project == null)
			{
				return variableDictionary;
			}

			var scopes = new Dictionary<ScopeField, string>();
			if (!string.IsNullOrEmpty(options.EnvironmentName))
			{
				scopes[ScopeField.Environment] = options.EnvironmentName;
			}
			if (!string.IsNullOrEmpty(options.MachineName))
			{
				scopes[ScopeField.Machine] = options.MachineName;
			}

			var variableSetIds = new List<string> { project.VariableSetId };
			variableSetIds.AddRange(project.IncludedLibraryVariableSetIds.Select(id => repository.LibraryVariableSets.Get(id).VariableSetId));

			var variables = new Dictionary<string, SortedSet<VariableResource>>();
			foreach (var variableSetId in variableSetIds)
			{
				var variableSet = repository.VariableSets.Get(variableSetId);
				AddVariableSet(variables, variableSet, scopes);
			}

			foreach (var variableName in variables.Keys)
			{
				variableDictionary.Set(variableName, variables[variableName].First().Value);
			}

			return variableDictionary;
		}
Example #12
0
        public OctoRepository(ServerInstanceElement instance)
        {
            ApiUri = instance.ApiUri.TrimEnd('/');

            var endpoint = new OctopusServerEndpoint(ApiUri, instance.ApiKey);
            var client = new OctopusClient(endpoint);
            _repository = new OctopusRepository(client);

            SystemInfoResource systemInfo;

            try
            {
                ServerStatusResource serverStatus = _repository.ServerStatus.GetServerStatus();
                systemInfo = _repository.ServerStatus.GetSystemInfo(serverStatus);
            }
            catch (OctopusException ex)
            {
                throw;
            }

            Version = new SemanticVersion(systemInfo.Version);

            using (var databaseModel = new DatabaseModel())
            {
                OctopusServer octopusServer = databaseModel.OctopusServers.SingleOrDefault(octo => octo.ApiUri == ApiUri);

                if (octopusServer == null)
                {
                    octopusServer = new OctopusServer();
                    octopusServer.ApiUri = ApiUri;
                    octopusServer.DisplayName = ApiUri;
                    databaseModel.OctopusServers.Add(octopusServer);
                    databaseModel.SaveChanges();
                }

                OctopusServerId = octopusServer.Id;
            }
        }
 public static void ImportVariables(OctopusRepository octopusRepository, ProjectResource createdProject,
     VariableSetResource variables)
 {
     variables.OwnerId = createdProject.Id;
     variables.Links["Self"] = string.Format("/api/variables/{0}", createdProject.VariableSetId);
     variables.Version = 0;
     octopusRepository.VariableSets.Modify(variables);
 }
 private IOctopusRepository GetOctoRepo()
 {
     var octopus = new OctopusRepository(new OctopusServerEndpoint(_args.Server, _args.Key));
       return octopus;
 }
Example #15
0
 public OctopusClient(OctopusApiConfiguration octopusApiConfiguration)
 {
     repository = new OctopusRepository(new OctopusServerEndpoint(octopusApiConfiguration.ServerUri, octopusApiConfiguration.ApiKey));
     serverUri = new Uri(octopusApiConfiguration.ServerUri);
 }
 public static void UpdateVariablesVersion(string projectSlug, OctopusRepository octopusRepository,
     ProjectResource project, VariableSetResource varaibleResources)
 {
     var variables = octopusRepository.VariableSets.Get(project.VariableSetId);
     varaibleResources.Version = variables.Version;
 }
 public static void UpdateProcessVersion(string projectSlug, OctopusRepository octopusRepository,
     ProjectResource project, DeploymentProcessResource deploymentProcessResource)
 {
     var process = octopusRepository.DeploymentProcesses.Get(project.DeploymentProcessId);
     deploymentProcessResource.Version = process.Version;
 }
 public static void ImportChannels(OctopusRepository octopusRepository, ProjectResource createdProject,
     ResourceCollection<ChannelResource> channels)
 {
     foreach (var channel in channels.Items)
     {
         try
         {
             channel.ProjectId = createdProject.Id;
             if (!channel.Name.Equals("Default"))
             {
                 octopusRepository.Channels.Create(channel);
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }
 public static void ImportProcess(OctopusRepository octopusRepository, ProjectResource createdProject,
     DeploymentProcessResource process)
 {
     process.ProjectId = createdProject.Id;
     process.Id = string.Format("deploymentprocess-{0}", createdProject.Id);
     process.Links["Self"] = string.Format("/api/deploymentprocesses/{0}", createdProject.DeploymentProcessId);
     process.Version = 0;
     octopusRepository.DeploymentProcesses.Modify(process);
 }