Restricting link sharing

I wonder if it is possible to restrict ‘share via link’ to a specific group.

The panel admin setting is an all-or-nothing configuration (or, rather everyone-or-nobody). I need to enable share via link to a specific (small) group of users.

Can I do this either via command line or RESTful API?

Any pointers will be appreciated.

Have you activated “sharing with groups” and also outside own group?

Yes, however, sharing with groups is about internal sharing (which I do want for everyone).

I don’t want anyone to be able to share via link except for a very small group of people (which I can, obviously, assign to a group).