Exemple #1
0
        /// <summary>
        /// Initializes a new <see cref="GitRepositoryKey"/>.
        /// </summary>
        /// <param name="secretKeyStore">The secret key store.</param>
        /// <param name="url">The url of the remote.</param>
        /// <param name="isPublic">Whether this repository is public.</param>
        public GitRepositoryKey(SecretKeyStore secretKeyStore, Uri url, bool isPublic)
        {
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (secretKeyStore == null)
            {
                throw new ArgumentNullException(nameof(secretKeyStore));
            }
            IsPublic       = isPublic;
            OriginUrl      = url;
            SecretKeyStore = secretKeyStore;

            if (url.Authority.Equals("github.com", StringComparison.OrdinalIgnoreCase))
            {
                KnownGitProvider = KnownGitProvider.GitHub;
            }
            else if (url.Authority.Equals("gitlab.com", StringComparison.OrdinalIgnoreCase))
            {
                KnownGitProvider = KnownGitProvider.GitLab;
            }
            else if (url.Authority.Equals("dev.azure.com", StringComparison.OrdinalIgnoreCase))
            {
                KnownGitProvider = KnownGitProvider.AzureDevOps;
            }
            else if (url.Authority.Equals("bitbucket.org", StringComparison.OrdinalIgnoreCase))
            {
                KnownGitProvider = KnownGitProvider.Bitbucket;
            }
            else if (url.Scheme == Uri.UriSchemeFile)
            {
                KnownGitProvider = KnownGitProvider.FileSystem;
            }

            if (KnownGitProvider == KnownGitProvider.FileSystem)
            {
                return;                                                   //No credentials needed.
            }
            if (KnownGitProvider != KnownGitProvider.Unknown)
            {
                string GetReadPATDescription(SecretKeyInfo current)
                {
                    var d = current?.Description ?? $"Used to read/clone solutions hosted by '{KnownGitProvider}'.";

                    if ((current == null || !current.IsRequired) && !IsPublic)
                    {
                        d += $" This secret is required since at least '{url}' is not public.";
                    }
                    return(d);
                }

                // The read PAT is required only if the repository is not public.
                ReadPATKeyName = GetPATName();
                var read = secretKeyStore.DeclareSecretKey(ReadPATKeyName, GetReadPATDescription, isRequired: !IsPublic);
                // The write PAT is the super key of the read PAT.
                WritePATKeyName = GetPATName("_WRITE_PAT");
                secretKeyStore.DeclareSecretKey(WritePATKeyName, current => current?.Description ?? $"Used to push solutions hosted by '{KnownGitProvider}'. This is required to publish builds.", subKey: read);
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new WorldSelector that exposes a <see cref="CurrentWorld"/>.
 /// </summary>
 /// <param name="store">The world store.</param>
 /// <param name="commandRegister">The command register.</param>
 /// <param name="factory">The factory for XTypedObjects.</param>
 /// <param name="userKeyStore">The user key store.</param>
 /// <param name="appLife">Simple application lifetime controller.</param>
 public WorldSelector(WorldStore store, CommandRegister commandRegister, XTypedFactory factory, SecretKeyStore userKeyStore, IBasicApplicationLifetime appLife)
 {
     Store         = store ?? throw new ArgumentNullException(nameof(store));
     _command      = commandRegister ?? throw new ArgumentNullException(nameof(commandRegister));
     _userKeyStore = userKeyStore ?? throw new ArgumentNullException(nameof(userKeyStore));
     _appLife      = appLife ?? throw new ArgumentNullException(nameof(appLife));
     _factory      = factory ?? throw new ArgumentNullException(nameof(factory));
     commandRegister.Register(this);
     _existingCommands = new HashSet <ICommandHandler>(commandRegister.GetAllCommands(false));
 }
Exemple #3
0
 public UserKeyVault(NormalizedPath userHostPath)
 {
     _store = new SecretKeyStore();
     _store.SecretDeclared += OnSecretDeclared;
     _vaultContent          = new Dictionary <string, string>();
     KeyVaultKeyName        = "CKLI-" + Environment.UserDomainName
                              .Replace('-', '_')
                              .Replace('/', '_')
                              .Replace('\\', '_')
                              .Replace('.', '_')
                              .ToUpperInvariant();
     KeyVaultPath = userHostPath.AppendPart(KeyVaultKeyName + ".KeyVault.txt");
 }
Exemple #4
0
 public GitWorldStore(
     NormalizedPath userHostPath,
     SimpleWorldLocalMapping mapping,
     SecretKeyStore keyStore,
     CommandRegister commandRegister)
     : base(mapping)
 {
     _rootPath               = userHostPath;
     SecretKeyStore          = keyStore;
     StacksFilePath          = userHostPath.AppendPart("Stacks.xml");
     _stackRepos             = new List <StackRepo>();
     mapping.MappingChanged += Mapping_MappingChanged;
     commandRegister.Register(this);
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new <see cref="FileSystem"/> on a physical root path.
 /// </summary>
 /// <param name="rootPath">Physical root path.</param>
 /// <param name="commandRegister">Command register.</param>
 /// <param name="sp">Optional base services.</param>
 public FileSystem(
     string rootPath,
     CommandRegister commandRegister,
     SecretKeyStore secretKeyStore,
     IServiceProvider sp)
 {
     Root             = new NormalizedPath(Path.GetFullPath(rootPath));
     _commandRegister = commandRegister;
     _secretKeyStore  = secretKeyStore;
     _protoGits       = new List <ProtoGitFolder>();
     _gits            = new List <GitFolder>();
     ServiceContainer = new SimpleServiceContainer(sp);
     ServiceContainer.Add(this);
     ServiceContainer.Add <IFileProvider>(this);
 }
Exemple #6
0
 public XWorldSecrets(Initializer initializer, SecretKeyStore keyStore) : base(initializer)
 {
     initializer.Reader.HandleAddRemoveClearChildren(
         new HashSet <object>(),
         b =>
     {
         string name        = b.HandleRequiredAttribute <string>("Name");
         string password    = b.HandleRequiredAttribute <string>("Value");
         string description = b.HandleRequiredAttribute <string>("Description");
         keyStore.DeclareSecretKey(name, desc => description, true, "World");
         keyStore.SetSecret(initializer.Monitor, name, password);
         return(name);
     }
         );
     initializer.Reader.WarnUnhandled();
 }
Exemple #7
0
 internal Snapshot(SecretKeyStore store)
 {
     _data = new (string name, string description, string secret, bool isRequired, string tags, string subKey)[store._orderedInfos.Count];
Exemple #8
0
 internal StackDef(SecretKeyStore secretKeyStore, string stackName, Uri url, bool isPublic, string branchName = null)
     : base(secretKeyStore, url, isPublic)
 {
     StackName  = stackName;
     BranchName = branchName ?? "master";
 }