Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regular expression filters #42

Closed
wants to merge 1 commit into from

Conversation

johnlettman
Copy link
Collaborator

@johnlettman johnlettman commented Aug 20, 2024

This PR adds regular expression filters per #1.

A significant concern is the balancing of user input sanitization vs. flexibility. Regular expressions could cause a ReDoS vector without filtering if the tool is used upstream in other projects. However, filtering removes groups, or operators, * extensions, and more, essentially making regular expressions useless.

I have used timeouts to prevent long-running regular expressions (e.g., preventing ReDoS through execution limits). This required the non-standard-library package regex, which provides timeouts.

The new filters are:

  • / -> REGEX
  • ^/ -> NOT_REGEX

The new info page is:


+----+
|NOTE|
+----+
Jockey is a work-in-progress currently only supports querying:
    units
    machines


+-------+
|FILTERS|
+-------+
Filters have a three-part syntax:
    <object type><filter code><content>

<object type> can be any supported Juju object types or their equivalent
abbreviations (see "SHORT NAMES", below).  These values are identical to the
`object` argument in the Jockey CLI.

<filter code> specifies how objects should be filtered relative to <content>
There are four possible values for <filter code>:
    =  : matches
    ^= : does not match
    ~  : contains
    ^~ : does not contain
    /  : matches regex
    ^/ : does not match regex
Exactly one <filter code> must be given per filter.

<content> is a given string that will be used to filter Juju object names.


+-----------+
|SHORT NAMES|
+-----------+
Jockey object name abbreviations:

OBJECT TYPE    SHORT NAMES
charms         charm, c
applications   app, apps, application, a
units          unit, u
machines       machine, m
ips            address, addresses, ip, i
hostnames      hostname, host, hosts, h


+---------------+
|EXAMPLE QUERIES|
+---------------+
 Get all units:
     jockey units

 Get all nova-compute units:
     jockey units application=nova-compute

 Get the hw-health unit on a machine with a partial hostname "e01":
    jockey u a=hw-health host~e01

 Get all non-lxd machines:
     jockey m m^~lxd

 Get units for applications matching a regular expression:
     jockey u a/'telegraf-ceph-(osd|mon)'


+-------------------+
|OPERATIONS EXAMPLES|
+-------------------+
 Run a 'show-sel' action a machine with a partial host name 'ts1363co':
     juju run-action --wait $(jockey u a~hw-hea m~ts1363co) show-sel

@johnlettman johnlettman added the enhancement New feature or request label Aug 20, 2024
@johnlettman johnlettman requested a review from LCVcode August 20, 2024 19:16
@johnlettman johnlettman self-assigned this Aug 20, 2024
@johnlettman johnlettman linked an issue Aug 20, 2024 that may be closed by this pull request
@johnlettman
Copy link
Collaborator Author

Ah, missing tests. I will get to that shortly.

@johnlettman johnlettman added the wip Work in progress label Aug 20, 2024
@johnlettman
Copy link
Collaborator Author

Closing: this will be included in a larger overall refactor I'm developing.

@LCVcode
Copy link
Owner

LCVcode commented Aug 25, 2024

Okay. What are you planning to refactor?

@johnlettman
Copy link
Collaborator Author

#47 complex caching and deeper introspection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wip Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable regex filtering
2 participants