示例#1
0
        public void Push(string url, string key, Stream stream)
        {
            var package = new ZipPackage(stream);
            stream = package.GetStream();

            var server = new PackageServer(url, "SymbolSource");
            server.PushPackage(key, package, stream.Length, 5000, false);
        }
示例#2
0
        public void PublishPackage(string file, string apiKey)
        {
            var packageServer = new PackageServer(Feed.NuGetV2.Url, "ripple");
            var package = new ZipPackage(file);

            RippleLog.Info("Publishing " + file);
            packageServer.PushPackage(apiKey, package.GetStream, (int)60.Minutes().TotalMilliseconds);
        }
 /// <summary>Publishes to the NuGet main repository.</summary>
 public static void PublishToNuget(string packagePath, string nugetApiKey)
 {
     TraceSource.TraceEvent(TraceEventType.Verbose, "Pushing \"{0}\" to NuGet repository", packagePath);
     PackageServer packageServer = new PackageServer("https://nuget.org/", "Google.Apis");
     try
     {
         packageServer.PushPackage(nugetApiKey, new ZipPackage(packagePath), NuGetPushTimeoutMills);
         TraceSource.TraceEvent(TraceEventType.Information, "\"{0}\" was pushed successfully", packagePath);
     }
     catch (Exception ex)
     {
         TraceSource.TraceEvent(TraceEventType.Error, "Can't publish \"{0}\" to NuGet repository. " +
             "Exception is: {1}", packagePath, ex.Message);
     }
 }
        // POST /api/sign
        public async Task<HttpResponseMessage> Post([FromBody]WebHookEvent payload)
        {
            if (payload.Payload.PackageIdentifier.EndsWith(ConfigurationManager.AppSettings["Signature:PackageIdSuffix"]))
            {
                return new HttpResponseMessage(HttpStatusCode.OK) {ReasonPhrase = "Package is already signed. "};
            }

            string tempPath = Path.GetTempFileName();
            try
            {
                // Download the package
                var httpClient = new HttpClient();
                var packageStream = await httpClient.GetStreamAsync(payload.Payload.PackageDownloadUrl);

                using (var stream = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    packageStream.CopyTo(stream);
                }

                // Sign the package
                PackageSigner signer = new PackageSigner();
                if (signer.SignPackage(tempPath, tempPath,
                    ConfigurationManager.AppSettings["Signature:KeyFile"],
                    ConfigurationManager.AppSettings["Signature:KeyFilePassword"],
                    payload.Payload.PackageIdentifier + ConfigurationManager.AppSettings["Signature:PackageIdSuffix"]))
                {
                    var server = new PackageServer(ConfigurationManager.AppSettings["Signature:NuGetFeedUrl"], "Signature/1.0");
                    server.PushPackage(ConfigurationManager.AppSettings["Signature:NuGetFeedApiKey"], new OptimizedZipPackage(tempPath), new FileInfo(tempPath).Length, 60 * 1000, true);
                    OptimizedZipPackage.PurgeCache();

                    return new HttpResponseMessage(HttpStatusCode.Created) { ReasonPhrase = "Package has been signed." };
                }
            }
            finally
            {
                File.Delete(tempPath);
            }

            return new HttpResponseMessage(HttpStatusCode.OK) { ReasonPhrase = "Package is already signed." };
        }
示例#5
0
        public static void push_package(ChocolateyConfiguration config, string nupkgFilePath)
        {
            var timeout = TimeSpan.FromSeconds(Math.Abs(config.PushCommand.TimeoutInSeconds));
            if (timeout.Seconds <= 0)
            {
                timeout = TimeSpan.FromMinutes(5); // Default to 5 minutes
            }
            const bool disableBuffering = false;

            var packageServer = new PackageServer(config.Sources, ApplicationParameters.UserAgent);
            packageServer.SendingRequest += (sender, e) => { if (config.Verbose) "chocolatey".Log().Info(ChocolateyLoggers.Verbose, "{0} {1}".format_with(e.Request.Method, e.Request.RequestUri)); };

            var package = new OptimizedZipPackage(nupkgFilePath);

            try
            {
                packageServer.PushPackage(
                    config.PushCommand.Key,
                    package,
                    new FileInfo(nupkgFilePath).Length,
                    Convert.ToInt32(timeout.TotalMilliseconds),
                    disableBuffering);
            }
            catch (InvalidOperationException ex)
            {
                var message = ex.Message;
                if (!string.IsNullOrWhiteSpace(message) && message.Contains("(500) Internal Server Error"))
                {
                    throw new ApplicationException("There was an internal server error, which might mean the package already exists on a Simple OData Server.", ex);
                }

                throw;
            }


            "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} was pushed successfully to {1}".format_with(package.GetFullName(), config.Sources));
        }
示例#6
0
        public void PublishPackage(string file, string apiKey)
        {
            var packageServer = new PackageServer("https://nuget.org/", "ripple");
            var package = new OptimizedZipPackage(file);

            RippleLog.Info("Publishing " + file + " with " + apiKey);

            packageServer.PushPackage(apiKey, package, (int)60.Minutes().TotalMilliseconds);
        }
示例#7
0
        public void PublishPackage(string serverUrl, string file, string apiKey)
        {
            var packageServer = new PackageServer(serverUrl, "ripple");
            var package = new OptimizedZipPackage(file);

            RippleLog.Info("Publishing " + file + " with " + apiKey);

            try
            {
                packageServer.PushPackage(apiKey, package, (int) 60.Minutes().TotalMilliseconds);
            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("already exists"))
                {
                    ConsoleWriter.Write(ConsoleColor.Yellow, "File {0} already exists on the server".ToFormat(file));
                }
                else
                {
                    ConsoleWriter.Write(ConsoleColor.Red, "File {0} failed!");
                    ConsoleWriter.Write(ConsoleColor.Red, ex.ToString());
                }

            }
        }
        void WritePackage(PackageBuilder builder, ManifestMetadata metadata)
        {
            //Create the Nuget package
            if (!Directory.Exists(NugetRepository)) Directory.CreateDirectory(NugetRepository);

            var package = NugetRepository + metadata.Id + NugetSeparator + metadata.Version + ".nupkg";
            using (FileStream stream = File.Open(package, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read))
                {
                    builder.Populate(metadata);
                    builder.Save(stream);
                }
                Trace.TraceInformation("Package {0} created locally", package);
                
                var localRepo = PackageRepositoryFactory.Default.CreateRepository(new DirectoryInfo("./nuget-repository").FullName);
                var nuGetPackage = PackageHelper.ResolvePackage(localRepo, metadata.Id, new SemanticVersion(metadata.Version));
                var packageFile = new FileInfo(package);
                var size = packageFile.Length;
                var ps = new PackageServer(_repository, "None");
                ps.PushPackage(_credential, nuGetPackage, size, 50000, false);
               
                Trace.TraceInformation("Package {0} uploaded to {1}", package, _repository);
        }
 public LocalPackageRepository(string path, string packageSource)
 {
   packageSource = string.IsNullOrEmpty(packageSource) ? "http://nugetsource/" : packageSource;
   _ps = new PackageServer(packageSource, "Package.Util");
   _localRepository = PackageRepositoryFactory.Default.CreateRepository(path);
 }
示例#10
0
 void INuGetServer.PushPackage(IPackage package)
 {
     var server = new PackageServer(_settings.Url, "NuGet Command Line");
     server.PushPackage(_settings.Key, package, 10000);
 }
示例#11
0
 public ServerPushLocation(string apiKey, PackageServer server)
 {
     _apiKey = apiKey;
     _server = server;
 }
示例#12
0
        protected internal override IPackagePushLocation GetPushLocation()
        {
            if (ServerPath == null)
                ServerPath = new Uri("https://nuget.org");
            PackageServer server = new PackageServer(ServerPath.ToString(), "NAnt.NuGet");
            string apiKey = ApiKey;
            if (apiKey == null && ApiKeyFile != null)
            {
                if (!ApiKeyFile.Exists)
                    throw new BuildException(String.Format("Api key-file '{0}' does not exist.", ApiKeyFile.FullName));
                apiKey = File.ReadAllText(ApiKeyFile.FullName);
            }

            return new ServerPushLocation(apiKey, server);
        }
示例#13
0
        public IPublishReportItem PublishPackage(string serverUrl, string file, string apiKey)
        {
            var packageServer = new PackageServer(serverUrl, "ripple");
            var package = new OptimizedZipPackage(file);

            RippleLog.Info("Publishing " + file + " with " + apiKey);

            try
            {
                var info = new FileInfo(file);
                packageServer.PushPackage(apiKey, package, info.Length, (int)60.Minutes().TotalMilliseconds);
                return new PublishSuccessful(package);
            }
            catch (Exception ex)
            {
                // TODO -- Hate this
                if (ex.Message.Contains("exists"))
                {
                    return new VersionAlreadyExists(package);
                }

                return new PublishFailure(package, ex);

            }
        }
        public void PublishPackage_PackageStreamIsNull_ResultIsFalse()
        {
            // Arrange
            string packagePath = @"C:\local-nuget-repo\package.nupkg";
            string packageServerConfigurationName = "Nuget.org Publish Config";

            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            var packageServerFactory = new Mock<IPackageServerFactory>();
            var publishConfigurationAccessor = new Mock<IPublishConfigurationAccessor>();

            Stream packageStream = null;
            filesystemAccessor.Setup(f => f.FileExists(packagePath)).Returns(true);
            filesystemAccessor.Setup(f => f.GetReadStream(packagePath)).Returns(packageStream);

            var publishConfiguration = new PublishConfiguration { Name = packageServerConfigurationName, PublishLocation = "http://nuget.org/api/v2" };
            publishConfigurationAccessor.Setup(p => p.GetPublishConfiguration(packageServerConfigurationName)).Returns(publishConfiguration);

            var packageServer = new PackageServer(publishConfiguration.PublishLocation, NuDeployConstants.NuDeployCommandLinePackageId);
            packageServerFactory.Setup(p => p.GetPackageServer(It.IsAny<string>())).Returns(packageServer);

            var publishingService = new PublishingService(filesystemAccessor.Object, packageServerFactory.Object, publishConfigurationAccessor.Object);

            // Act
            var result = publishingService.PublishPackage(packagePath, packageServerConfigurationName);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
 public void Push(string url, string key, Stream stream)
 {
     var server = new PackageServer(url, "SymbolSource");
     server.PushPackage(key, stream, 5000);
 }