blob: 5691fe64ed3b50c0f7c5e4930c45c78cb5001bca [file] [log] [blame]
Michal Zegan3a7e0732018-12-19 11:51:26 +01001import org.sonatype.nexus.security.realm.RealmManager
2import org.sonatype.nexus.repository.attributes.AttributesFacet
3import org.sonatype.nexus.security.user.UserManager
4import org.sonatype.nexus.repository.manager.RepositoryManager
5import org.sonatype.nexus.security.user.UserNotFoundException
6
7/* Use the container to look up some services. */
8realmManager = container.lookup(RealmManager.class)
9userManager = container.lookup(UserManager.class, "default") //default user manager
10repositoryManager = 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. */
14userManager.listUserIds().each({ id ->
15 if (id != "anonymous" && id != "admin")
16 userManager.deleteUser(id)
17})
18
19repositoryManager.browse().each {
20 repositoryManager.delete(it.getName())
21}
22
23/* Add bearer token realms at the end of realm lists... */
24realmManager.enableRealm("NpmToken")
25realmManager.enableRealm("DockerToken")
26
27/* Create the docker user. */
28security.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. */
31repository.createNpmHosted("npm-private")
32def r = repository.createDockerHosted("docker", 8082, 0)
33
34/* force basic authentication true by default, must set to false for docker repo. */
35conf=r.getConfiguration()
36conf.attributes("docker").set("forceBasicAuth", false)
37repositoryManager.update(conf)