# Create role with specific selection on the name

**URL:** <https://community.sonatype.com/t/create-role-with-specific-selection-on-the-name/11029>\
**Category:** Sonatype Nexus Repository\
**Tags:** privileges, roles\
**Created:** [July 26, 2023, 1:22pm UTC](https://community.sonatype.com/t/create-role-with-specific-selection-on-the-name/11029 "2023-07-26T13:22:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michel13](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@michel13](https://community.sonatype.com/u/michel13)\
**Post date:** [July 26, 2023, 1:22pm UTC](https://community.sonatype.com/t/create-role-with-specific-selection-on-the-name/11029/1 "2023-07-26T13:22:14Z")

</div>

Hi, I want to autorize some users to access (read only) to all repositories ending by “-public”, I have more than 100 repositories and I continue to create new repository.  
If it’s not possible , is it possible to filter for all “released” repositories ?

How can I create this role (and ay be I have to create a specific privilege)…  
Thx  
Michel

---

<div class="post-metadata">

**Author:** ![mpiggott](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mpiggott](https://community.sonatype.com/u/mpiggott)\
**Post date:** [July 31, 2023, 5:44pm UTC](https://community.sonatype.com/t/create-role-with-specific-selection-on-the-name/11029/2 "2023-07-31T17:44:40Z")

</div>

I don’t believe you can do this in Nexus. You could use the public REST APIs to retrieve the list of repositories, filter the names yourself and then use the REST API to update the role to include all appropriate repositories.

---

<div class="post-metadata">

**Author:** ![michel13](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@michel13](https://community.sonatype.com/u/michel13)\
**Post date:** [November 22, 2023, 3:29pm UTC](https://community.sonatype.com/t/create-role-with-specific-selection-on-the-name/11029/3 "2023-11-22T15:29:12Z")

</div>

I did it !  
I created a role like this

```auto
# pour gérer tous les privilèges de type "maven2" et "repository-view"
data "nexus_privileges" "priv_pub_read" {
  format = "maven2"
  type = "repository-view"
  depends_on = [module.repository]
}

# affiche les privilèges public-browse et public-read
# debug
#output "privileges_all_read" {
# value = local.privileges_all_read
#}

# variable pour stocker les privilieges nommés "*public-browse" et "*public-read"
locals {
  privileges_all_read = [for x in data.nexus_privileges.priv_pub_read.privileges: 
  x.name if can(regex("public-browse|public-read", x.name))
  ]
}

# il faut au prealable faire un import de tous les groupeAD deja migres avec la commande 
# indus-all-acces-pub-read à boucler par script avant de lancer la 1ere fois
# creation/modification du role indus-all-acces-pub-read avec tous les privilèges "*public-browse" et "*public-read"
resource "nexus_security_role" "indus-all-acces-pub-read" {
  description = "indus-all-acces-pub-read"
  name = "indus-all-acces-pub-read"
  roleid = "indus-all-acces-pub-read"
  privileges = local.privileges_all_read
  depends_on = [module.repository]
}

```
