Mir S Mehdi
Mir S Mehdi

Reputation: 1530

Artifactory Restrict upload to repository, allow copy from another repo

How do I restrict users from manually deploying anything into a repository, at the same time allow them to copy from an another repository.

RepoA/Dir/File.txt  
RepoB/Dir

I would like to allow the copy of File.txt from RepoA to RepoB, this requires Deploy permissions to the RepoB. However, I would also like to restrict the manual deploy to RepoB. Anything coming into RepoB should be only from RepoA.

I tried this with the User Plugin with beforeCreate module, this restricts the Manual upload, however, this restricts the Copy function as well.

storage{ 
  beforeCreate { item ->
    log.debug("ENTER storage -> beforeCreate")
    if (item.getRepoKey().equals("RepoB")) {
    throw new CancelException("Artifact create not permitted", 403)
    }
    log.debug("EXIT storage -> beforeCreate")
}  }

Upvotes: 0

Views: 231

Answers (1)

JBaruch
JBaruch

Reputation: 22893

If you want to allow copy, just add a check that verifies that the same path (artifact) exists in RepoA. If it does - allow:

storage { 
  beforeCreate { item ->
        log.debug("ENTER storage -> beforeCreate")
        if (item.getRepoKey().equals("RepoB") &&
            !repositories.exist(RepoPathFactory.create('RepoA', item.repoPath)) {
            throw new CancelException("Artifact create not permitted", 403)
        }
        log.debug("EXIT storage -> beforeCreate")
    }  
}

Upvotes: 2

Related Questions