99from freight .checks .utils import parse_checks_config
1010from freight .config import db , queue
1111from freight .environments .utils import parse_environments_config
12- from freight .models import App , Repository
12+ from freight .models import App , Repository , TaskConfig , TaskConfigType
1313from freight .notifiers .utils import parse_notifiers_config
1414from freight .providers .utils import parse_provider_config
1515
@@ -20,12 +20,19 @@ def get(self, app):
2020 if app is None :
2121 return self .error ('Invalid app' , name = 'invalid_resource' , status_code = 404 )
2222
23+ deploy_config = TaskConfig .query .filter (
24+ TaskConfig .app_id == app .id ,
25+ TaskConfig .type == TaskConfigType .deploy ,
26+ ).first ()
27+ if deploy_config is None :
28+ return self .error ('Missing deploy config' , name = 'missing_conf' , status_code = 404 )
29+
2330 context = serialize (app )
2431 context .update ({
25- 'provider' : app .provider ,
26- 'provider_config' : app .provider_config ,
27- 'notifiers' : app .notifiers ,
28- 'checks' : app .checks ,
32+ 'provider' : deploy_config .provider ,
33+ 'provider_config' : deploy_config .provider_config ,
34+ 'notifiers' : deploy_config .notifiers ,
35+ 'checks' : deploy_config .checks ,
2936 })
3037
3138 return self .respond (context )
@@ -49,27 +56,38 @@ def put(self, app):
4956 if app is None :
5057 return self .error ('Invalid app' , name = 'invalid_resource' , status_code = 404 )
5158
59+ # For backwards compatibility, we assume that we need a deploy TaskConfig
60+ # on the app at all times.
61+ deploy_config = TaskConfig .query .filter (
62+ TaskConfig .app_id == app .id ,
63+ TaskConfig .type == TaskConfigType .deploy ,
64+ ).first ()
65+ if deploy_config is None :
66+ deploy_config = TaskConfig (app_id = app .id , type = TaskConfigType .deploy )
67+ db .session .add (deploy_config )
68+ db .session .flush ()
69+
5270 if args .provider or args .provider_config :
5371 if args .provider is not None :
5472 provider = args .provider
5573 else :
56- provider = app .provider
74+ provider = deploy_config .provider
5775
5876 if args .provider_config is not None :
5977 provider_config = args .provider_config
6078 else :
61- provider_config = app .provider_config
79+ provider_config = deploy_config .provider_config
6280
63- app .provider = provider
64- app .data ['provider_config' ] = parse_provider_config (
81+ deploy_config .provider = provider
82+ deploy_config .data ['provider_config' ] = parse_provider_config (
6583 provider , provider_config
6684 )
6785
6886 if args .notifiers is not None :
69- app .data ['notifiers' ] = parse_notifiers_config (args .notifiers )
87+ deploy_config .data ['notifiers' ] = parse_notifiers_config (args .notifiers )
7088
7189 if args .checks is not None :
72- app .data ['checks' ] = parse_checks_config (args .checks )
90+ deploy_config .data ['checks' ] = parse_checks_config (args .checks )
7391
7492 if args .environments is not None :
7593 app .data ['environments' ] = parse_environments_config (args .environments )
@@ -89,14 +107,15 @@ def put(self, app):
89107 app .repository_id = repo .id
90108
91109 db .session .add (app )
110+ db .session .add (deploy_config )
92111 db .session .commit ()
93112
94113 context = serialize (app )
95114 context .update ({
96- 'provider' : app .provider ,
97- 'provider_config' : app .provider_config ,
98- 'notifiers' : app .notifiers ,
99- 'checks' : app .checks ,
115+ 'provider' : deploy_config .provider ,
116+ 'provider_config' : deploy_config .provider_config ,
117+ 'notifiers' : deploy_config .notifiers ,
118+ 'checks' : deploy_config .checks ,
100119 })
101120
102121 return self .respond (context )
0 commit comments