Ejemplo n.º 1
0
        public void PerformOperation()
        {
            NapackClientSettings settings = Serializer.Deserialize <NapackClientSettings>(File.ReadAllText(this.NapackSettingsFile));

            string      userId     = this.UserId;
            List <Guid> accessKeys = this.AuthorizationKeys?.Split(';').Select(key => Guid.Parse(key)).ToList();

            if (string.IsNullOrWhiteSpace(this.UserId) || accessKeys == null || accessKeys.Count == 0)
            {
                DefaultCredentials defaultCredentials = Serializer.Deserialize <DefaultCredentials>(File.ReadAllText(NapackClient.GetDefaultCredentialFilePath()));
                userId     = defaultCredentials.UserId;
                accessKeys = defaultCredentials.Secrets;
            }

            UserSecret userSecret = new UserSecret()
            {
                UserId  = userId,
                Secrets = accessKeys
            };

            string packageName = Path.GetFileNameWithoutExtension(this.PackageFile);
            NapackLocalDescriptor napackDescriptor = Serializer.Deserialize <NapackLocalDescriptor>(File.ReadAllText(this.PackageFile));

            napackDescriptor.Validate(userId, true);

            using (NapackServerClient client = new NapackServerClient(settings.NapackFrameworkServer))
            {
                CreateOrUpdateNapackAsync(packageName, napackDescriptor, userSecret, client).GetAwaiter().GetResult();
            }
        }
Ejemplo n.º 2
0
 private NewNapackVersion CreateNapackVersion(NapackLocalDescriptor napackDescriptor, Dictionary <string, NapackFile> files)
 {
     return(new NewNapackVersion()
     {
         Files = files,
         Dependencies = napackDescriptor.Dependencies?.Select(dependency => new NapackMajorVersion(dependency.Key, dependency.Value)).ToList() ?? new List <NapackMajorVersion>(),
         Authors = napackDescriptor.Authors,
         ForceMajorUpversioning = this.ForceMajorUpversioning,
         ForceMinorUpversioning = this.ForceMinorUpversioning,
         License = new Napack.Common.License()
         {
             LicenseText = napackDescriptor.License.LicenseText,
             LicenseType = napackDescriptor.License.Type
         }
     });
 }
Ejemplo n.º 3
0
        private async Task CreateNapackPackageAsync(string packageName, NapackLocalDescriptor napackDescriptor, Dictionary <string, NapackFile> files, UserSecret secret, NapackServerClient client)
        {
            NewNapack newNapack = new NewNapack()
            {
                metadata = new NewNapackMetadata()
                {
                    Description       = napackDescriptor.Description,
                    MoreInformation   = napackDescriptor.MoreInformation,
                    AuthorizedUserIds = napackDescriptor.AuthorizedUserIds,
                    Tags = napackDescriptor.Tags
                },
                NewNapackVersion = this.CreateNapackVersion(napackDescriptor, files)
            };

            string response = await client.CreatePackageAsync(packageName, newNapack, secret).ConfigureAwait(false);

            NapackClient.Log($"Package creation result: {response}");
        }
Ejemplo n.º 4
0
        private async Task CreateOrUpdateNapackAsync(string packageName, NapackLocalDescriptor napackDescriptor, UserSecret userSecret, NapackServerClient client)
        {
            string rootDirectory = Path.GetFullPath(Path.GetDirectoryName(this.PackageFile));
            Dictionary <string, NapackFile> files = UploadOperation.ParseNapackFiles(rootDirectory, rootDirectory);

            files.Remove(Path.GetFileName(this.PackageFile));

            bool packageExists = await client.ContainsNapack(packageName).ConfigureAwait(false);

            if (!packageExists)
            {
                await this.CreateNapackPackageAsync(packageName, napackDescriptor, files, userSecret, client).ConfigureAwait(false);
            }
            else
            {
                // This is a new version creation operation.
                VersionDescriptor version = await client.UpdatePackageAsync(packageName, this.CreateNapackVersion(napackDescriptor, files), userSecret).ConfigureAwait(false);

                NapackClient.Log($"Updated the {packageName} package to version {version.Major}.{version.Minor}.{version.Patch}");
            }
        }
Ejemplo n.º 5
0
        public void PerformOperation()
        {
            NapackClient.Log("Reading in the Napack settings file...");
            NapackClientSettings settings = Serializer.Deserialize <NapackClientSettings>(File.ReadAllText(this.NapackSettingsFile));

            string      userId     = this.UserId;
            List <Guid> accessKeys = this.AuthorizationKeys?.Split(';').Select(key => Guid.Parse(key)).ToList();

            if (string.IsNullOrWhiteSpace(this.UserId) || accessKeys == null || accessKeys.Count == 0)
            {
                DefaultCredentials defaultCredentials = Serializer.Deserialize <DefaultCredentials>(File.ReadAllText(NapackClient.GetDefaultCredentialFilePath()));
                userId     = defaultCredentials.UserId;
                accessKeys = defaultCredentials.Secrets;
            }

            UserSecret userSecret = new UserSecret()
            {
                UserId  = userId,
                Secrets = accessKeys
            };

            string packageName = Path.GetFileNameWithoutExtension(this.PackageFile);
            NapackLocalDescriptor napackDescriptor = Serializer.Deserialize <NapackLocalDescriptor>(File.ReadAllText(this.PackageFile));

            napackDescriptor.Validate(userId, false);

            using (NapackServerClient client = new NapackServerClient(settings.NapackFrameworkServer))
            {
                NewNapackMetadata metadata = new NewNapackMetadata()
                {
                    AuthorizedUserIds = napackDescriptor.AuthorizedUserIds,
                    Description       = napackDescriptor.Description,
                    MoreInformation   = napackDescriptor.MoreInformation,
                    Tags = napackDescriptor.Tags
                };

                string response = client.UpdatePackageMetadataAsync(packageName, metadata, userSecret).GetAwaiter().GetResult();
                NapackClient.Log($"Package metadata update result: {response}");
            }
        }