This file is indexed.

/usr/lib/python2.7/dist-packages/gdata/apps/organization/client.py is in python-gdata 2.0.18+dfsg1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/usr/bin/python2.4
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""OrganizationUnitProvisioningClient simplifies OrgUnit Provisioning API calls.

OrganizationUnitProvisioningClient extends gdata.client.GDClient to ease
interaction with the Google Organization Unit Provisioning API.
These interactions include the ability to create, retrieve, update and delete
organization units, move users within organization units, retrieve customerId
and update and retrieve users in organization units.
"""


__author__ = 'Gunjan Sharma <gunjansharma@google.com>'


import urllib
import gdata.apps.organization.data
import gdata.client

CUSTOMER_ID_URI_TEMPLATE = '/a/feeds/customer/%s/customerId'

# OrganizationUnit URI templates
# The strings in this template are eventually replaced with the feed type
# (orgunit/orguser), API version and Google Apps domain name, respectively.
ORGANIZATION_UNIT_URI_TEMPLATE = '/a/feeds/%s/%s/%s'

# The value for orgunit requests
ORGANIZATION_UNIT_FEED = 'orgunit'
# The value for orguser requests
ORGANIZATION_USER_FEED = 'orguser'


class OrganizationUnitProvisioningClient(gdata.client.GDClient):
  """Client extension for the Google Org Unit Provisioning API service.

  Attributes:
    host: string The hostname for the MultiDomain Provisioning API service.
    api_version: string The version of the MultiDomain Provisioning API.
  """

  host = 'apps-apis.google.com'
  api_version = '2.0'
  auth_service = 'apps'
  auth_scopes = gdata.gauth.AUTH_SCOPES['apps']
  ssl = True

  def __init__(self, domain, auth_token=None, **kwargs):
    """Constructs a new client for the Organization Unit Provisioning API.

    Args:
      domain: string The Google Apps domain with Organization Unit
          Provisioning.
      auth_token: (optional) gdata.gauth.ClientLoginToken, AuthSubToken, or
          OAuthToken which authorizes this client to edit the Organization
          Units.
    """
    gdata.client.GDClient.__init__(self, auth_token=auth_token, **kwargs)
    self.domain = domain

  def make_organization_unit_provisioning_uri(
      self, feed_type, customer_id, org_unit_path_or_user_email=None,
      params=None):

    """Creates a resource feed URI for the Organization Unit Provisioning API.

    Using this client's Google Apps domain, create a feed URI for organization
    unit provisioning in that domain. If an org unit path or org user email
    address is provided, return a URI for that specific resource.
    If params are provided, append them as GET params.

    Args:
      feed_type: string The type of feed (orgunit/orguser)
      customer_id: string The customerId of the user.
      org_unit_path_or_user_email: string (optional) The org unit path or
          org user email address for which to make a feed URI.
      params: dict (optional) key -> value params to append as GET vars to the
          URI. Example: params={'start': 'my-resource-id'}

    Returns:
      A string giving the URI for organization unit provisioning for this
          client's Google Apps domain.
    """
    uri = ORGANIZATION_UNIT_URI_TEMPLATE % (feed_type, self.api_version,
                                            customer_id)
    if org_unit_path_or_user_email:
      uri += '/' + org_unit_path_or_user_email
    if params:
      uri += '?' + urllib.urlencode(params)
    return uri

  MakeOrganizationUnitProvisioningUri = make_organization_unit_provisioning_uri

  def make_organization_unit_orgunit_provisioning_uri(self, customer_id,
                                                      org_unit_path=None,
                                                      params=None):
    """Creates a resource feed URI for the orgunit's Provisioning API calls.

    Using this client's Google Apps domain, create a feed URI for organization
    unit orgunit's provisioning in that domain. If an org_unit_path is
    provided, return a URI for that specific resource.
    If params are provided, append them as GET params.

    Args:
      customer_id: string The customerId of the user.
      org_unit_path: string (optional) The organization unit's path for which
          to make a feed URI.
      params: dict (optional) key -> value params to append as GET vars to the
          URI. Example: params={'start': 'my-resource-id'}

    Returns:
      A string giving the URI for organization unit provisioning for
          given org_unit_path
    """
    return self.make_organization_unit_provisioning_uri(
        ORGANIZATION_UNIT_FEED, customer_id, org_unit_path, params)

  MakeOrganizationUnitOrgunitProvisioningUri = make_organization_unit_orgunit_provisioning_uri

  def make_organization_unit_orguser_provisioning_uri(self, customer_id,
                                                      org_user_email=None,
                                                      params=None):
    """Creates a resource feed URI for the orguser's Provisioning API calls.

    Using this client's Google Apps domain, create a feed URI for organization
    unit orguser's provisioning in that domain. If an org_user_email is
    provided, return a URI for that specific resource.
    If params are provided, append them as GET params.

    Args:
      customer_id: string The customerId of the user.
      org_user_email: string (optional) The organization unit's path for which
          to make a feed URI.
      params: dict (optional) key -> value params to append as GET vars to the
          URI. Example: params={'start': 'my-resource-id'}

    Returns:
      A string giving the URI for organization user provisioning for
          given org_user_email
    """
    return self.make_organization_unit_provisioning_uri(
        ORGANIZATION_USER_FEED, customer_id, org_user_email, params)

  MakeOrganizationUnitOrguserProvisioningUri = make_organization_unit_orguser_provisioning_uri

  def make_customer_id_feed_uri(self):
    """Creates a feed uri for retrieving customerId of the user.

    Returns:
      A string giving the URI for retrieving customerId of the user.
    """
    uri = CUSTOMER_ID_URI_TEMPLATE % (self.api_version)
    return uri

  MakeCustomerIdFeedUri = make_customer_id_feed_uri

  def retrieve_customer_id(self, **kwargs):
    """Retrieve the Customer ID for the customer domain.

    Returns:
      A gdata.apps.organization.data.CustomerIdEntry.
    """
    uri = self.MakeCustomerIdFeedUri()
    return self.GetEntry(
        uri,
        desired_class=gdata.apps.organization.data.CustomerIdEntry,
        **kwargs)

  RetrieveCustomerId = retrieve_customer_id

  def create_org_unit(self, customer_id, name, parent_org_unit_path='/',
                      description='', block_inheritance=False, **kwargs):
    """Create a Organization Unit.

    Args:
      customer_id: string The ID of the Google Apps customer.
      name: string The simple organization unit text name, not the full path
            name.
      parent_org_unit_path: string The full path of the parental tree to this
                            organization unit (default: '/').
                            [Note: Each element of the path MUST be URL encoded
                            (example: finance%2Forganization/suborganization)]
      description: string The human readable text description of the
                   organization unit (optional).
      block_inheritance: boolean This parameter blocks policy setting
                         inheritance from organization units higher in
                         the organization tree (default: False).

    Returns:
      A gdata.apps.organization.data.OrgUnitEntry representing an organization
      unit.
    """
    new_org_unit = gdata.apps.organization.data.OrgUnitEntry(
        org_unit_name=name, parent_org_unit_path=parent_org_unit_path,
        org_unit_description=description,
        org_unit_block_inheritance=block_inheritance)
    return self.post(
        new_org_unit,
        self.MakeOrganizationUnitOrgunitProvisioningUri(customer_id), **kwargs)

  CreateOrgUnit = create_org_unit

  def update_org_unit(self, customer_id, org_unit_path, org_unit_entry,
                      **kwargs):
    """Update a Organization Unit.

    Args:
      customer_id: string The ID of the Google Apps customer.
      org_unit_path: string The organization's full path name.
                     [Note: Each element of the path MUST be URL encoded
                     (example: finance%2Forganization/suborganization)]
      org_unit_entry: gdata.apps.organization.data.OrgUnitEntry
                      The updated organization unit entry.

    Returns:
      A gdata.apps.organization.data.OrgUnitEntry representing an organization
          unit.
    """
    if not org_unit_entry.GetParentOrgUnitPath():
      org_unit_entry.SetParentOrgUnitPath('/')
    return self.update(org_unit_entry,
                       uri=self.MakeOrganizationUnitOrgunitProvisioningUri(
                           customer_id, org_unit_path=org_unit_path), **kwargs)

  UpdateOrgUnit = update_org_unit

  def move_users_to_org_unit(self, customer_id, org_unit_path, users_to_move,
                             **kwargs):
    """Move a user to an Organization Unit.

    Args:
      customer_id: string The ID of the Google Apps customer.
      org_unit_path: string The organization's full path name.
                     [Note: Each element of the path MUST be URL encoded
                     (example: finance%2Forganization/suborganization)]
      users_to_move: list Email addresses of users to move in list format.
                     [Note: You can move a maximum of 25 users at one time.]

    Returns:
      A gdata.apps.organization.data.OrgUnitEntry representing
      an organization unit.
    """
    org_unit_entry = self.retrieve_org_unit(customer_id, org_unit_path)
    org_unit_entry.SetUsersToMove(', '.join(users_to_move))
    if not org_unit_entry.GetParentOrgUnitPath():
      org_unit_entry.SetParentOrgUnitPath('/')
    return self.update(org_unit_entry,
                       uri=self.MakeOrganizationUnitOrgunitProvisioningUri(
                           customer_id, org_unit_path=org_unit_path), **kwargs)

  MoveUserToOrgUnit = move_users_to_org_unit

  def retrieve_org_unit(self, customer_id, org_unit_path, **kwargs):
    """Retrieve a Orgunit based on its path.

    Args:
      customer_id: string The ID of the Google Apps customer.
      org_unit_path: string The organization's full path name.
                     [Note: Each element of the path MUST be URL encoded
                     (example: finance%2Forganization/suborganization)]

    Returns:
      A gdata.apps.organization.data.OrgUnitEntry representing
          an organization unit.
    """
    uri = self.MakeOrganizationUnitOrgunitProvisioningUri(
        customer_id, org_unit_path=org_unit_path)
    return self.GetEntry(
        uri, desired_class=gdata.apps.organization.data.OrgUnitEntry, **kwargs)

  RetrieveOrgUnit = retrieve_org_unit

  def retrieve_feed_from_uri(self, uri, desired_class, **kwargs):
    """Retrieve feed from given uri.

    Args:
      uri: string The uri from where to get the feed.
      desired_class: Feed The type of feed that if to be retrieved.

    Returns:
      Feed of type desired class.
    """
    return self.GetFeed(uri, desired_class=desired_class, **kwargs)

  RetrieveFeedFromUri = retrieve_feed_from_uri

  def retrieve_all_org_units_from_uri(self, uri, **kwargs):
    """Retrieve all OrgUnits from given uri.

    Args:
      uri: string The uri from where to get the orgunits.

    Returns:
      gdata.apps.organisation.data.OrgUnitFeed object
    """
    orgunit_feed = gdata.apps.organization.data.OrgUnitFeed()
    temp_feed = self.RetrieveFeedFromUri(
        uri, gdata.apps.organization.data.OrgUnitFeed)
    orgunit_feed.entry = temp_feed.entry
    next_link = temp_feed.GetNextLink()
    while next_link is not None:
      uri = next_link.GetAttributes()[0].value
      temp_feed = self.GetFeed(
          uri, desired_class=gdata.apps.organization.data.OrgUnitFeed, **kwargs)
      orgunit_feed.entry[0:0] = temp_feed.entry
      next_link = temp_feed.GetNextLink()
    return orgunit_feed

  RetrieveAllOrgUnitsFromUri = retrieve_all_org_units_from_uri

  def retrieve_all_org_units(self, customer_id, **kwargs):
    """Retrieve all OrgUnits in the customer's domain.

    Args:
      customer_id: string The ID of the Google Apps customer.

    Returns:
      gdata.apps.organisation.data.OrgUnitFeed object
    """
    uri = self.MakeOrganizationUnitOrgunitProvisioningUri(
        customer_id, params={'get': 'all'}, **kwargs)
    return self.RetrieveAllOrgUnitsFromUri(uri)

  RetrieveAllOrgUnits = retrieve_all_org_units

  def retrieve_page_of_org_units(self, customer_id, startKey=None, **kwargs):
    """Retrieve one page of OrgUnits in the customer's domain.

    Args:
      customer_id: string The ID of the Google Apps customer.
      startKey: string The key to continue for pagination through all OrgUnits.

    Returns:
      gdata.apps.organisation.data.OrgUnitFeed object
    """
    uri = ''
    if startKey is not None:
      uri = self.MakeOrganizationUnitOrgunitProvisioningUri(
          customer_id, params={'get': 'all', 'startKey': startKey}, **kwargs)
    else:
      uri = self.MakeOrganizationUnitOrgunitProvisioningUri(
          customer_id, params={'get': 'all'}, **kwargs)
    return self.GetFeed(
        uri, desired_class=gdata.apps.organization.data.OrgUnitFeed, **kwargs)

  RetrievePageOfOrgUnits = retrieve_page_of_org_units

  def retrieve_sub_org_units(self, customer_id, org_unit_path, **kwargs):
    """Retrieve all Sub-OrgUnits of the provided OrgUnit.

    Args:
      customer_id: string The ID of the Google Apps customer.
      org_unit_path: string The organization's full path name.
                     [Note: Each element of the path MUST be URL encoded
                     (example: finance%2Forganization/suborganization)]

    Returns:
      gdata.apps.organisation.data.OrgUnitFeed object
    """
    uri = self.MakeOrganizationUnitOrgunitProvisioningUri(
        customer_id,
        params={'get': 'children', 'orgUnitPath': org_unit_path}, **kwargs)
    return self.RetrieveAllOrgUnitsFromUri(uri)

  RetrieveSubOrgUnits = retrieve_sub_org_units

  def delete_org_unit(self, customer_id, org_unit_path, **kwargs):
    """Delete a Orgunit based on its path.

    Args:
      customer_id: string The ID of the Google Apps customer.
      org_unit_path: string The organization's full path name.
                     [Note: Each element of the path MUST be URL encoded
                     (example: finance%2Forganization/suborganization)]

    Returns:
      An HTTP response object.  See gdata.client.request().
    """
    return self.delete(self.MakeOrganizationUnitOrgunitProvisioningUri(
        customer_id, org_unit_path=org_unit_path), **kwargs)

  DeleteOrgUnit = delete_org_unit

  def update_org_user(self, customer_id, user_email, org_unit_path, **kwargs):
    """Update the OrgUnit of a OrgUser.

    Args:
      customer_id: string The ID of the Google Apps customer.
      user_email: string The email address of the user.
      org_unit_path: string The new organization's full path name.
                     [Note: Each element of the path MUST be URL encoded
                     (example: finance%2Forganization/suborganization)]

    Returns:
      A gdata.apps.organization.data.OrgUserEntry representing
          an organization user.
    """
    old_user_entry = self.RetrieveOrgUser(customer_id, user_email)
    old_org_unit_path = old_user_entry.GetOrgUnitPath()
    if not old_org_unit_path:
      old_org_unit_path = '/'
    old_user_entry.SetOldOrgUnitPath(old_org_unit_path)
    old_user_entry.SetOrgUnitPath(org_unit_path)
    return self.update(old_user_entry,
                       uri=self.MakeOrganizationUnitOrguserProvisioningUri(
                           customer_id, user_email), **kwargs)

  UpdateOrgUser = update_org_user

  def retrieve_org_user(self, customer_id, user_email, **kwargs):
    """Retrieve an organization user.

    Args:
      customer_id: string The ID of the Google Apps customer.
      user_email: string The email address of the user.

    Returns:
      A gdata.apps.organization.data.OrgUserEntry representing
          an organization user.
    """
    uri = self.MakeOrganizationUnitOrguserProvisioningUri(customer_id,
                                                          user_email)
    return self.GetEntry(
        uri, desired_class=gdata.apps.organization.data.OrgUserEntry, **kwargs)

  RetrieveOrgUser = retrieve_org_user

  def retrieve_all_org_users_from_uri(self, uri, **kwargs):
    """Retrieve all OrgUsers from given uri.

    Args:
      uri: string The uri from where to get the orgusers.

    Returns:
      gdata.apps.organisation.data.OrgUserFeed object
    """
    orguser_feed = gdata.apps.organization.data.OrgUserFeed()
    temp_feed = self.RetrieveFeedFromUri(
        uri, gdata.apps.organization.data.OrgUserFeed)
    orguser_feed.entry = temp_feed.entry
    next_link = temp_feed.GetNextLink()
    while next_link is not None:
      uri = next_link.GetAttributes()[0].value
      temp_feed = self.GetFeed(
          uri, desired_class=gdata.apps.organization.data.OrgUserFeed, **kwargs)
      orguser_feed.entry[0:0] = temp_feed.entry
      next_link = temp_feed.GetNextLink()
    return orguser_feed

  RetrieveAllOrgUsersFromUri = retrieve_all_org_users_from_uri

  def retrieve_all_org_users(self, customer_id, **kwargs):
    """Retrieve all OrgUsers in the customer's domain.

    Args:
      customer_id: string The ID of the Google Apps customer.

    Returns:
      gdata.apps.organisation.data.OrgUserFeed object
    """
    uri = self.MakeOrganizationUnitOrguserProvisioningUri(
        customer_id, params={'get': 'all'}, **kwargs)
    return self.RetrieveAllOrgUsersFromUri(uri)

  RetrieveAllOrgUsers = retrieve_all_org_users

  def retrieve_page_of_org_users(self, customer_id, startKey=None, **kwargs):
    """Retrieve one page of OrgUsers in the customer's domain.

    Args:
      customer_id: string The ID of the Google Apps customer.
      startKey: The string key to continue for pagination through all OrgUnits.

    Returns:
      gdata.apps.organisation.data.OrgUserFeed object
    """
    uri = ''
    if startKey is not None:
      uri = self.MakeOrganizationUnitOrguserProvisioningUri(
          customer_id, params={'get': 'all', 'startKey': startKey}, **kwargs)
    else:
      uri = self.MakeOrganizationUnitOrguserProvisioningUri(
          customer_id, params={'get': 'all'})
    return self.GetFeed(
        uri, desired_class=gdata.apps.organization.data.OrgUserFeed, **kwargs)

  RetrievePageOfOrgUsers = retrieve_page_of_org_users

  def retrieve_org_unit_users(self, customer_id, org_unit_path, **kwargs):
    """Retrieve all OrgUsers of the provided OrgUnit.

    Args:
      customer_id: string The ID of the Google Apps customer.
      org_unit_path: string The organization's full path name.
                     [Note: Each element of the path MUST be URL encoded
                     (example: finance%2Forganization/suborganization)]

    Returns:
      gdata.apps.organisation.data.OrgUserFeed object
    """
    uri = self.MakeOrganizationUnitOrguserProvisioningUri(
        customer_id,
        params={'get': 'children', 'orgUnitPath': org_unit_path})
    return self.RetrieveAllOrgUsersFromUri(uri, **kwargs)

  RetrieveOrgUnitUsers = retrieve_org_unit_users