Пример #1
0
        private static SharpBucketV2 GetV2ClientAuthenticatedWithOAuth2()
        {
            var sharpBucket = new SharpBucketV2();

            sharpBucket.OAuth2ClientCredentials(OAuthConsumerKey, OAuthConsumerSecretKey);
            return(sharpBucket);
        }
Пример #2
0
        private void DoLogin()
        {
            AddToOutput("Logging in...." + Environment.NewLine, false, GetTimeStamp(), _OUTPUT_COLOR);
            try
            {
                if (!string.IsNullOrWhiteSpace(txtConsumerKey.Text) && !string.IsNullOrWhiteSpace(txtConsumerSecret.Text) && !string.IsNullOrWhiteSpace(txtUsername.Text))
                {
                    _SharpBucket.OAuth2ClientCredentials(txtConsumerKey.Text, txtConsumerSecret.Text);

                    var userEndPoint = _SharpBucket.UsersEndPoint(Properties.Settings.Default.username);
                    _UserProfile    = userEndPoint.GetProfile();
                    tsUserName.Text = _UserProfile.display_name + $" ({_UserProfile.username}) ";

                    mainTabs.SelectedIndex = 1;

                    AddToOutput("Login success." + Environment.NewLine, false, GetTimeStamp(), _OUTPUT_SUCCESS_COLOR);
                }
                else
                {
                    AddToOutput("Invalid login info." + Environment.NewLine, false, GetTimeStamp(), _OUTPUT_ERROR_COLOR);
                }
            }
            catch (Exception ex)
            {
                AddToOutput("Error during login : "******" - " + ex.Message + Environment.NewLine, false, GetTimeStamp(), _OUTPUT_ERROR_COLOR);
            }
        }
Пример #3
0
        public void OAuth2ClientCredentials_AllowToListPrivateRepositories()
        {
            var privateRepo = SampleRepositories.PrivateTestRepository.GetRepository();

            var sharpBucket = new SharpBucketV2();

            sharpBucket.OAuth2ClientCredentials(TestHelpers.OAuthConsumerKey, TestHelpers.OAuthConsumerSecretKey);
            var accountRepos = sharpBucket.RepositoriesEndPoint().ListRepositories(TestHelpers.AccountName);

            accountRepos.ShouldNotBe(null);
            accountRepos.Any(p => p.is_private == true && p.name == privateRepo.name).ShouldBe(true);
        }
        public BitBucketScanner(
            ProjectFileParser projectFileParser,
            string account,
            string key,
            string secretKey)
        {
            _projectFileParser = projectFileParser;
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (string.IsNullOrWhiteSpace(secretKey))
            {
                throw new ArgumentNullException(nameof(secretKey));
            }
            _bbAccount = account ?? throw new InvalidOperationException(nameof(account));

            _client = new SharpBucketV2();
            _client.OAuth2ClientCredentials(key, secretKey);
        }
        public BitBucketScanner(IConfiguration configuration)
        {
            var bbKey = configuration[KeyEnvVar];

            if (string.IsNullOrWhiteSpace(bbKey))
            {
                throw new InvalidOperationException($"{KeyEnvVar} env var can't be empty!");
            }
            var bbSecret = configuration[SecretEnvVar];

            if (string.IsNullOrWhiteSpace(bbSecret))
            {
                throw new InvalidOperationException($"{SecretEnvVar} env var can't be empty!");
            }
            _bbAccount = configuration[AccountEnvVar];
            if (string.IsNullOrWhiteSpace(_bbAccount))
            {
                throw new InvalidOperationException($"{AccountEnvVar} env var can't be empty!");
            }

            _client = new SharpBucketV2();
            _client.OAuth2ClientCredentials(bbKey, bbSecret);
        }
Пример #6
0
        public void NoAuthentication_ExplicitlyCalledAfterAnEffectiveAuthentication_ShouldReadPublicReposButNotPrivateOnes()
        {
            var privateRepo = SampleRepositories.PrivateTestRepository.GetRepository();
            var publicRepo  = SampleRepositories.EmptyTestRepository.GetRepository();

            var sharpBucket          = new SharpBucketV2();
            var repositoriesEndPoint = sharpBucket.RepositoriesEndPoint();

            sharpBucket.OAuth2ClientCredentials(TestHelpers.OAuthConsumerKey, TestHelpers.OAuthConsumerSecretKey);
            var accountRepos = repositoriesEndPoint.ListRepositories(TestHelpers.AccountName);

            accountRepos.ShouldNotBe(null);
            accountRepos.Any(p => p.name == privateRepo.name).ShouldBe(true);
            accountRepos.Any(p => p.is_private == true).ShouldBe(true);
            accountRepos.Any(p => p.is_private == false && p.name == publicRepo.name).ShouldBe(true);

            sharpBucket.NoAuthentication();
            accountRepos = repositoriesEndPoint.ListRepositories(TestHelpers.AccountName);
            accountRepos.ShouldNotBe(null);
            accountRepos.Any(p => p.name == privateRepo.name).ShouldBe(false);
            accountRepos.Any(p => p.is_private == true).ShouldBe(false);
            accountRepos.Any(p => p.is_private == false && p.name == publicRepo.name).ShouldBe(true);
        }
Пример #7
0
        private void PullRequest(ref Repositorios_VM repositorio, ref List <PullProjeto> ListPull, string tipo, Projeto objprojeto)
        {
            Repositorio codRepositorio;

            Repositorio objeto_repositorio;

            objeto_repositorio = objprojeto.Repositorio.Where(x => x.Tipo.Nome == tipo).SingleOrDefault();

            var sharpBucket = new SharpBucketV2();

            sharpBucket.OAuth2ClientCredentials(ConfigurationManager.AppSettings["consumerKey"], ConfigurationManager.AppSettings["consumerSecretKey"]);
            codRepositorio = objprojeto.Repositorio.Where(x => x.Tipo.Nome == tipo).SingleOrDefault();

            if (tipo == "APP")
            {
                repositorio.VersaoAPP = (sharpBucket.RepositoriesEndPoint().TagResource(codUserAPI, codRepositorio.Codigo).ListTags().OrderByDescending(x => x.date).Select(x => x.name).FirstOrDefault() ?? repositorio.VersaoAPP);
            }
            else
            {
                repositorio.VersaoAPI = (sharpBucket.RepositoriesEndPoint().TagResource(codUserAPI, codRepositorio.Codigo).ListTags().OrderByDescending(x => x.date).Select(x => x.name).FirstOrDefault() ?? repositorio.VersaoAPI);
            }

            ListParameters parameters = new ListParameters
            {
                Filter = $"destination.branch.name = \"master\"",
                Sort   = "-updated_on",
                Max    = 1
            };

            var pullRequest = sharpBucket.RepositoriesEndPoint().PullRequestsResource(codUserAPI, objeto_repositorio.Codigo).ListPullRequests(parameters).FirstOrDefault();


            if (pullRequest != null && !string.IsNullOrEmpty(pullRequest.title))
            {
                ListPull.Add(new PullProjeto(pullRequest.title, pullRequest.created_on));
            }
        }
Пример #8
0
        public RepositoriesEndPoint Authenticate(string clientId, string secret)
        {
            _sharpBucketV2.OAuth2ClientCredentials(clientId, secret);

            return(_sharpBucketV2.RepositoriesEndPoint());
        }