Michal Zegan | 3a7e073 | 2018-12-19 11:51:26 +0100 | [diff] [blame] | 1 | import org.sonatype.nexus.security.realm.RealmManager |
| 2 | import org.sonatype.nexus.repository.attributes.AttributesFacet |
| 3 | import org.sonatype.nexus.security.user.UserManager |
| 4 | import org.sonatype.nexus.repository.manager.RepositoryManager |
| 5 | import org.sonatype.nexus.security.user.UserNotFoundException |
| 6 | |
| 7 | /* Use the container to look up some services. */ |
| 8 | realmManager = container.lookup(RealmManager.class) |
| 9 | userManager = container.lookup(UserManager.class, "default") //default user manager |
| 10 | repositoryManager = container.lookup(RepositoryManager.class) |
| 11 | |
| 12 | /* Managers are used when scripting api cannot. Note that scripting api can only create mostly, and that creation methods return objects of created entities. */ |
| 13 | /* Perform cleanup by removing all repos and users. Realms do not need to be re-disabled, admin and anonymous user will not be removed. */ |
| 14 | userManager.listUserIds().each({ id -> |
| 15 | if (id != "anonymous" && id != "admin") |
| 16 | userManager.deleteUser(id) |
| 17 | }) |
| 18 | |
| 19 | repositoryManager.browse().each { |
| 20 | repositoryManager.delete(it.getName()) |
| 21 | } |
| 22 | |
| 23 | /* Add bearer token realms at the end of realm lists... */ |
| 24 | realmManager.enableRealm("NpmToken") |
| 25 | realmManager.enableRealm("DockerToken") |
| 26 | |
| 27 | /* Create the docker user. */ |
| 28 | security.addUser("docker", "docker", "docker", "docker@example.com", true, "docker", ["nx-anonymous"]) |
| 29 | |
| 30 | /* Create npm and docker repositories. Their default configuration should be compliant with our requirements, except the docker registry creation. */ |
| 31 | repository.createNpmHosted("npm-private") |
| 32 | def r = repository.createDockerHosted("docker", 8082, 0) |
| 33 | |
| 34 | /* force basic authentication true by default, must set to false for docker repo. */ |
| 35 | conf=r.getConfiguration() |
| 36 | conf.attributes("docker").set("forceBasicAuth", false) |
| 37 | repositoryManager.update(conf) |