def createGroup( domain , auth_token , group_id , groupname=None , description="" ): from GoogleAppsAccountManager import template server = "apps-apis.google.com" path = "/a/feeds/group/2.0/{0}".format(domain) header = { "Content-type" : "application/atom+xml" , "Authorization": "GoogleLogin auth={0}".format(auth_token) } if groupname is None: groupname = group_id body = template.GROUP_ENTRY.format( group_id=group_id , groupname=groupname , description=description , domain=domain ) # HTTP Request (response, status) = http.httpsPOSTRequest(server, path, header, body) group_entry = data.GroupEntry(status, xml_string=response) return True
def createAlias( domain , auth_token , user_email , alias_email ): from GoogleAppsAccountManager import template # Get additional domain (alias_name, alias_domain) = alias_email.split("@") server = "apps-apis.google.com" path = "/a/feeds/alias/2.0/{0}".format(alias_domain) header = { "Content-type" : "application/atom+xml" , "Authorization": "GoogleLogin auth={0}".format(auth_token) } body = template.ALIAS_ENTRY_M.format( alias_name=alias_name , alias_domain=alias_domain , user_email=user_email ) # HTTP Request (response, status) = http.httpsPOSTRequest(server, path, header, body) nickname_entry = data.AliasEntry_M(status, xml_string=response) return True
def createOu( auth_token , customer_id , ou_path # "/ou1/ou1-1/" <-- prefix "/" is needed , description="" , blockInheritance="false" ): from GoogleAppsAccountManager import template server = "apps-apis.google.com" path = "/a/feeds/orgunit/2.0/{0}".format(customer_id) header = { "Content-type" : "application/atom+xml" , "Authorization": "GoogleLogin auth={0}".format(auth_token) } ou_path_rel = ou_path[1:] ou_basename = ou_path_rel.split("/")[-1] ou_parent_path = "/".join(ou_path_rel.split("/")[:-1]) if ou_parent_path == "": ou_parent_path = "/" body = template.OU_ENTRY.format( customer_id = customer_id , ou_name = ou_basename , ou_name_quote = urllib.quote(ou_basename) , ou_parent_path_quote = urllib.quote(ou_parent_path) , description = description , blockInheritance = blockInheritance ) # HTTP Request (response, status) = http.httpsPOSTRequest(server, path, header, body) ou_entry = data.OuEntry(status, xml_string=response) return True
def assignOwnerToGroup(domain, auth_token, owner_name, group_id): from GoogleAppsAccountManager import template server = "apps-apis.google.com" path = "/a/feeds/group/2.0/{0}/{1}/owner".format(domain, group_id) header = { "Content-type" : "application/atom+xml" , "Authorization" : "GoogleLogin auth={0}".format(auth_token) } body = template.GROUP_OWNER_ENTRY.format( domain=domain , group_id=group_id , owner_name=owner_name ) # HTTP Request (response, status) = http.httpsPOSTRequest(server, path, header, body) # Get group feed group_owner_entry = data.GroupOwnerEntry(status, xml_string=response) return True
def createUser( domain , auth_token , user_email , password , sn , given_name , hash_function_name="SHA-1" , is_suspended="false" , is_admin="false" , is_change_password="******" ): from GoogleAppsAccountManager import template # Get additional domain (user_name, mail_domain) = user_email.split("@") server = "apps-apis.google.com" path = "/a/feeds/user/2.0/{0}".format(mail_domain) header = { "Content-type" : "application/atom+xml" , "Authorization": "GoogleLogin auth={0}".format(auth_token) } body = template.USER_ENTRY_M.format( user_name=user_name , mail_domain=mail_domain , password=password , hash_function_name=hash_function_name , sn=sn , given_name=given_name , is_change_password=is_change_password , is_suspended=is_suspended , is_admin=is_admin ) # HTTP Request (response, status) = http.httpsPOSTRequest(server, path, header, body) user_entry = data.UserEntry_M(status, xml_string=response) return True
def createNickname( domain , auth_token , user_name , nickname ): from GoogleAppsAccountManager import template server = "apps-apis.google.com" path = "/a/feeds/{0}/nickname/2.0".format(domain) header = { "Content-type" : "application/atom+xml" , "Authorization": "GoogleLogin auth={0}".format(auth_token) } body = template.NICKNAME_ENTRY.format( user_name=user_name , nickname=nickname , domain=domain ) # HTTP Request (response, status) = http.httpsPOSTRequest(server, path, header, body) nickname_entry = data.NicknameEntry(status, xml_string=response) return True
def createUser( domain , auth_token , user_name , password , sn , given_name , hash_function_name="SHA-1" , suspended="false" , limit="10240" # Not available ): from GoogleAppsAccountManager import template server = "apps-apis.google.com" path = "/a/feeds/{0}/user/2.0".format(domain) header = { "Content-type" : "application/atom+xml" , "Authorization": "GoogleLogin auth={0}".format(auth_token) } # Quota is not available. # So nothing will be done whether limit has value or not. # With an eye toward a future, I leave this implemention limit = "10240" body = template.USER_ENTRY.format( user_name=user_name , password=password , sn=sn , given_name=given_name , hash_function_name=hash_function_name , suspended=suspended , limit=limit , domain=domain ) # HTTP Request (response, status) = http.httpsPOSTRequest(server, path, header, body) user_entry = data.UserEntry(status, xml_string=response) return True