Repository: cloud-custodian/cloud-custodian

Issue:
App-ELB Conditions Error - PolicyConditions object has no attribute config
**Describe the bug**
When running a app-elb policy which has a conditions statement to see if the account_id is present in a S3 csv file we are getting the error "PolicyConditions object has no attribute config"

**To Reproduce**
Steps to reproduce the behavior: Running policy produces error

**Expected behavior**
On previous 0.9.1 this policy seemed to work fine.


**Background (please complete the following information):**
 - OS: [e.g. OSX 10.15] Ubuntu v20
 - Python Version: [e.g. python 3.8.1] 3.8.2
 - Custodian Version: [e.g. 0.8.46.1] 0.9.4.0  c7n-org 0.6.3
 - Tool Version: [if applicable] c7n-org 0.6.3
 - Cloud Provider: [e.g. gcp, aws, azure] aws
 - Policy: [please exclude any account/sensitive information]
```

- name: app-elb-tag-now-compliant-poll
  resource: app-elb
  description: |
    Any Application ELBs which have previously been marked as non compliant with tag policies, that are now compliant
    should be unmarked and the customer emailed.
  conditions:
    - type: value
      key: account_id
      op: not-in
      value_from:
         url: s3://mys3bucket/AccountExceptions.csv
         format: csv2dict
  filters:
    - "tag:c7n_tag_compliance_poll": not-null
    - "tag:ResourceContact": present
    - type: value
      key: "tag:ResourceContact"
      op: not-in
      value_from:
         url: s3://mys3bucket/InvalidEmails.csv
         format: csv2dict
    - type: value
      key: "tag:ResourceContact"
      op: regex
      value: (^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)
    - "tag:BillingCostCenter": present
    - type: value
      key: "tag:BillingCostCenter"
      op: in
      value_from:
         url: s3://mys3bucket/ValidCostCenters.csv
         format: csv2dict
    - "tag:Environment": present
    - type: value
      key: "tag:Environment"
      op: in
      value:
        - tst
        - dev
        - mdl
        - acc
        - prd
        - eat
    - "tag:ResourcePurpose": present
    - type: value
      key: "tag:ResourcePurpose"
      op: regex
      value: ^.{3,}$
    - "tag:Division": present
    - type: value
      key: "tag:Division"
      op: in
      value_from:
         url: s3://mys3bucket/ValidDivisions.csv
         format: csv2dict
    - type: value
      value_type: date
      key: CreatedTime
      op: greater-than
      value: "2020/05/05"
  actions:
    - type: remove-tag
      tags: ["c7n_tag_compliance_poll"]
    - type: notify
      template: default.html
      priority_header: 1
      subject: "Application ELB Tags - Application ELB is now compliant - [custodian {{ account }} - {{ region }}]" 
      violation_desc: |
          The Application ELB which was previously missing or had invalid required tags is now compliant and won't be deleted
      action_desc: "Actions Taken:  Notification Only. The Application ELB is now compliant with tags."
      to:
        - resource-owner
      transport:
        type: sqs
        queue: https://sqs.us-east-1.amazonaws.com/123456789/cloud-custodian-mailer
        region: us-east-1

```
 - Traceback: [if applicable, please exclude sensitive/account information]

```
Traceback (most recent call last):
  File "/root/c7n/lib/python3.8/site-packages/c7n/cli.py", line 362, in main
    command(config)
  File "/root/c7n/lib/python3.8/site-packages/c7n/commands.py", line 136, in _load_policies
    return f(options, list(policies))
  File "/root/c7n/lib/python3.8/site-packages/c7n/commands.py", line 282, in run
    policy()
  File "/root/c7n/lib/python3.8/site-packages/c7n/policy.py", line 1171, in __call__
    elif not self.is_runnable():
  File "/root/c7n/lib/python3.8/site-packages/c7n/policy.py", line 1011, in is_runnable
    return self.conditions.evaluate(event)
  File "/root/c7n/lib/python3.8/site-packages/c7n/policy.py", line 945, in evaluate
    state = all([f.process([policy_vars], event) for f in self.filters])
  File "/root/c7n/lib/python3.8/site-packages/c7n/policy.py", line 945, in <listcomp>
    state = all([f.process([policy_vars], event) for f in self.filters])
  File "/root/c7n/lib/python3.8/site-packages/c7n/filters/core.py", line 530, in process
    return super(ValueFilter, self).process(resources, event)
  File "/root/c7n/lib/python3.8/site-packages/c7n/filters/core.py", line 217, in process
    return list(filter(self, resources))
  File "/root/c7n/lib/python3.8/site-packages/c7n/filters/core.py", line 517, in __call__
    matched = self.match(i)
  File "/root/c7n/lib/python3.8/site-packages/c7n/filters/core.py", line 569, in match
    values = ValuesFrom(self.data['value_from'], self.manager)
  File "/root/c7n/lib/python3.8/site-packages/c7n/resolver.py", line 132, in __init__
    'account_id': manager.config.account_id,
AttributeError: 'PolicyConditions' object has no attribute 'config'
> /root/c7n/lib/python3.8/site-packages/c7n/resolver.py(132)__init__()
-> 'account_id': manager.config.account_id,
(Pdb)

```
 - `custodian version --debug` output 

```
Custodian:   0.9.4
Python:      3.8.2 (default, Apr 27 2020, 15:53:34)
             [GCC 9.3.0]
Platform:    posix.uname_result(sysname='Linux', nodename='ip-10-128-128-28', release='5.4.0-1009-aws', version='#9-Ubuntu SMP Sun Apr 12 19:46:01 UTC 2020', machine='x86_64')
Using venv:  True
Docker: False
Installed:

argcomplete==1.11.1
attrs==19.3.0
boto3==1.14.20
botocore==1.17.20
docutils==0.15.2
importlib-metadata==1.7.0
jmespath==0.10.0
jsonschema==3.2.0
pyrsistent==0.16.0
python-dateutil==2.8.1
pyyaml==5.3.1
s3transfer==0.3.3
setuptools==44.0.0
six==1.15.0
tabulate==0.8.7
urllib3==1.25.9
zipp==3.1.0
```

**Additional context**
Add any other context about the problem here.



Discussion:
its specific to value_from usage in conditions, fix coming up shortly.
> its specific to value_from usage in conditions, fix coming up shortly.

Will this be done as a mini release or just on the master branch?  We haven't been able to use release 0.9.2, 0.9.3, or 0.9.4 due to bugs/issues when running our policies.  A mini release would be nice so we could get a newer releases going in our environments

Resolving patch:
diff --git a/c7n/policy.py b/c7n/policy.py
--- a/c7n/policy.py
+++ b/c7n/policy.py
@@ -922,6 +922,15 @@ def __init__(self, policy, data):
         self.policy = policy
         self.data = data
         self.filters = self.data.get('conditions', [])
+        # for value_from usage / we use the conditions class
+        # to mimic a resource manager interface. we can't use
+        # the actual resource manager as we're overriding block
+        # filters which work w/ resource type metadata and our
+        # resource here is effectively the execution variables.
+        self.config = self.policy.options
+        rm = self.policy.resource_manager
+        self._cache = rm._cache
+        self.session_factory = rm.session_factory
         # used by c7n-org to extend evaluation conditions
         self.env_vars = {}
 


Test patch:
diff --git a/tests/test_policy.py b/tests/test_policy.py
--- a/tests/test_policy.py
+++ b/tests/test_policy.py
@@ -16,6 +16,7 @@
 import json
 import logging
 import mock
+import os
 import shutil
 import tempfile
 
@@ -992,6 +993,24 @@ def test_validate_policy_start_stop(self):
 
 class PolicyConditionsTest(BaseTest):
 
+    def test_value_from(self):
+        tmp_dir = self.change_cwd()
+        p = self.load_policy({
+            'name': 'fx',
+            'resource': 'aws.ec2',
+            'conditions': [{
+                'type': 'value',
+                'key': 'account_id',
+                'op': 'in',
+                'value_from': {
+                    'url': 'file:///{}/accounts.txt'.format(tmp_dir),
+                    'type': 'txt'}
+            }]
+        })
+        with open(os.path.join(tmp_dir, 'accounts.txt'), 'w') as fh:
+            fh.write(p.ctx.options.account_id)
+        self.assertTrue(p.is_runnable())
+
     def test_env_var_extension(self):
         p = self.load_policy({
             'name': 'profx',