Beispiel #1
0
        /// <summary>
        /// Returns the state for a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <returns>Returns the project state for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public ProjectState GetProjectState(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectState", UserKey, projectToken: projectToken);
            var response = request.MakeRequest <ProjectStateResponse>(this);

            return(response.Data.ProjectState);
        }
Beispiel #2
0
        /// <summary>
        /// Returns the source files for a library within a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <param name="uuid">The UUID for the library to retrieve source files for.</param>
        /// <returns>Returns the source files for a library within the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public List <SourceFile> GetLibrarySourceFiles(ProjectToken projectToken, string uuid)
        {
            var request  = new ProjectUuidRequest("getLibrarySourceFiles", UserKey, projectToken, uuid);
            var response = request.MakeRequest <SourceFilesResponse>(this);

            return(response.Data.SourceFiles);
        }
Beispiel #3
0
        /// <summary>
        /// Returns the library inventory for a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <param name="includeInHouseData">An optional parameter to determine whether in-house data should be included
        /// in the hierarchy. The default is <c>true</c> which means to include the in-house data.</param>
        /// <returns>Returns the library inventory for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public ProjectInventory GetProjectInventory(ProjectToken projectToken, bool includeInHouseData = true)
        {
            var request  = new InventoryRequest("getProjectInventory", UserKey, projectToken, includeInHouseData);
            var response = request.MakeRequest <ProjectInventoryResponse>(this);

            return(new ProjectInventory(response.Data));
        }
Beispiel #4
0
        /// <summary>
        /// Returns a list of library locations for a given project.
        /// </summary>
        /// <param name="projectToken">The Whitesource project token for the target project.</param>
        /// <returns>Returns a list of library locations for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public List <LibraryLocation> GetProjectLibraryLocations(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectLibraryLocations", UserKey, projectToken: projectToken);
            var response = request.MakeRequest <LibraryLocationsResponse>(this);

            return(response.Data.LibraryLocations);
        }
Beispiel #5
0
        /// <summary>
        /// Get basic information for a specific project: name, token, creation date and last updated date.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <returns>Returns the vitals within the organization for all products.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public List <Vitals> GetProjectVitals(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectVitals", UserKey, projectToken: projectToken);
            var response = request.MakeRequest <ProjectVitalsResponse>(this);

            return(response.Data.ProjectVitals);
        }
Beispiel #6
0
        /// <summary>
        /// Returns a list of alerts for a given project.
        /// </summary>
        /// <param name="projectToken">The Whitesource project token for the target project.</param>
        /// <returns>Returns a list of alerts for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public List <Alert> GetProjectAlerts(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectAlerts", UserKey, projectToken: projectToken);
            var response = request.MakeRequest <AlertsResponse>(this);

            return(response.Data.Alerts);
        }
        public void mark_as_last_accessed_when_the_project_is_not_the_most_recent_project()
        {
            var token = new ProjectToken
            {
                Filename = "project4.xml",
                Name = "project4"
            };


            var history = new ProjectHistory();
            history.Store(new ProjectToken
            {
                Filename = "project1.xml",
                Name = "project1"
            });
            history.Store(new ProjectToken
            {
                Filename = "project2.xml",
                Name = "project2"
            });
            history.Store(new ProjectToken
            {
                Filename = "project3.xml",
                Name = "project3"
            });

            history.Store(token);


            history.MarkAsLastAccessed(token);

            history.LastAccessed.ShouldBeTheSameAs(token);

            history.Projects.Length.ShouldEqual(4);
        }
        /// <summary>
        /// Returns the source files for a library within a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <param name="uuid">The UUID for the library to retrieve source files for.</param>
        /// <returns>Returns the source files for a library within the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <List <SourceFile> > GetLibrarySourceFilesAsync(ProjectToken projectToken, string uuid)
        {
            var request  = new ProjectUuidRequest("getLibrarySourceFiles", UserKey, projectToken, uuid);
            var response = await request.MakeRequestAsync <SourceFilesResponse>(this);

            return(response.Data.SourceFiles);
        }
Beispiel #9
0
        public async Task <IActionResult> GetProjectToken(int id)
        {
            var project = await service.GetAsync(id);

            if (project == null || project.WorkflowProjectUrl == null)
            {
                return(NotFound());
            }

            var token = await BuildEngineProjectService.GetProjectTokenAsync(id);

            if (token == null || token.SecretAccessKey == null)
            {
                return(NotFound());
            }
            var projectToken = new ProjectToken
            {
                Id              = id,
                SessionToken    = token.SessionToken,
                SecretAccessKey = token.SecretAccessKey,
                AccessKeyId     = token.AccessKeyId,
                Expiration      = token.Expiration,
                Url             = project.WorkflowProjectUrl,
                Region          = token.Region
            };

            return(Ok(projectToken));
        }
        /// <summary>
        /// Returns the library inventory for a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <param name="includeInHouseData">An optional parameter to determine whether in-house data should be included
        /// in the hierarchy. The default is <c>true</c> which means to include the in-house data.</param>
        /// <returns>Returns the library inventory for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <ProjectInventory> GetProjectInventoryAsync(ProjectToken projectToken, bool includeInHouseData = true)
        {
            var request  = new InventoryRequest("getProjectInventory", UserKey, projectToken, includeInHouseData);
            var response = await request.MakeRequestAsync <ProjectInventoryResponse>(this);

            return(new ProjectInventory(response.Data));
        }
        /// <summary>
        /// Returns the state for a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <returns>Returns the project state for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <ProjectState> GetProjectStateAsync(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectState", UserKey, projectToken: projectToken);
            var response = await request.MakeRequestAsync <ProjectStateResponse>(this);

            return(response.Data.ProjectState);
        }
        /// <summary>
        /// Returns a list of library locations for a given project.
        /// </summary>
        /// <param name="projectToken">The Whitesource project token for the target project.</param>
        /// <returns>Returns a list of library locations for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <List <LibraryLocation> > GetProjectLibraryLocationsAsync(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectLibraryLocations", UserKey, projectToken: projectToken);
            var response = await request.MakeRequestAsync <LibraryLocationsResponse>(this);

            return(response.Data.LibraryLocations);
        }
        /// <summary>
        /// Returns the library hierarchy for a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <param name="includeInHouseData">An optional parameter to determine whether in-house data should be included
        /// in the hierarchy. The default is <c>true</c> which means to include the in-house data.</param>
        /// <returns>Returns a the library hierarchy for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <List <Library> > GetProjectHierarchyAsync(ProjectToken projectToken, bool includeInHouseData = true)
        {
            var request  = new InventoryRequest("getProjectHierarchy", UserKey, projectToken, includeInHouseData);
            var response = await request.MakeRequestAsync <LibrariesResponse>(this);

            return(response.Data.Libraries);
        }
        /// <summary>
        /// Returns a list of alerts for a given project with the specified type.
        /// </summary>
        /// <param name="projectToken">The Whitesource project token for the target project.</param>
        /// <param name="alertType">The alert type to use to filter the alerts.</param>
        /// <param name="fromDate">An optional parameter that filters alerts after this date.</param>
        /// <param name="toDate">An optional parameter that filters alerts before this date.</param>
        /// <returns>Returns a list of alerts for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <List <Alert> > GetProjectAlertsByTypeAsync(ProjectToken projectToken, string alertType, DateTime?fromDate = null, DateTime?toDate = null)
        {
            var request  = new AlertTypeRequest("getProjectAlertsByType", UserKey, projectToken: projectToken, alertType: alertType, fromDate: fromDate, toDate: toDate);
            var response = await request.MakeRequestAsync <AlertsResponse>(this);

            return(response.Data.Alerts);
        }
        /// <summary>
        /// Get basic information for a specific project: name, token, creation date and last updated date.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <returns>Returns the vitals within the organization for all products.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <List <Vitals> > GetProjectVitalsAsync(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectVitals", UserKey, projectToken: projectToken);
            var response = await request.MakeRequestAsync <ProjectVitalsResponse>(this);

            return(response.Data.ProjectVitals);
        }
Beispiel #16
0
        /// <summary>
        /// Returns a dictionary of licenses and counts for a given project.
        /// </summary>
        /// <param name="projectToken">The Whitesource project token for the target project.</param>
        /// <returns>Returns a dictionary of licenses and counts for a given project.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public Dictionary <string, int> GetProjectLicenseHistogram(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectLicenseHistogram", UserKey, projectToken: projectToken);
            var response = request.MakeRequest <LicensesHistogramResponse>(this);

            return(response.Data.LicenseHistogram);
        }
        protected override void beforeEach()
        {
            Services.PartialMockTheClassUnderTest();
            tokens = new ProjectToken[0];

            MockFor <IProjectHistory>().Expect(x => x.Projects).Return(tokens);

            var projectToken1 = new ProjectToken
            {
                Filename = theProjectName
            };
            var projectToken2 = new ProjectToken
            {
                Filename = theProjectName,
                Name     = "foo"
            };


            MockFor <IProjectHistory>().Expect(x => x.LastAccessed).Return(projectToken1);
            MockFor <IProjectHistory>().Expect(x => x.Next(projectToken1)).Return(projectToken2);

            ClassUnderTest.Expect(x => x.LoadProject(projectToken1)).Return(false);
            ClassUnderTest.Expect(x => x.LoadProject(projectToken2)).Return(true);

            ClassUnderTest.Start();
        }
        /// <summary>
        /// Returns the dependencies for a library within a given project.
        /// </summary>
        /// <param name="projectToken">The project token.</param>
        /// <param name="uuid">The UUID for the library to retrieve the dependencies for.</param>
        /// <returns>Returns the source files for a library within the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <List <Dependency> > GetProjectLibraryDependenciesAsync(ProjectToken projectToken, string uuid)
        {
            var request  = new ProjectUuidRequest("getProjectLibraryDependencies", UserKey, projectToken, uuid);
            var response = await request.MakeRequestAsync <DependenciesResponse>(this);

            return(response.Data.Dependencies);
        }
        /// <summary>
        /// Returns a list of alerts for a given project.
        /// </summary>
        /// <param name="projectToken">The Whitesource project token for the target project.</param>
        /// <returns>Returns a list of alerts for the given project token.</returns>
        /// <exception cref="WhitesourceRequestException">Thrown if an exception occurs calling Whitesource service.</exception>
        public async Task <List <Alert> > GetProjectAlertsAsync(ProjectToken projectToken)
        {
            var request  = new BaseRequest("getProjectAlerts", UserKey, projectToken: projectToken);
            var response = await request.MakeRequestAsync <AlertsResponse>(this);

            return(response.Data.Alerts);
        }
        public void mark_as_last_accessed_when_the_project_is_already_the_most_recent_project()
        {
            var token = new ProjectToken
            {
                Filename = "project4.xml",
                Name = "project4"
            };


            var history = new ProjectHistory();
            history.Store(token);
            history.Store(new ProjectToken
            {
                Filename = "project1.xml",
                Name = "project1"
            });
            history.Store(new ProjectToken
            {
                Filename = "project2.xml",
                Name = "project2"
            });
            history.Store(new ProjectToken
            {
                Filename = "project3.xml",
                Name = "project3"
            });


            history.MarkAsLastAccessed(token);
        }
Beispiel #21
0
        public async Task <IActionResult> GetProjectToken(int id)
        {
            var project = await service.GetAsync(id);

            if (project == null)
            {
                return(NotFound($"Project id={id} not found"));
            }

            if (project.WorkflowProjectUrl == null)
            {
                return(NotFound($"Project id={id}: WorkflowProjectUrl is null"));
            }

            var roles = await ProjectService.GetUserRolesForProject(project, CurrentUser.Id);

            bool readOnly;

            if (CurrentUser.Id == project.OwnerId)
            {
                readOnly = false;
            }
            else if (roles != null && roles.Exists(role => role.RoleName == RoleName.OrganizationAdmin))
            {
                readOnly = true;
            }
            else if (CurrentUser.HasRole(RoleName.SuperAdmin))
            {
                readOnly = true;
            }
            else
            {
                return(NotFound($"Project id={id}, user={CurrentUser.Name} does not have permission"));
            }

            var token = await BuildEngineProjectService.GetProjectTokenAsync(id, readOnly);

            if (token == null)
            {
                return(NotFound($"Project id={id}: GetProjectToken returned null"));
            }
            if (token.SecretAccessKey == null)
            {
                return(NotFound($"Project id={id}: Token.SecretAccessKey is null"));
            }
            var projectToken = new ProjectToken
            {
                Id              = id,
                SessionToken    = token.SessionToken,
                SecretAccessKey = token.SecretAccessKey,
                AccessKeyId     = token.AccessKeyId,
                Expiration      = token.Expiration,
                Url             = project.WorkflowProjectUrl,
                Region          = token.Region,
                ReadOnly        = token.ReadOnly
            };

            return(Ok(projectToken));
        }
 protected override void beforeEach()
 {
     _projectToken = new ProjectToken
     {
         Filename = "somefilename",
         Name     = "somename"
     };
 }
 public InventoryRequest(
     string requestType,
     string userKey,
     ProjectToken projectToken = null,
     bool includeInHouseData   = true)
     : base(requestType, userKey, null, null, projectToken)
 {
     IncludeInHouseData = includeInHouseData;
 }
 public ProjectUuidRequest(
     string requestType,
     string userKey,
     ProjectToken projectToken,
     string keyUuid)
     : base(requestType, userKey, null, null, projectToken)
 {
     KeyUuid = keyUuid;
 }
        public void marks_the_project_history()
        {
            var theProjectTokenThatShouldBeMarked = new ProjectToken
            {
                Filename = _theFileName,
                Name     = _theProjectName
            };

            MockFor <IProjectHistory>().AssertWasCalled(x => x.MarkAsLastAccessed(theProjectTokenThatShouldBeMarked));
        }
Beispiel #26
0
 public BaseRequest(
     string requestType,
     string userKey,
     OrgToken orgToken         = null,
     ProductToken productToken = null,
     ProjectToken projectToken = null)
 {
     RequestType  = requestType ?? throw new ArgumentNullException(nameof(requestType));
     UserKey      = userKey;
     OrgToken     = orgToken;
     ProductToken = productToken;
     ProjectToken = projectToken;
 }
        protected override void beforeEach()
        {
            _token = new ProjectToken {
                Filename = "some file name",
                Name     = "some name"
            };

            message = new RemoveProjectFromHistoryMessage()
            {
                ProjectToken = _token
            };
            ClassUnderTest.Handle(message);
        }
        public ServiceIntegrationTests()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile("appsettings.test.json", optional: true, reloadOnChange: true);
            var configuration = builder.Build();

            OrgToken     = new OrgToken(configuration.GetSection("whitesource:orgToken").Value);
            ProductToken = new ProductToken(configuration.GetSection("whitesource:productToken").Value);
            ProjectToken = new ProjectToken(configuration.GetSection("whitesource:projectToken").Value);
            LibraryUuid  = configuration.GetSection("whitesource:libraryUuid").Value;
            service      = new WhitesourceService(configuration.GetSection("whitesource:userKey").Value, configuration.GetSection("whitesource:url").Value);
        }
        protected override void beforeEach()
        {
            MockFor <IProjectPersistor>().Expect(x => x.LoadFromFile(_theFileName)).Return(null);
            _projectToken = new ProjectToken
            {
                Filename = _theFileName
            };

            _projectLoadFailureMessage = new ProjectLoadFailureMessage
            {
                ProjectToken = _projectToken
            };
            _output = ClassUnderTest.LoadProject(_projectToken);
        }
Beispiel #30
0
        public Project AddProject(ProjectToken token, Guid user)
        {
            var output = new Project();

            output.Name        = token.Name;
            output.Description = token.Description;
            output.CreatedAt   = DateTime.Now;
            output.ID          = Guid.NewGuid();
            output.OP          = user;

            Projects.Add(output);
            SaveChanges();

            return(output);
        }