# Copyright 2020 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Flask config."""
import os
from dotenv import load_dotenv
from google.cloud import secretmanager

load_dotenv()


class Config:
    """Base config."""

    FLASK_ENV = 'production'
    TESTING = False
    DEBUG = False
    
    

class ProdConfig(Config):
    @property
    def PHILIPS_HUE_URL(self):
        client = secretmanager.SecretManagerServiceClient()

        secret_path = client.secret_version_path('alertmanager-2020-intern-r', 'philips_ip', 'latest')
        response = client.access_secret_version(secret_path)
        philips_ip = response.payload.data.decode('UTF-8')

        secret_path = client.secret_version_path('alertmanager-2020-intern-r', 'philips_username', 'latest')
        response = client.access_secret_version(secret_path)
        philips_username = response.payload.data.decode('UTF-8')

        return 'http://{}/api/{}'.format(philips_ip, philips_username)
    


class DevConfig(Config):
    FLASK_ENV = 'development'
    DEBUG = True
    TESTING = True
    PHILIPS_HUE_URL = os.environ.get('PHILIPS_URL')



configs = {
    'prod': ProdConfig,
    'dev': DevConfig,
    'default': ProdConfig
}

@@ -824,24 +824,91 @@
 ig(Config):%0A
+    __philips_hue_ip = None%0A    __philips_hue_username = None%0A    %0A
     @propert
@@ -933,19 +933,18 @@
 HUE_
-URL
+IP
 (self):%0A
     
@@ -939,16 +939,57 @@
 (self):%0A
+        if __philips_hue_ip is None:%0A    
         
@@ -1040,17 +1040,20 @@
 lient()%0A
-%0A
+    
         
@@ -1147,32 +1147,36 @@
 atest')%0A        
+   
+ 
 response = clien
@@ -1220,24 +1220,30 @@
         
+    __
 philips_
 ip = res
@@ -1234,16 +1234,20 @@
 philips_
+hue_
 ip = res
@@ -1274,32 +1274,230 @@
 ecode('UTF-8')%0A%0A
+        return __philips_hue_ip%0A    %0A    @property%0A    def PHILIPS_HUE_USERNAME(self):%0A        if __philips_hue_username is None:%0A            client = secretmanager.SecretManagerServiceClient()%0A    
         secret_p
@@ -1589,32 +1589,36 @@
 atest')%0A        
+    
 response = clien
@@ -1662,24 +1662,30 @@
         
+   
+ __
 philips_
 username
@@ -1668,32 +1668,36 @@
       __philips_
+hue_
 username = respo
@@ -1749,53 +1749,21 @@
 urn 
-'http://%7B%7D/api/%7B%7D'.format(philips_ip, philips
+__philips_hue
 _use
@@ -1767,17 +1767,16 @@
 username
-)
 %0A    %0A%0A%0A

split url into ip and username