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
        public void PerformOperation()
        {
            // The specified napacks.
            NapackClient.Log("Reading in the Napacks JSON file...");
            Dictionary <string, string>    rawNapacks    = Serializer.Deserialize <Dictionary <string, string> >(File.ReadAllText(this.NapacksFile));
            List <NapackVersionIdentifier> listedNapacks = rawNapacks.Select(item => new NapackVersionIdentifier(item.Key + "." + item.Value)).ToList();

            // The specified napacks, plus those dependencies. This doesn't have to exist -- we'll detect everything as unused if it doesn't and clear the napack folder.
            Dictionary <string, List <NapackVersion> > knownNapacks = new Dictionary <string, List <NapackVersion> >();

            try
            {
                knownNapacks = Serializer.Deserialize <Dictionary <string, List <NapackVersion> > >(File.ReadAllText(this.NapacksFile + UpdateOperation.LockFileSuffix));
            }
            catch (Exception)
            {
                NapackClient.Log("Didn't find the napack lock file; packages may be redownloaded.");
            }

            NapackClient.Log("Reading in the Napack Settings JSON file...");
            NapackClientSettings settings = Serializer.Deserialize <NapackClientSettings>(File.ReadAllText(this.NapackSettingsFile));

            // Now that we've read in everything, start processing.
            knownNapacks = this.RemoveUnusedNapacks(knownNapacks);

            using (NapackServerClient client = new NapackServerClient(settings.NapackFrameworkServer))
            {
                this.AcquireNapacks(client, listedNapacks, knownNapacks);
            }

            // Save the lock file now that we're in an updated state.
            foreach (NapackVersion knownNapack in knownNapacks.Values.SelectMany(value => value))
            {
                // Clear the files so we aren't duplicating them in the lock file.
                knownNapack.Files.Clear();
            }
            File.WriteAllText(this.NapacksFile + UpdateOperation.LockFileSuffix, Serializer.Serialize(knownNapacks));

            // Extract out our version identifiers
            List <NapackVersionIdentifier>     napackVersionIdentifiers = new List <NapackVersionIdentifier>();
            Dictionary <string, NapackVersion> allNapackVersions        = new Dictionary <string, NapackVersion>();

            foreach (KeyValuePair <string, List <NapackVersion> > napackVersions in knownNapacks)
            {
                foreach (NapackVersion napackVersion in napackVersions.Value)
                {
                    napackVersionIdentifiers.Add(new NapackVersionIdentifier(napackVersions.Key, napackVersion.Major, napackVersion.Minor, napackVersion.Patch));
                    allNapackVersions.Add(napackVersions.Key, napackVersion);
                }
            }

            NapackTargets.SaveNapackTargetsFile(this.ProjectDirectory, this.NapackDirectory, napackVersionIdentifiers);
            NapackAttributions.SaveNapackAttributionsFile(this.ProjectDirectory, allNapackVersions);
        }
Ejemplo n.º 3
0
        public void PerformOperation()
        {
            NapackClientSettings settings = Serializer.Deserialize <NapackClientSettings>(File.ReadAllText(this.NapackSettingsFile));

            using (NapackServerClient client = new NapackServerClient(settings.NapackFrameworkServer))
            {
                string response = client.VerifyUserAsync(this.UserEmail, this.VerificationCode).GetAwaiter().GetResult();
                NapackClient.Log("Verification status:");
                NapackClient.Log(response);
            }
        }
Ejemplo n.º 4
0
        public void PerformOperation()
        {
            NapackClientSettings settings = Serializer.Deserialize <NapackClientSettings>(File.ReadAllText(this.NapackSettingsFile));

            using (NapackServerClient client = new NapackServerClient(settings.NapackFrameworkServer))
            {
                UserSecret secret = client.RegisterUserAsync(this.UserEmail).GetAwaiter().GetResult();
                NapackClient.Log($"User {secret.UserId} successfully registered. Secrets (order&case sensitive):");
                foreach (Guid individualSecret in secret.Secrets)
                {
                    NapackClient.Log($"  {individualSecret}");
                }

                if (this.SaveAsDefault)
                {
                    File.WriteAllText(NapackClient.GetDefaultCredentialFilePath(), Serializer.Serialize(new DefaultCredentials(secret.UserId, secret.Secrets)));
                }
            }
        }
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}");
            }
        }