Groovy parameterized scripting and rest calls to them

Hello!
I’ve a couple questions to discuss and might be find any solution for them.

Our use case:
We have a service that have resource-role model. In other words:

  1. Resource - it’s some set of permission.
    2 )Role - contains some users.
    Then resource associating with role and all users within that role will have permission.

The whole process communicating with Domain and in fact it’s just a compilation of local security groups with global domain groups.

As far as I know and saw in Nexus OSS documentation Nexus have some kind of problems to scan large domains (in our case domain is very huge). So the first question is - do you plan to improve domain search in nearest future? Because for now my process looks like this in example of docker:
1)Create Content-Selector for private namespace
2)Assign privileges for that CS
3)Create new role with those privileges
4)associate this role with user

And when I’m trying to search this user in domain it takes a couple of retries to find him. Today it was 13-15 retries until I finaly can found him and associate role with user. This was the first pain…

Second and more interesting question:
At the moment nexus doesn’t provide any REST-Methods to create, rule, map or do anything with ldap, users and so on. Do you plan to improve your API in the nearest future in that way? Because it will be realy cool to rule this sort of things via API.

Third question: is there a some way to “make friendship” between Nexus and our Service with resource-role model?

I see the next one:
1)Write some groovy-script. Let’s take a very simple example of creating a new hosted repository. So the script will be look something like this:

import org.sonatype.nexus.repository.Repository;

repository.createNugetHosted("nuget-test", "blob-nuget");

2)Next step is to upload this script to Nexus. Fancy part in documentation in REST-API call where I need to fill this as a json and put content of the script in “content” section. It have nothing wrong with simple scripts like “Hello World!” but even with this situation I must write something like this:

{
"name" : "repository",
"content" : "import org.sonatype.nexus.*;\nimport org.sonatype.nexus.repository.Repository\n;repository.createNugetHosted(\"nuget-test\", \"kontur-nuget\");",
"type" : "groovy" 
}

As you can see it not very convenient way in my opinion, because if it will be a little more complex scripts (for example about 30-50 rows) it becomes realy painful to convert them like that.
3) Can I write and upload some parameterized script inside Nexus and “push” it’s parameters to script via REST-Call?
Let’s take a look at our simple example again(I’m very new at Groovy so it might just be my misunderstanding of process itself):

import org.sonatype.nexus.repository.Repository;

repository.createNugetHosted("nuget-test", "blob-nuget");

So can I somehow pass name of repository (nuget-test) and blob-store (blob-nuget) as a parameter via REST-call?
If not than it’s very hard to talk about some hardcoded automation and it’s much more esear to do it manualy.

Thanks.

Parameters can be passed in via a JSON file in the POST request:

params.json:

{  "repoName":"snapshots",
"groupId":"org.some.project",
"artifactId":"someartifact"
}

Then the command would be similar to the following:

curl -k -u user:pass -X POST --header 'Content-Type: text/plain' http://localhost:8081/service/rest/v1/script/rebuild-maven-metadata/run -d @params.json

And you can access the parameters in your script code:

def request = new JsonSlurper().parseText(args);
assert request.repoName: 'repoName parameter is required';
assert request.groupId: 'groupId parameter is required';
assert request.artifactId: 'artifactId parameter is required';
1 Like

Thank you!
I tried it today in a simple creating repository command and it works :slight_smile: