Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google groups #253

Open
yosefy opened this issue Jan 2, 2020 · 2 comments
Open

google groups #253

yosefy opened this issue Jan 2, 2020 · 2 comments
Labels

Comments

@yosefy
Copy link

yosefy commented Jan 2, 2020

google added new feature to add permissions to google groups
so you may see groups in project
may be we can add it so, no need to define groups twice

thanks

@bugy
Copy link
Owner

bugy commented Jan 4, 2020

Hi @yosefy, thanks for the ticket, it's a really nice one!

@bugy bugy added the feature label Jan 4, 2020
@schnippendullerich
Copy link

schnippendullerich commented Dec 9, 2020

You can use my script, I fixed it like this:

#!/bin/bash

$gam=~/bin/gamdir/gam # this must be set to the path of gam on your system
JSON_FILE="$HOME/bin/script-server/conf/conf.json"

# get users from google group
echo "Building array..."
readarray -t EMAILS < <($gam print group-members group GOOGLEGROUPNAME fields email | grep GOOGLEGROUPNAME | cut -d ',' -f2)
NULL=`declare -p EMAILS`
echo -e "done.\n"

# create new json values from array
buildJSON () {
  echo -n '[ '
  while [ $# -gt 0 ]; do
    x=${1//\\/\\\\}
    echo -n \"${x//\"/\\\"}\"
    [ $# -gt 1 ] && echo -n ', '
    shift
  done
  echo ' ]'
}

echo "Building new JSON text..."
NEWLINE=`buildJSON "${EMAILS[@]}"`
NEWLINE_USERS=`echo -e "\"allowed_users\": $NEWLINE,"`
NEWLINE_ADMINS=`echo -e "\"admin_users\": $NEWLINE"`
echo "    $NEWLINE_USERS"
echo "    $NEWLINE_ADMINS"
echo -e "done.\n"

echo -n "Replacing lines in $JSON_FILE... "
sed -i "11s/.*/\t$NEWLINE_USERS/" $JSON_FILE
sed -i "12s/.*/\t$NEWLINE_ADMINS/" $JSON_FILE
echo -e "done.\n"

echo -n "Restarting service script-server..."
sleep 3 # without a short break we won't have much info in webUI
sudo systemctl restart script-server # to get new users working in script-server
echo " done." # won't appear in webUI of script-server anymore
  1. You will need to setup gam before from https://github.com/jay0lee/GAM/wiki and setup a project in google developers console.
  2. Change sed -i "11s... and sed -i "12s... to the line numbers to replace of your conf.json. In my case ist 11 and 12. To make this more flexible you could also just search for the lines and assing line numbers as they are, even after manual editing. Up to you.
  3. For the last command you need to modify sudoers file to prevent asking for sudoers password.

As all users in the group I am getting the users from are admins, it's the same in both replaced lines. Just create a new array from another group if different.

You can run this as cronjob or even with script-server to update users/admins after change in the google group.

Kay

@bugy bugy added this to the 1.18.0 milestone Sep 3, 2021
@bugy bugy removed this from the 1.18.0 milestone Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants