Example #1
0
        private static SharpBucketV2 GetV2ClientAuthenticatedWithOAuth2()
        {
            var sharpBucket = new SharpBucketV2();

            sharpBucket.OAuth2ClientCredentials(OAuthConsumerKey, OAuthConsumerSecretKey);
            return(sharpBucket);
        }
Example #2
0
        public static SharpBucketV2 GetV2ClientAuthenticatedWithOAuth1()
        {
            var sharpBucket = new SharpBucketV2();

            sharpBucket.OAuth1TwoLeggedAuthentication(OAuthConsumerKey, OAuthConsumerSecretKey);
            return(sharpBucket);
        }
Example #3
0
        /// <summary>
        /// Constructor for a user
        /// </summary>
        /// <param name="username">the username of the current user</param>
        /// <param name="password">the password of the current user</param>
        public User(string username, string password)
        {
            logged        = false;
            this.username = username;
            this.password = password;


            //Sharp bucket has two versions of API so we authenticate with both as well as our own RESTSHARP client
            v1Api = new SharpBucketV1();
            v1Api.BasicAuthentication(username, password);
            try
            {
                this.accountName = v1Api.UserEndPoint().GetInfo().user.username;
                logged           = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            v2Api = new SharpBucketV2();
            v2Api.BasicAuthentication(username, password);

            client = new RestClient("https://api.bitbucket.org/");
            client.Authenticator = new HttpBasicAuthenticator(username, password);
        }
        public void Init()
        {
            sharpBucket   = TestHelpers.SharpBucketV2;
            teamsEndPoint = sharpBucket.TeamsEndPoint();

            teamName     = teamsEndPoint.GetUserTeamsWithAdminRole()[0].username;
            teamResource = teamsEndPoint.TeamResource(teamName);
        }
        public void NoAuthentication_NotExplicitlyCalled_ShouldReadPublicRepos()
        {
            var sharpBucket = new SharpBucketV2();
            var ep          = sharpBucket.RepositoriesEndPoint();
            var repos       = ep.ListPublicRepositories(5);

            repos.Count.ShouldBe(5);
        }
        public void Client_WithNoAuth_ShouldReadPublicRepos()
        {
            var client = new SharpBucketV2();
            var ep     = client.RepositoriesEndPoint();
            var repos  = ep.ListPublicRepositories(5);

            repos.Count.ShouldBe(5);
        }
Example #7
0
 private static void TestUsersEndPoint(SharpBucketV2 sharpBucket)
 {
     var usersEndPoint = sharpBucket.UsersEndPoint(accountName);
     var profile       = usersEndPoint.GetProfile();
     var followers     = usersEndPoint.ListFollowers();
     var following     = usersEndPoint.ListFollowing();
     var repositories  = usersEndPoint.ListRepositories();
 }
Example #8
0
 private static void TestTeamsEndPoint(SharpBucketV2 sharpBucket)
 {
     var TEAM_NAME     = "";
     var teamsEndPoint = sharpBucket.TeamsEndPoint(TEAM_NAME);
     var teamProfile   = teamsEndPoint.GetProfile();
     var teamMembers   = teamsEndPoint.ListMembers();
     var teamFollowers = teamsEndPoint.ListFollowers();
     var teamFollowing = teamsEndPoint.ListFollowing();
 }
        public void Client_WithNoAuth_ShouldRetrieveTortoise()
        {
            var client = new SharpBucketV2();
            var ep     = client.RepositoriesEndPoint();
            var repo   = ep.RepositoryResource("tortoisehg", "thg").GetRepository();

            repo.ShouldNotBeNull();
            repo.full_name.ShouldBe("tortoisehg/thg");
        }
Example #10
0
        public static SharpBucketV2 GetV2ClientAuthenticatedWithOAuth2()
        {
            var consumerKey       = Environment.GetEnvironmentVariable(SbConsumerKey);
            var consumerSecretKey = Environment.GetEnvironmentVariable(SbConsumerSecretKey);
            var sharpbucket       = new SharpBucketV2();

            sharpbucket.OAuthentication2(consumerKey, consumerSecretKey);
            return(sharpbucket);
        }
Example #11
0
        public BitbucketAPIService(string username, string publicKey, string secretKey)
        {
            Username   = username;
            PublicKey  = publicKey;
            PrivateKey = secretKey;

            m_sharpBucket2 = new SharpBucketV2();
            m_sharpBucket2.OAuth2LeggedAuthentication(PublicKey, PrivateKey);
        }
Example #12
0
        private static void TestApiV2()
        {
            var sharpBucket = new SharpBucketV2();

            ReadTestDataOauth();
            sharpBucket.OAuth2LeggedAuthentication(consumerKey, consumerSecretKey);
            //TestUsersEndPoint(sharpBucket);
            //TestTeamsEndPoint(sharpBucket);
            TestRestRepositoriesEndPoint(sharpBucket);
        }
Example #13
0
        public TeamResource(SharpBucketV2 sharpBucketV2, string teamName)
        {
            _sharpBucketV2 = sharpBucketV2 ?? throw new ArgumentNullException(nameof(sharpBucketV2));

            if (string.IsNullOrEmpty(teamName))
            {
                throw new ArgumentNullException(nameof(teamName));
            }
            _teamName = teamName.GuidOrValue();
            _baseUrl  = $"teams/{teamName}/";
        }
Example #14
0
 public TeamsEndPoint(SharpBucketV2 sharpBucketV2, string teamName)
     : this(sharpBucketV2)
 {
     // initially when teamName was null there where no check in the constructor
     // which means that only the methods that need it will fails and methods that doesn't works
     // this test is here to reproduce that legacy behaviour until we delete the obsolete code
     if (!string.IsNullOrEmpty(teamName))
     {
         _teamResource = new TeamResource(sharpBucketV2, teamName);
     }
 }
Example #15
0
        internal BaseBitBucketIssueNumberMessageHandler(SharpBucketV2 bitBucketClient)
        {
            var client = bitBucketClient;

            client.OAuth2ClientCredentials(ConsumerKey, ConsumerSecretKey);

            var repositoriesEndPoint = client.RepositoriesEndPoint();
            var repositoryResource   = repositoriesEndPoint.RepositoryResource(RepositoryOwner, RepositoryName);

            _pullRequestsResource = repositoryResource.PullRequestsResource();
            _issuesResource       = repositoryResource.IssuesResource();
        }
Example #16
0
        public void BasicAuthentication_BasicAuthentication_AllowToListPrivateRepositories()
        {
            var privateRepo = SampleRepositories.PrivateTestRepository.GetRepository();

            var sharpBucket = new SharpBucketV2();

            sharpBucket.BasicAuthentication(TestHelpers.UserName, TestHelpers.Password);
            var accountRepos = sharpBucket.RepositoriesEndPoint().ListRepositories(TestHelpers.AccountName);

            accountRepos.ShouldNotBe(null);
            accountRepos.Any(p => p.is_private == true && p.name == privateRepo.name).ShouldBe(true);
        }
Example #17
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);
        }
Example #18
0
 public ProjectResource(SharpBucketV2 sharpBucketV2, string teamName, string projectKey)
 {
     this.SharpBucketV2 = sharpBucketV2 ?? throw new ArgumentNullException(nameof(sharpBucketV2));
     if (string.IsNullOrEmpty(teamName))
     {
         throw new ArgumentNullException(nameof(teamName));
     }
     if (string.IsNullOrEmpty(projectKey))
     {
         throw new ArgumentNullException(nameof(projectKey));
     }
     this.ProjectKey = projectKey.GuidOrValue();
     this.ProjectUrl = $"teams/{teamName.GuidOrValue()}/projects/{this.ProjectKey}";
 }
Example #19
0
        public static SharpBucketV2 GetV2ClientAuthenticatedWithBasicAuthentication()
        {
            var sharpbucket = new SharpBucketV2();
            // Reads test data information from a file, you should structure it like this:
            // By default it reads from c:\
            // Username:yourUsername
            // Password:yourPassword
            // AccountName:yourAccountName
            // Repository:testRepository
            var lines    = File.ReadAllLines(TestInformationPath);
            var email    = lines[0].Split(':')[1];
            var password = lines[1].Split(':')[1];

            sharpbucket.BasicAuthentication(email, password);
            return(sharpbucket);
        }
        public void MockAuthentication_ShouldUseMock()
        {
            string expected = "Hello from mock";

            _client.Setup(c => c.Execute(It.IsAny <IRestRequest>()))
            .Returns(new RestResponse()
            {
                ResponseStatus = ResponseStatus.Completed,
                StatusCode     = System.Net.HttpStatusCode.OK,
                Content        = expected,
            });

            var client = new SharpBucketV2();

            client.MockAuthentication(_client.Object);
            var output = client.Get(null);

            output.ShouldBe(expected);
        }
        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);
        }
Example #22
0
        /// <summary>
        /// Create or update a project at this resource location.
        /// https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams/%7Busername%7D/projects/%7Bproject_key%7D
        /// </summary>
        /// <param name="project">The project object to create or update</param>
        public Project PutProject(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            // create an instance that contains only the fields accepted in the PUT operation
            var updateableFields = new Project
            {
                name        = project.name,
                description = project.description,
                is_private  = project.is_private
            };

            // include the key field only if needed, which should be only when the intent is to change the key itself.
            if (project.key != null && !project.key.Equals(this.ProjectKey, StringComparison.Ordinal))
            {
                updateableFields.key = project.key;
            }

            return(SharpBucketV2.Put(updateableFields, ProjectUrl));
        }
        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);
        }
        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);
        }
Example #25
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));
            }
        }
 public void Init()
 {
     sharpBucket   = TestHelpers.SharpBucketV2;
     teamsEndPoint = sharpBucket.TeamsEndPoint();
 }
Example #27
0
 public UsersEndpoint(string accountName, SharpBucketV2 sharpBucketV2)
     : base(sharpBucketV2, "users/" + accountName + "/")
 {
     _repositoriesUrl = "repositories/" + accountName + "/";
 }
 public void Init()
 {
     sharpBucket   = TestHelpers.SharpBucketV2;
     usersEndPoint = sharpBucket.UsersEndPoint(SampleRepositories.MERCURIAL_ACCOUNT_UUID);
 }
 public RepositoriesEndPoint(SharpBucketV2 sharpBucketV2)
     : base(sharpBucketV2, "repositories/")
 {
 }
 public RepositoriesEndPoint(SharpBucketV2 sharpBucketV2)
     : base(sharpBucketV2, "repositories/")
 {
 }
Example #31
0
 public void Init()
 {
     sharpBucket  = TestHelpers.GetV2ClientAuthenticatedWithOAuth();
     userEndPoint = sharpBucket.UserEndPoint();
 }
Example #32
0
 public UserEndpoint(SharpBucketV2 sharpBucketV2)
     : base(sharpBucketV2, "user/")
 {
 }
Example #33
0
 public TeamsEndPoint(SharpBucketV2 sharpBucketV2, string teamName)
     : base(sharpBucketV2, "teams/" + teamName + "/")
 {
 }
 public RepositoriesEndPoint(SharpBucketV2 sharpBucketV2)
 {
     _sharpBucketV2 = sharpBucketV2;
     _baseUrl = "repositories/";
 }
 public TeamsEndPoint(SharpBucketV2 sharpBucketV2, string teamName)
 {
     _sharpBucketV2 = sharpBucketV2;
     _baseUrl = "teams/" + teamName + "/";
 }
 public UsersEndpoint(string accountName, SharpBucketV2 sharpBucketV2)
 {
     _sharpBucketV2 = sharpBucketV2;
     _baseUrl = "users/" + accountName + "/";
     _repositoriesUrl = "repositories/" + accountName + "/";
 }