parameters: (self)
return_statement: return 0
docstring: Command entry point for signurl command.
docstring_summary: Command entry point for signurl command.
docstring_tokens: Command entry point for signurl command .
function: def RunCommand(self):
      """Command entry point for signurl command."""
      if not HAVE_OPENSSL:
        raise CommandException(
            'The signurl command requires the pyopenssl library (try pip '
            'install pyopenssl or easy_install pyopenssl)')
  
      method, expiration, content_type, passwd = self._ParseAndCheckSubOpts()
      storage_urls = self._EnumerateStorageUrls(self.args[1:])
  
      if not passwd:
        passwd = getpass.getpass('Keystore password:')
  
      ks, client_id = _ReadKeystore(open(self.args[0], 'rb').read(), passwd)
  
      print 'URL\tHTTP Method\tExpiration\tSigned URL'
      for url in storage_urls:
        if url.scheme != 'gs':
          raise CommandException('Can only create signed urls from gs:// urls')
        if url.IsBucket():
          gcs_path = url.bucket_name
        else:
          # Need to url encode the object name as Google Cloud Storage does when
          # computing the string to sign when checking the signature.
          gcs_path = '{0}/{1}'.format(url.bucket_name,
                                      urllib.quote(url.object_name.encode(UTF8)))
  
        final_url = _GenSignedUrl(ks.get_privatekey(), client_id,
                                  method, '', content_type, expiration,
                                  gcs_path)
  
        expiration_dt = datetime.fromtimestamp(expiration)
  
        print '{0}\t{1}\t{2}\t{3}'.format(url.url_string.encode(UTF8), method,
                                          (expiration_dt
                                           .strftime('%Y-%m-%d %H:%M:%S')),
                                          final_url.encode(UTF8))
  
        response_code = self._ProbeObjectAccessWithClient(ks.get_privatekey(),
                                                          client_id, gcs_path)
  
        if response_code == 404 and method != 'PUT':
          if url.IsBucket():
            msg = ('Bucket {0} does not exist. Please create a bucket with '
                   'that name before a creating signed URL to access it.'
                   .format(url))
          else:
            msg = ('Object {0} does not exist. Please create/upload an object '
                   'with that name before a creating signed URL to access it.'
                   .format(url))
  
          raise CommandException(msg)
        elif response_code == 403:
          self.logger.warn(
              '%s does not have permissions on %s, using this link will likely '
              'result in a 403 error until at least READ permissions are granted',
              client_id, url)
  
      return 0
function_tokens: def RunCommand ( self ) : if not HAVE_OPENSSL : raise CommandException ( 'The signurl command requires the pyopenssl library (try pip ' 'install pyopenssl or easy_install pyopenssl)' ) method , expiration , content_type , passwd = self . _ParseAndCheckSubOpts ( ) storage_urls = self . _EnumerateStorageUrls ( self . args [ 1 : ] ) if not passwd : passwd = getpass . getpass ( 'Keystore password:' ) ks , client_id = _ReadKeystore ( open ( self . args [ 0 ] , 'rb' ) . read ( ) , passwd ) print 'URL\tHTTP Method\tExpiration\tSigned URL' for url in storage_urls : if url . scheme != 'gs' : raise CommandException ( 'Can only create signed urls from gs:// urls' ) if url . IsBucket ( ) : gcs_path = url . bucket_name else : # Need to url encode the object name as Google Cloud Storage does when # computing the string to sign when checking the signature. gcs_path = '{0}/{1}' . format ( url . bucket_name , urllib . quote ( url . object_name . encode ( UTF8 ) ) ) final_url = _GenSignedUrl ( ks . get_privatekey ( ) , client_id , method , '' , content_type , expiration , gcs_path ) expiration_dt = datetime . fromtimestamp ( expiration ) print '{0}\t{1}\t{2}\t{3}' . format ( url . url_string . encode ( UTF8 ) , method , ( expiration_dt . strftime ( '%Y-%m-%d %H:%M:%S' ) ) , final_url . encode ( UTF8 ) ) response_code = self . _ProbeObjectAccessWithClient ( ks . get_privatekey ( ) , client_id , gcs_path ) if response_code == 404 and method != 'PUT' : if url . IsBucket ( ) : msg = ( 'Bucket {0} does not exist. Please create a bucket with ' 'that name before a creating signed URL to access it.' . format ( url ) ) else : msg = ( 'Object {0} does not exist. Please create/upload an object ' 'with that name before a creating signed URL to access it.' . format ( url ) ) raise CommandException ( msg ) elif response_code == 403 : self . logger . warn ( '%s does not have permissions on %s, using this link will likely ' 'result in a 403 error until at least READ permissions are granted' , client_id , url ) return 0