@@ -14,6 +14,10 @@ def __init__(self, manifest_path, app_name='my-predix-app'):
1414 self .manifest_path = os .path .expanduser (manifest_path )
1515 self .app_name = app_name
1616
17+ # App may have a client
18+ self .client_id = None
19+ self .client_secret = None
20+
1721 # Read or Generate a manifest file
1822 if os .path .exists (self .manifest_path ):
1923 manifest = self .read_manifest ()
@@ -89,17 +93,144 @@ def get_client_id(self):
8993 needed scopes and authorities for the services
9094 in this manifest.
9195 """
92- if 'PREDIX_APP_CLIENT_ID' not in self .manifest ['env' ]:
93- raise ValueError ('UAA client id must be added to manifest.' )
96+ key = 'predix.security.uaa.client_id'
97+ if key not in self .manifest ['env' ]:
98+ raise ValueError ("%s undefined in manifest." % key )
9499
95- return self .manifest ['env' ]['PREDIX_APP_CLIENT_ID' ]
100+ self .client_id = self .manifest ['env' ][key ]
101+ return self .client_id
96102
97103 def get_client_secret (self ):
98104 """
99105 Return the client secret that should correspond with
100106 the client id.
101107 """
102- if 'PREDIX_APP_CLIENT_SECRET' not in self .manifest ['env' ]:
103- raise ValueError ('UAA client secret must be added to manifest.' )
108+ key = 'predix.security.uaa.client_secret'
109+ if key not in self .manifest ['env' ]:
110+ raise ValueError ("%s must be added to manifest." % key )
111+
112+ self .client_secret = self .manifest ['env' ][key ]
113+ return self .client_secret
114+
115+ def create_timeseries (self ):
116+ """
117+ Creates an instance of the Time Series Service.
118+ """
119+ import predix .admin .timeseries
120+ ts = predix .admin .timeseries .TimeSeries ()
121+ ts .create ()
122+
123+ client_id = self .get_client_id ()
124+ if client_id :
125+ ts .grant_client (client_id )
126+
127+ ts .add_to_manifest (self .manifest_path )
128+ return ts
129+
130+ def get_timeseries (self , * args , ** kwargs ):
131+ """
132+ Returns an instance of the Time Series Service.
133+ """
134+ import predix .data .timeseries
135+ ts = predix .data .timeseries .TimeSeries (* args , ** kwargs )
136+ return ts
137+
138+ def create_asset (self ):
139+ """
140+ Creates an instance of the Asset Service.
141+ """
142+ import predix .admin .asset
143+ asset = predix .admin .asset .Asset ()
144+ asset .create ()
145+
146+ client_id = self .get_client_id ()
147+ if client_id :
148+ asset .grant_client (client_id )
149+
150+ asset .add_to_manifest (self .manifest_path )
151+ return asset
152+
153+ def get_asset (self ):
154+ """
155+ Returns an instance of the Asset Service.
156+ """
157+ import predix .data .asset
158+ asset = predix .data .asset .Asset ()
159+ return asset
160+
161+ def create_uaa (self , admin_secret ):
162+ """
163+ Creates an instance of UAA Service.
164+ """
165+ import predix .admin .uaa
166+ uaa = predix .admin .uaa .UserAccountAuthentication ()
167+ if not uaa .exists ():
168+ uaa .create (admin_secret )
169+ uaa .add_to_manifest (self .manifest_path )
170+ return uaa
104171
105- return self .manifest ['env' ]['PREDIX_APP_CLIENT_SECRET' ]
172+ def create_client (self , client_id , client_secret ):
173+ """
174+ Create a client and add it to the manifest.
175+ """
176+ import predix .admin .uaa
177+ uaa = predix .admin .uaa .UserAccountAuthentication ()
178+ uaa .create_client (client_id , client_secret )
179+ uaa .add_client_to_manifest (client_id , client_secret ,
180+ self .manifest_path )
181+
182+ def get_uaa (self ):
183+ """
184+ Returns an insstance of the UAA Service.
185+ """
186+ import predix .security .uaa
187+ uaa = predix .security .uaa .UserAccountAuthentication ()
188+ return uaa
189+
190+ def create_acs (self ):
191+ """
192+ Creates an instance of the Asset Service.
193+ """
194+ import predix .admin .acs
195+ acs = predix .admin .acs .AccessControl ()
196+ acs .create ()
197+
198+ client_id = self .get_client_id ()
199+ if client_id :
200+ acs .grant_client (client_id )
201+
202+ acs .grant_client (client_id )
203+ acs .add_to_manifest (self .manifest_path )
204+ return acs
205+
206+ def get_acs (self ):
207+ """
208+ Returns an instance of the Asset Control Service.
209+ """
210+ import predix .security .acs
211+ acs = predix .security .acs .AccessControl ()
212+ return acs
213+
214+ def create_weather (self ):
215+ """
216+ Creates an instance of the Asset Service.
217+ """
218+ import predix .admin .weather
219+ weather = predix .admin .weather .WeatherForecast ()
220+ weather .create ()
221+
222+ client_id = self .get_client_id ()
223+ if client_id :
224+ weather .grant_client (client_id )
225+
226+ weather .grant_client (client_id )
227+ weather .add_to_manifest (self .manifest_path )
228+ return weather
229+
230+ def get_weather (self ):
231+ """
232+ Returns an instance of the Weather Service.
233+ """
234+ import predix .data .weather
235+ weather = predix .data .weather .WeatherForecast ()
236+ return weather
0 commit comments