turbaszek commented on a change in pull request #8440: Add airflow connection 
lookup command
URL: https://github.com/apache/airflow/pull/8440#discussion_r410740985
 
 

 ##########
 File path: airflow/cli/commands/connection_command.py
 ##########
 @@ -15,29 +15,41 @@
 # specific language governing permissions and limitations
 # under the License.
 """Connection sub-commands"""
-import reprlib
+from typing import List
 from urllib.parse import urlunparse
 
 from sqlalchemy.orm import exc
 from tabulate import tabulate
 
+from airflow.hooks.base_hook import BaseHook
 from airflow.models import Connection
 from airflow.utils import cli as cli_utils
 from airflow.utils.session import create_session
 
 
+def _tabule_connection(conns: List[Connection], tablefmt: str):
+    tabulat_data = [
+        {
+            'Conn Id': conn.conn_id,
+            'Conn Type': conn.conn_type,
+            'Host': conn.host,
+            'Port': conn.port,
+            'Is Encrypted': conn.is_encrypted,
+            'Is Extra Encrypted': conn.is_encrypted,
+            'Extra': conn.extra,
+        } for conn in conns
+    ]
+
+    msg = tabulate(tabulat_data, tablefmt=tablefmt, headers='keys')
+    return msg
+
+
 def connections_list(args):
     """Lists all connections at the command line"""
     with create_session() as session:
-        conns = session.query(Connection.conn_id, Connection.conn_type,
-                              Connection.host, Connection.port,
-                              Connection.is_encrypted,
-                              Connection.is_extra_encrypted,
-                              Connection.extra).all()
-        conns = [map(reprlib.repr, conn) for conn in conns]
-        msg = tabulate(conns, ['Conn Id', 'Conn Type', 'Host', 'Port',
-                               'Is Encrypted', 'Is Extra Encrypted', 'Extra'],
-                       tablefmt=args.output)
+        conns = session.query(Connection).all()
 
 Review comment:
   I quite agree with @kaxil, adding `--filter=conn` sounds like a possible 
solution? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to