Hello all,
I’ve been able to create, using the Nexus groovy scripts (documented in Nexus 3 Groovy Script development environment setup – Sonatype Support), some repos, roles, users and blobstores.
Now I’m trying to add routing-rules.
It’s pretty easy to create one; such code evaluated fine from Groovy:
RoutingRule routingRule = new RoutingRule("com.company only API", "only com.company content", RoutingMode.BLOCK, ["^(?!/com/company)/.*\$"])
The part I could not figure out was how to persist this rule and attach it to an existing repository.
I thought it could have been as easy as adding configuration to an existing repository, something like:
Configuration mavenPublicConfiguration = repository.getRepositoryManager().get("maven-public").getConfiguration()["routing-rule"]= new RoutingRule()
But no, the closest thing I found was Configuration.setRoutingRuleId(EntityId id)
and unfortunately, getting this id does not seem to be straightforward.
I could have @Inject
ed services to my groovy code, but it felt like I was going too far…
The Rest API seems to have a resource for routing-rules(RoutingRulesApiResource) , but there does not seem to be an API to attach the routing rule to an existing repo.
Nexus community, is there a way to add and attach a routing rule to an existing repo via scripting or Rest API ?
Thank you!