Repository: cloud-custodian/cloud-custodian

Issue:
GCP mark(ed)-for-op support op that contains hyphen
### Describe the bug

The below filter works as expected. But if change the op to anything contains hyphen, eg `set-public-access-prevention`, it won't work because the way we split the label value, `msg, action, action_date_str = v.rsplit('-', 2)` at line 89 of _tools/c7n_gcp/c7n_gcp/filters/labels.py_.
```yaml
      - type: marked-for-op
        label: custodian_status
        op: notify
```
I revised it in my folk and here are [the changes](https://github.com/newscorp-ghfb/cloud-custodian/pull/124/files). It is not backward compatible so no PR will be summited.
```python
msg, action, action_date_str = v.rsplit('--', 2)
```
On the other hand, I wonder how Cloud Custodian handles this kind of non-backword-compatible changes?

### What did you expect to happen?

I expect it to support all actions.

### Cloud Provider

Google Cloud (GCP)

### Cloud Custodian version and dependency information

```shell
0.9.17, macOS
```


### Policy

_No response_

### Relevant log/traceback output

_No response_

### Extra information or context

_No response_


Discussion:
hmm.. thanks for the bug report, in terms of maintaining compatibility, I think it would be best for us to build an action vocabulary set, and do a split('-', 1) with longest prefix match to determine action. Its also worth reviewing the behavior here in other providers.

Resolving patch:
diff --git a/tools/c7n_gcp/c7n_gcp/filters/labels.py b/tools/c7n_gcp/c7n_gcp/filters/labels.py
--- a/tools/c7n_gcp/c7n_gcp/filters/labels.py
+++ b/tools/c7n_gcp/c7n_gcp/filters/labels.py
@@ -68,6 +68,8 @@ def validate(self):
             raise FilterValidationError(
                 "Invalid timezone specified '%s' in %s" % (
                     self.data.get('tz'), self.manager.data))
+        self.valid_actions = sorted(
+            self.manager.action_registry.keys(), key=lambda k: len(k), reverse=True)
         return self
 
     def process(self, resources, event=None):
@@ -78,6 +80,17 @@ def process(self, resources, event=None):
         self.tz = Time.get_tz(self.data.get('tz', 'utc'))
         return super(LabelActionFilter, self).process(resources, event)
 
+    def parse(self, v: str):
+        remainder, action_date = v.rsplit('-', 1)
+        found = False
+        msg = ""
+        for a in self.valid_actions:
+            if remainder.endswith(a):
+                found = a
+                msg = remainder[:-len(a) - 1]
+                break
+        return msg, found, action_date
+
     def __call__(self, i):
         v = i.get('labels', {}).get(self.label, None)
 
@@ -86,9 +99,9 @@ def __call__(self, i):
         if '-' not in v or '_' not in v:
             return False
 
-        msg, action, action_date_str = v.rsplit('-', 2)
+        msg, action, action_date_str = self.parse(v)
 
-        if action != self.op:
+        if action != self.op or not action:
             return False
 
         try:


Test patch:
diff --git a/tools/c7n_gcp/tests/test_gcp_labels.py b/tools/c7n_gcp/tests/test_gcp_labels.py
--- a/tools/c7n_gcp/tests/test_gcp_labels.py
+++ b/tools/c7n_gcp/tests/test_gcp_labels.py
@@ -93,3 +93,18 @@ def test_schema_validate(self):
                 {'type': 'marked-for-op',
                  'op': 'no-such-op'}
             ]))
+
+    def test_parse(self):
+        p = self.load_policy(get_policy(None, [{"type": "marked-for-op", "op": "detach-disks"}]))
+        marked_for = p.resource_manager.filters[0]
+        assert marked_for.parse("resource_policy-detach-disks-2022_10_23_12_10") == (
+            'resource_policy', 'detach-disks', '2022_10_23_12_10')
+
+        assert marked_for.parse("resource_policy-create-machine-image-2022_10_23_12_10") == (
+            'resource_policy', 'create-machine-image', '2022_10_23_12_10')
+
+        assert marked_for.parse("resource_policy-delete-2022_10_23_12_10") == (
+            'resource_policy', 'delete', '2022_10_23_12_10')
+
+        assert marked_for.parse("custom-message-delete-2022_10_23_12_10") == (
+            'custom-message', 'delete', '2022_10_23_12_10')