Groovy parameterized scripting and rest calls to them

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

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.

1 Like

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:

Hi

I am wondering if there is any reason that header Content-Type could not be set to “application/json”?

This is causing some issues where the most REST works with Content-Type", "application/json to send JSON in header and Nexus does not.

Regards,
Areg

Hi!

There is an build in function to create a cleanup policy like the repository creation?

Where should we put this script code?

Can you explain it step by step?
I’m new to nexus and groovy scripts