
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	KJr  SS
KJr  \	R                   " \	R"                  R$                  \	R"                  R&                  5       " S S\	R(                  5      5       rg)z/Command to set scopes for an instance resource.    )absolute_import)division)unicode_literals)base_classes)	constants)base)scope)
exceptions)flagsc                   p   ^  \ rS rSrSrSSS.rU 4S jr\S 5       rS r	S	 r
S
 rS rS rS rS rSrU =r$ )	SetScopes   zCSet scopes and service account for a Compute Engine VM instance.
  z        `{command}` lets you configure service account and scopes for a
        Compute Engine VM instance.

        Note: This command might be deprecated in a future release.
        Use `gcloud compute instances set-service-account` instead.
        z
       To set a service account with the ``cloud-platform'' scope, run:

    $ {command} example-instance --scopes=cloud-platform --zone=us-central1-b --service-account=example-account
       )DESCRIPTIONEXAMPLESc                 H   > [         U R                  U ]
  " U0 UD6  S U l        g )N)super	__class____init__	_instance)selfargskwargsr   s      +lib/surface/compute/instances/set_scopes.pyr   SetScopes.__init__1   s"    	$..$($9&9DN    c                 p    [         R                  R                  U 5        [         R                  " U S5        g )NT)r   INSTANCE_ARGAddArgumentAddServiceAccountAndScopeArgs)parsers    r   ArgsSetScopes.Args5   s&    	""6*	''5r   c                     U R                   (       d[  UR                  R                  SUR                  R                  " S0 UR                  5       D64nUR                  U/S9nUS   U l         U R                   $ )z?Return cached instance if there isn't one fetch referenced one.Get)requestsr    )r   apitools_client	instancesmessagesComputeInstancesGetRequestAsDictMakeRequests)r   instance_refclientrequestinstances        r   _get_instanceSetScopes._get_instance:   sp    >>''115;; .#**,./g $$wi$8h{dn>>r   c                 r    U R                  X5      nUc  gUR                  nU(       a  US   R                  $ g)z2Return email of service account instance is using.Nr   )r1   serviceAccountsemail)r   r-   r.   r0   orignal_service_accountss        r   _original_emailSetScopes._original_emailF   s>    !!,7H'77%a(...r   c                 |    U R                  X5      nUc  / $ UR                  n/ nU H  nXVR                  -  nM     U$ )z Return scopes instance is using.)r1   r4   scopes)r   r-   r.   r0   r6   resultaccountss          r   _original_scopesSetScopes._original_scopesP   sI    !!,7Hi'77F,f -Mr   c                     UR                   (       a  gUR                  (       a  UR                  $ U R                  X#5      $ )z8Return email to set as service account for the instance.N)no_service_accountservice_accountr7   r   r   r-   r.   s       r   _emailSetScopes._email[   s4    !!!55r   c                 |    UR                   (       a  / $ UR                  b  UR                  $ U R                  X#5      $ )z&Return scopes to set for the instance.)	no_scopesr:   r=   rB   s       r   _unprocessed_scopesSetScopes._unprocessed_scopesc   s3    ~~i{{[[  66r   c                     / nU R                  UX#5       H4  n[        R                  R                  XU/5      nUR	                  U5        M6     U$ )a*  Get list of scopes to be assigned to the instance.

Args:
  args: parsed command  line arguments.
  instance_ref: reference to the instance to which scopes will be assigned.
  client: a compute_holder.client instance

Returns:
  List of scope urls extracted from args, with scope aliases expanded.
)rG   r   SCOPESgetextend)r   r   r-   r.   r;   unprocessed_scoper	   s          r   _scopesSetScopes._scopesk   sS     F!55d6BL""#46IJemmEL Mr   c                    [         R                  " U R                  5       5      nUR                  n[        R
                  " U5        [        R                  R                  XR                  [        R                  R                  [        R                  " U5      S9nU R                  XU5      nU R                  XU5      nU(       a  U(       d  [        R                   " S5      eUR"                  R%                  UR"                  R'                  UUS9UR(                  UR*                  UR-                  5       S9nUR/                  UR0                  R2                  SU4/5      $ )N)default_scopescope_listerz4Can not set scopes when there is no service acoount.)r5   r:   )!instancesSetServiceAccountRequestprojectzoner0   SetServiceAccount)r   ComputeApiHolderReleaseTrackr.   r   "ValidateServiceAccountAndScopeArgsr   ResolveAsResource	resourcescompute_scope	ScopeEnumZONEGetInstanceZoneScopeListerrC   rN   r
   $ScopesWithoutServiceAccountExceptionr)   (ComputeInstancesSetServiceAccountRequest!InstancesSetServiceAccountRequestrT   rU   Namer,   r'   r(   )r   r   compute_holderr.   r-   r5   r:   r/   s           r   RunSetScopes.Run}   sB   !2243D3D3FGN""F	,,T2%%77&&#--2255f= 8 ?L
 KKF3E\\$f5Fe;;
@B B ooFFOO== >  $$""$ G &G !7!7!A!A!4g!?  @ A Ar   )r   )__name__
__module____qualname____firstlineno____doc__detailed_helpr   staticmethodr!   r1   r7   r=   rC   rG   rN   re   __static_attributes____classcell__)r   s   @r   r   r      s\    
- 6 6
	67$A Ar   r   N)rk   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   r\   ,googlecloudsdk.command_lib.compute.instancesr
   r   ReleaseTracksrX   ALPHABETASilentCommandr   r&   r   r   <module>ry      sr    6 &  ' 7 4 ( E C > D%%++T->->-C-CD{A"" {A E{Ar   