• Kassio Borges's avatar
    Add `/projects/remote-import-s3` API endpoint to import from AWS S3 · 920812c9
    Kassio Borges authored
    Related to: https://gitlab.com/gitlab-org/gitlab/-/issues/348874
    
    Instead of using inheritance to share code among the project creation
    classes, I refactor it to use composition. This away the code is a bit
    more extensible and has more independent parts (less coupling).
    
    `Import::GitlabProjects::CreateProjectFromRemoteFileService` and
    `Import::GitlabProjects::CreateProjectFromUploadedFileService` was
    replaced by a single entry point
    `Import::GitlabProjects::CreateProjectService`.
    
    `Import::GitlabProjects::CreateProjectService` is responsible to create
    a project when the user parameters are valid. Since the user can use
    different strategies to create/import a project, the requirements for
    each strategy is implemented in different
    `Import::GitlabProjects::Strategies::*` classes, this way the strategy
    can be changed by dependency injection.
    
    A `Import::GitlabProjects::Strategies::*` class must implement:
    - initialize(current_user:, params:)
    - valid? - validate the user parameters
    - errors - when invalid, a ActiveModel::Errors object
    - project_params - A hash with the specific strategy extra parameters to
      create the project
    
    Also, because importing from a generic object storage and from AWS S3
    have similar validations to be performed, the
    `Import::GitlabProjects::Strategies::RemoteFileValidator` was created to
    validate the remote file `content_length` and `content_type`.
    
    MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77259
    920812c9
project_import_spec.rb 15.7 KB