add an nexus api example snippet to check for a component existence

This commit is contained in:
Rui Lopes 2017-11-01 14:39:01 +00:00
parent c12829cd83
commit e7ddf7a981
2 changed files with 57 additions and 2 deletions

View File

@ -13,7 +13,7 @@ This will:
* Setup an Active Directory LDAP user authentication source (when `config_authentication='ldap'` is set inside the `provision-nexus.sh` file). * Setup an Active Directory LDAP user authentication source (when `config_authentication='ldap'` is set inside the `provision-nexus.sh` file).
* For more details look inside the [provision/provision-nexus](provision/provision-nexus) directory. * For more details look inside the [provision/provision-nexus](provision/provision-nexus) directory.
* Setup nginx as a Nexus HTTPS proxy and static file server. * Setup nginx as a Nexus HTTPS proxy and static file server.
* Test the installed repositories by [using and publishing to them](provision/test.sh). * Test the installed repositories by using and publishing to them (see the `use-*` files).
**NB** If you are new to Groovy, be sure to check the [Groovy Learn X in Y minutes page](https://learnxinyminutes.com/docs/groovy/). **NB** If you are new to Groovy, be sure to check the [Groovy Learn X in Y minutes page](https://learnxinyminutes.com/docs/groovy/).
@ -44,6 +44,58 @@ one of the example accounts, e.g. `alice.doe` and password `password`).
**NB** nginx is setup with a self-signed certificate that you have to trust before being **NB** nginx is setup with a self-signed certificate that you have to trust before being
able to access the local Nexus home page. able to access the local Nexus home page.
# Notes
## Check for a component existence
With bash, [HTTPie](https://httpie.org/) and [jq](https://stedolan.github.io/jq/):
```bash
function nexus-component-exists {
[ \
"$(
http \
get \
https://nexus.example.com/service/siesta/rest/beta/search \
"repository==$1" \
"name==$2" \
"version==$3" \
| jq -r .items[].name)" == "$2" \
]
}
if nexus-component-exists npm-hosted hello-world 1.0.0; then
echo 'component exists'
else
echo 'component does not exists'
fi
```
With PowerShell:
```powershell
function Test-NexusComponent {
param(
[string]$repository,
[string]$name,
[string]$version)
$items = (Invoke-RestMethod `
-Method Get `
-Uri https://nexus.example.com/service/siesta/rest/beta/search `
-Body @{
repository = $repository
name = $name
version = $version
}).items
$items.Count -and ($items.name -eq $name)
}
if (Test-NexusComponent npm-hosted hello-world 1.0.0) {
Write-Host 'component exists'
} else {
Write-Host 'component does not exists'
}
```
# Troubleshooting # Troubleshooting

View File

@ -7,11 +7,14 @@ config_fqdn=$(hostname --fqdn)
cat <<EOF cat <<EOF
nexus is running at: nexus is running at:
http://localhost:8081
https://$config_fqdn https://$config_fqdn
use the admin/admin123 credentials to login. use the admin/admin123 credentials to login.
the api browser at:
https://$config_fqdn/swagger-ui/
the logs are at: the logs are at:
/opt/nexus/nexus3/log/ /opt/nexus/nexus3/log/