Beispiel #1
0
        private bool TryGetCredentials(out string authString)
        {
            authString = this.gitAuthorization;
            if (authString == null)
            {
                lock (this.gitAuthorizationLock)
                {
                    if (this.gitAuthorization == null)
                    {
                        string gitUsername;
                        string gitPassword;
                        bool   backingOff = DateTime.Now < this.authRetryBackoff;
                        if (this.credentialHasBeenRevoked)
                        {
                            // Update backoff after an immediate first retry.
                            this.authRetryBackoff = DateTime.Now.AddMinutes(AuthorizationBackoffMinutes);
                        }

                        if (backingOff ||
                            !GitProcess.TryGetCredentials(this.tracer, this.enlistment, out gitUsername, out gitPassword))
                        {
                            authString = null;
                            return(false);
                        }

                        this.gitAuthorization = Convert.ToBase64String(Encoding.ASCII.GetBytes(gitUsername + ":" + gitPassword));
                    }

                    authString = this.gitAuthorization;
                }
            }

            return(true);
        }
Beispiel #2
0
        private bool TryGetCredentials(out string authString)
        {
            authString = this.gitAuthorization;
            if (authString == null)
            {
                lock (this.gitAuthorizationLock)
                {
                    if (this.gitAuthorization == null)
                    {
                        string gitUsername;
                        string gitPassword;

                        // These auth settings are necessary to support running the functional tests on build servers.
                        // The reason it's needed is that the GVFS.Service runs as LocalSystem, and the build agent does not
                        // so storing the agent's creds in the Windows Credential Store does not allow the service to discover it
                        GitProcess        git            = new GitProcess(this.enlistment);
                        GitProcess.Result usernameResult = git.GetFromConfig("gvfs.FunctionalTests.UserName");
                        GitProcess.Result passwordResult = git.GetFromConfig("gvfs.FunctionalTests.Password");

                        if (!usernameResult.HasErrors &&
                            !passwordResult.HasErrors)
                        {
                            gitUsername = usernameResult.Output.TrimEnd('\n');
                            gitPassword = passwordResult.Output.TrimEnd('\n');

                            EventMetadata metadata = new EventMetadata()
                            {
                                { "username", gitUsername },
                            };

                            this.tracer.RelatedEvent(EventLevel.LogAlways, "FunctionalTestCreds", metadata);
                        }
                        else
                        {
                            bool backingOff = DateTime.Now < this.authRetryBackoff;
                            if (this.credentialHasBeenRevoked)
                            {
                                // Update backoff after an immediate first retry.
                                this.authRetryBackoff = DateTime.Now.AddMinutes(AuthorizationBackoffMinutes);
                            }

                            if (backingOff ||
                                !GitProcess.TryGetCredentials(this.tracer, this.enlistment, out gitUsername, out gitPassword))
                            {
                                authString = null;
                                return(false);
                            }
                        }

                        this.gitAuthorization = Convert.ToBase64String(Encoding.ASCII.GetBytes(gitUsername + ":" + gitPassword));
                    }

                    authString = this.gitAuthorization;
                }
            }

            return(true);
        }
Beispiel #3
0
        public bool TryGetCredentials(ITracer tracer, out string gitAuthString, out string errorMessage)
        {
            gitAuthString = this.cachedAuthString;
            if (this.cachedAuthString == null)
            {
                lock (this.gitAuthorizationLock)
                {
                    if (this.cachedAuthString == null)
                    {
                        string gitUsername;
                        string gitPassword;

                        // These auth settings are necessary to support running the functional tests on build servers.
                        // The reason it's needed is that the GVFS.Service runs as LocalSystem, and the build agent does not
                        // so storing the agent's creds in the Windows Credential Store does not allow the service to discover it
                        GitProcess        git            = new GitProcess(this.enlistment);
                        GitProcess.Result usernameResult = git.GetFromConfig("gvfs.FunctionalTests.UserName");
                        GitProcess.Result passwordResult = git.GetFromConfig("gvfs.FunctionalTests.Password");

                        if (!usernameResult.HasErrors &&
                            !passwordResult.HasErrors)
                        {
                            gitUsername = usernameResult.Output.TrimEnd('\n');
                            gitPassword = passwordResult.Output.TrimEnd('\n');
                        }
                        else
                        {
                            bool backingOff = DateTime.Now < this.authRetryBackoff;
                            if (this.credentialHasBeenRevoked)
                            {
                                // Update backoff after an immediate first retry.
                                this.authRetryBackoff = DateTime.Now.AddMinutes(AuthorizationBackoffMinutes);
                            }

                            if (backingOff || !GitProcess.TryGetCredentials(tracer, this.enlistment, out gitUsername, out gitPassword))
                            {
                                gitAuthString = null;
                                errorMessage  =
                                    this.authRetryBackoff == DateTime.MinValue
                                    ? "Authorization failed."
                                    : "Authorization failed. No retries will be made until: " + this.authRetryBackoff;
                                return(false);
                            }
                        }

                        this.cachedAuthString = Convert.ToBase64String(Encoding.ASCII.GetBytes(gitUsername + ":" + gitPassword));
                    }

                    gitAuthString = this.cachedAuthString;
                }
            }

            errorMessage = null;
            return(true);
        }