66
77from __future__ import annotations
88
9- from typing import Generator , List
9+ from typing import Generator , List , BinaryIO
1010
1111from c8y_api ._base_api import CumulocityRestApi
1212from c8y_api .model ._base import SimpleObject , CumulocityResource
@@ -22,22 +22,93 @@ class Application(SimpleObject):
2222 See also: https://cumulocity.com/api/#tag/Application-API
2323 """
2424 _parser = SimpleObjectParser ({
25- 'name' : 'name' ,
26- 'type' : 'type' ,
27- 'availability' : 'availability' })
28- _resource = 'application/applications'
25+ '_u_name' : 'name' ,
26+ '_u_type' : 'type' ,
27+ '_u_key' : 'key' ,
28+ '_u_availability' : 'availability' ,
29+ 'owner' : 'owner' ,
30+ 'manifest' : 'manifest' ,
31+ '_u_roles' : 'roles' ,
32+ '_u_required_roles' : 'requiredRoles' ,
33+ '_u_breadcrumbs' : 'breadcrumbs' ,
34+ '__u_content_security_policy' : 'contentSecurityPolicy' ,
35+ '_u_dynamic_options_url' : 'dynamicOptionsUrl' ,
36+ '__u_global_title' : 'globalTitle' ,
37+ '_u_legacy' : 'legacy' ,
38+ '_u_rightDrawer' : 'rightDrawer' ,
39+ '_u_upgrade' : 'upgrade'
40+ })
41+ _resource = '/application/applications'
42+ _accept = 'application/vnd.com.nsn.cumulocity.application+json'
43+ _not_updatable = ['owner' ]
2944
3045 EXTERNAL_TYPE = "EXTERNAL"
3146 HOSTED_TYPE = "HOSTED"
3247 MICROSERVICE_TYPE = "MICROSERVICE"
3348
34- def __init__ (self , c8y : CumulocityRestApi = None , name : str = None , type : str = None , availability : str = None ,
35- owner : str = None ):
49+ PRIVATE_AVAILABILITY = 'PRIVATE'
50+ MARKET_AVAILABILITY = 'MARKET'
51+
52+ def __init__ (self , c8y : CumulocityRestApi = None , name : str = None , key : str = None , type : str = None ,
53+ availability : str = None , context_path : str = None , manifest : dict = None ,
54+ roles : List [str ] = None , required_roles : List [str ] = None ,
55+ breadcrumbs : bool = None , content_security_policy : str = None ,
56+ dynamic_options_url : str = None , global_title : str = None ,
57+ legacy : bool = None , right_drawer : bool = None , upgrade : bool = None ):
58+ """Create a new Application object.
59+
60+ Args:
61+ c8y (CumulocityRestApi): Cumulocity connection reference; needs
62+ to be set for direct manipulation (create, delete)
63+ name (str): Name of the application
64+ key (str): Key to identify the application
65+ type (str): Type of the application
66+ availability (str): Application access level for tenants
67+ context_path (str): The path where the application is accessible
68+ manifest (dict): Microservice or web application manifest
69+ roles (str): List of roles provided by the application
70+ required_roles (str): List of roles required by the application
71+ breadcrumbs (bool): Whether the (web) application uses breadcrumbs
72+ content_security_policy (str): The content security policy of the application
73+ dynamic_options_url (str): A URL to a JSON object with dynamic content options
74+ global_title (str): The global title of the application
75+ legacy (bool): Whether the (web) application is of legacy type
76+ right_drawer (bool): Whether the (web) application uses the
77+ right hand context menu
78+ upgrade (bool): Whether the (web) application uses both Angular and AngularJS
79+ """
3680 super ().__init__ (c8y = c8y )
37- self .name = name
38- self .type = type
39- self .availability = availability
40- self .owner = owner
81+ self ._u_name = name
82+ self ._u_type = type
83+ self ._u_key = key
84+ self .owner = None
85+ self ._u_availability = availability
86+ self ._u_contextPath = context_path
87+ self .manifest = manifest
88+ self ._u_roles = roles
89+ self ._u_required_roles = required_roles
90+ self ._u_breadcrumbs = breadcrumbs
91+ self .__u_content_security_policy = content_security_policy
92+ self ._u_dynamic_options_url = dynamic_options_url
93+ self .__u_global_title = global_title
94+ self ._u_legacy = legacy
95+ self ._u_rightDrawer = right_drawer
96+ self ._u_upgrade = upgrade
97+
98+ name = SimpleObject .UpdatableProperty ('_u_name' )
99+ type = SimpleObject .UpdatableProperty ('_u_type' )
100+ key = SimpleObject .UpdatableProperty ('_u_key' )
101+ availability = SimpleObject .UpdatableProperty ('_u_availability' )
102+ context_path = SimpleObject .UpdatableProperty ('_u_contextPath' )
103+ roles = SimpleObject .UpdatableProperty ('_u_roles' )
104+ required_roles = SimpleObject .UpdatableProperty ('_u_required_roles' )
105+ breadcrumbs = SimpleObject .UpdatableProperty ('_u_breadcrumbs' )
106+ content_security_policy = SimpleObject .UpdatableProperty ('__u_content_security_policy' )
107+ dynamic_options_url = SimpleObject .UpdatableProperty ('_u_dynamic_options_url' )
108+ global_title = SimpleObject .UpdatableProperty ('__u_global_title' )
109+ legacy = SimpleObject .UpdatableProperty ('_u_legacy' )
110+ right_drawer = SimpleObject .UpdatableProperty ('_u_rightDrawer' )
111+ upgrade = SimpleObject .UpdatableProperty ('_u_upgrade' )
41112
42113 @classmethod
43114 def from_json (cls , json : dict ) -> Application :
@@ -46,6 +117,30 @@ def from_json(cls, json: dict) -> Application:
46117 obj .owner = json ['owner' ]['tenant' ]['id' ]
47118 return obj
48119
120+ def create (self ) -> Application :
121+ """Create the Application within the database.
122+
123+ Returns:
124+ A fresh Application object representing what was
125+ created within the database (including the ID).
126+ """
127+ return super ()._create ()
128+
129+ def update (self ) -> Application :
130+ """Update the Application within the database.
131+
132+ Note: This will only send changed fields to increase performance.
133+
134+ Returns:
135+ A fresh Application object representing what the updated
136+ state within the database (including the ID).
137+ """
138+ return super ()._update ()
139+
140+ def delete (self ):
141+ """Delete the Application within the database."""
142+ super ()._delete ()
143+
49144
50145class Applications (CumulocityResource ):
51146 """Provides access to the Application API.
@@ -79,7 +174,7 @@ def select(self, name: str = None, type: str = None, owner: str = None, user: st
79174 fetched from the database as long there is a consumer for them.
80175
81176 All parameters are considered to be filters, limiting the result set
82- to objects which meet the filters specification. Filters can be
177+ to objects which meet the filters' specification. Filters can be
83178 combined (within reason).
84179
85180 Args:
@@ -121,3 +216,14 @@ def get_all(self, name: str = None, type: str = None, owner: str = None, user: s
121216 return list (self .select (name = name , type = type , owner = owner , user = user ,
122217 tenant = tenant , subscriber = subscriber , provided_for = provided_for ,
123218 limit = limit , page_size = page_size ))
219+
220+ def upload_attachment (self , application_id : str , file : str | BinaryIO ):
221+ """Upload application binary for a registered application.
222+
223+ Args:
224+ application_id (str): The Cumulocity object ID of the application
225+ file (str|BinaryIO): File path or file-like object to upload.
226+
227+ See also: https://cumulocity.com/api/#tag/Application-binaries
228+ """
229+ self .c8y .post_file (self .build_object_path (application_id ) + '/binaries' , file = file )
0 commit comments