• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Wirecloud / wirecloud / 8191877055

07 Mar 2024 04:55PM UTC coverage: 88.984% (+0.06%) from 88.923%
8191877055

push

github

web-flow
Merge pull request #534 from oxixes/mac-v2

Add v2-web components based widgets and get rid of iframes in operators.

7798 of 9095 branches covered (85.74%)

Branch coverage included in aggregate %.

222 of 242 new or added lines in 9 files covered. (91.74%)

119 existing lines in 11 files now uncovered.

21193 of 23485 relevant lines covered (90.24%)

32.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.55
src/wirecloud/fiware/plugins.py
1
# -*- coding: utf-8 -*-
2

3
# Copyright (c) 2012-2017 Conwet Lab., Universidad Politécnica de Madrid
4
# Copyright (c) 2019 Future Internet Consulting and Development Solutions S.L.
5

6
# This file is part of Wirecloud.
7

8
# Wirecloud is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
12

13
# Wirecloud is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU Affero General Public License for more details.
17

18
# You should have received a copy of the GNU Affero General Public License
19
# along with Wirecloud.  If not, see <http://www.gnu.org/licenses/>.
20

21
import os
15✔
22

23
from django.conf import settings
15✔
24
from django.conf.urls import url
15✔
25
from django.utils.translation import ugettext_lazy as _
15✔
26
from django.views.decorators.cache import cache_page
15✔
27

28
from wirecloud.catalogue.models import CatalogueResource
15✔
29
from wirecloud.commons.utils.wgt import WgtFile
15✔
30
from wirecloud.platform.core.plugins import get_version_hash
15✔
31
from wirecloud.platform.localcatalogue.utils import install_component
15✔
32
from wirecloud.platform.markets.utils import MarketManager
15✔
33
from wirecloud.platform.plugins import WirecloudPlugin
15✔
34
from wirecloud.platform.workspace.utils import create_workspace, delete_workspace
15✔
35

36
import wirecloud.fiware
15✔
37

38
try:
15✔
39
    from social_django.utils import BACKENDS, get_backend, load_strategy
15✔
40
    FIWARE_SOCIAL_AUTH_BACKEND = get_backend(BACKENDS, 'fiware')(load_strategy())
×
41

42
    IDM_SUPPORT_ENABLED = 'wirecloud.fiware' in settings.INSTALLED_APPS and 'social_django' in settings.INSTALLED_APPS \
×
43
        and getattr(settings, 'SOCIAL_AUTH_FIWARE_KEY', None) is not None and getattr(settings, 'SOCIAL_AUTH_FIWARE_SECRET', None) is not None
44

45
except Exception:
15✔
46
    IDM_SUPPORT_ENABLED = False
15✔
47

48

49
BASE_PATH = os.path.dirname(__file__)
15✔
50
BAE_BROWSER_WIDGET = os.path.join(BASE_PATH, 'initial', 'CoNWeT_bae-browser_0.1.1.wgt')
15✔
51
BAE_DETAILS_WIDGET = os.path.join(BASE_PATH, 'initial', 'CoNWeT_bae-details_0.1.1.wgt')
15✔
52
BAE_SEARCH_FILTERS_WIDGET = os.path.join(BASE_PATH, 'initial', 'CoNWeT_bae-search-filters_0.1.1.wgt')
15✔
53
BAE_MASHUP = os.path.join(BASE_PATH, 'initial', 'CoNWeT_bae-marketplace_0.1.1.wgt')
15✔
54

55

56
def auth_fiware_token(auth_type, token):
15✔
57

58
    from social_django.models import UserSocialAuth
12✔
59
    user_data = FIWARE_SOCIAL_AUTH_BACKEND.user_data(token)
12✔
60
    return UserSocialAuth.objects.get(provider='fiware', uid=user_data['username']).user
12✔
61

62

63
class FIWAREBAEManager(MarketManager):
15✔
64

65
    _user = None
15✔
66
    _name = None
15✔
67
    _options = None
15✔
68

69
    def __init__(self, user, name, options):
15✔
70

71
        self._user = user
×
72
        self._name = name
×
73
        self._options = options
×
74

75
    def create(self, user):
15✔
76
        create_workspace(
×
77
            user,
78
            mashup="CoNWeT/bae-marketplace/0.1.1",
79
            new_name=self._options['name'],
80
            preferences={'server_url': self._options['url']},
81
            searchable=False,
82
            public=self._options['public']
83
        )
84

85
    def delete(self):
15✔
86
        delete_workspace(user=self._user, name=self._name)
×
87

88

89
class FiWarePlugin(WirecloudPlugin):
15✔
90

91
    features = {
15✔
92
        'FIWARE': wirecloud.fiware.__version__,
93
        'NGSI': '1.4.1',
94
        'ObjectStorage': '0.5',
95
    }
96

97
    def get_market_classes(self):
15✔
98
        return {
13✔
99
            'fiware-bae': FIWAREBAEManager,
100
        }
101

102
    def get_scripts(self, view):
15✔
103

104
        common = (
13✔
105
            'js/NGSI/NGSI.min.js',
106
            'js/NGSI/NGSIManager.js',
107
            'js/WirecloudAPI/NGSIAPI.js',
108
            'js/ObjectStorage/OpenStackManager.js',
109
            'js/ObjectStorage/ObjectStorageAPI.js'
110
        )
111

112
        if view == 'classic':
13✔
113
            return common + (
13✔
114
                "js/wirecloud/FiWare.js",
115
                "js/wirecloud/FiWare/BusinessAPIEcosystemView.js",
116
            )
117
        else:
118
            return common
13✔
119

120
    def get_urls(self):
15✔
121

122
        if IDM_SUPPORT_ENABLED:
15✔
123
            from wirecloud.fiware.views import oauth_discovery
12✔
124
            return (
12✔
125
                url('^.well-known/oauth$', cache_page(7 * 24 * 60 * 60, key_prefix='well-known-oauth-%s' % get_version_hash())(oauth_discovery), name='oauth.discovery'),
126
            )
127
        else:
128
            return ()
15✔
129

130
    def get_platform_context_definitions(self):
15✔
131
        return {
13✔
132
            'fiware_version': {
133
                'label': _('FIWARE version'),
134
                'description': _('FIWARE version of the platform'),
135
            },
136
            'fiware_token_available': {
137
                'label': _('FIWARE token available'),
138
                'description': _('Indicates if the current user has associated a FIWARE auth token that can be used for accessing other FIWARE resources'),
139
            },
140
        }
141

142
    def get_platform_context_current_values(self, user, **kwargs):
15✔
143
        # Work around bug when running manage.py compress
144
        import wirecloud.fiware
13✔
145

146
        fiware_token_available = IDM_SUPPORT_ENABLED and user.is_authenticated and user.social_auth.filter(provider='fiware').exists()
13✔
147
        return {
13✔
148
            'fiware_version': wirecloud.fiware.__version__,
149
            'fiware_token_available': fiware_token_available
150
        }
151

152
    def get_constants(self):
15✔
153
        # Work around bug when running manage.py compress
154
        import wirecloud.fiware
13✔
155

156
        constants = {
13✔
157
            "FIWARE_HOME": getattr(settings, "FIWARE_HOME", wirecloud.fiware.DEFAULT_FIWARE_HOME),
158
            'FIWARE_PORTALS': getattr(settings, "FIWARE_PORTALS", ())
159
        }
160

161
        if IDM_SUPPORT_ENABLED:
13✔
162
            global FIWARE_SOCIAL_AUTH_BACKEND
163
            import wirecloud.fiware.social_auth_backend
12✔
164
            constants["FIWARE_OFFICIAL_PORTAL"] = getattr(settings, "FIWARE_OFFICIAL_PORTAL", False)
12✔
165
            constants["FIWARE_IDM_SERVER"] = FIWARE_SOCIAL_AUTH_BACKEND.FIWARE_IDM_SERVER
12✔
166

167
        return constants
13✔
168

169
    def get_widget_api_extensions(self, view, features):
15✔
170
        files = []
13✔
171

172
        if 'NGSI' in features:
13!
UNCOV
173
            files.append('js/WirecloudAPI/NGSIAPI.js')
×
174

175
        if 'ObjectStorage' in features:
13!
UNCOV
176
            files.append('js/ObjectStorage/ObjectStorageAPI.js')
×
177

178
        return files
13✔
179

180
    def get_operator_api_extensions(self, view, features):
15✔
181
        files = []
1✔
182

183
        if 'NGSI' in features:
1!
UNCOV
184
            files.append('js/WirecloudAPI/NGSIAPI.js')
×
185

186
        if 'ObjectStorage' in features:
1!
UNCOV
187
            files.append('js/ObjectStorage/ObjectStorageAPI.js')
×
188

189
        return files
1✔
190

191
    def get_proxy_processors(self):
15✔
192
        if not IDM_SUPPORT_ENABLED:
13!
193
            return ()
13✔
194

UNCOV
195
        return ('wirecloud.fiware.proxy.IDMTokenProcessor',)
×
196

197
    def get_django_template_context_processors(self):
15✔
198
        context = {
13✔
199
            "FIWARE_HOME": getattr(settings, "FIWARE_HOME", wirecloud.fiware.DEFAULT_FIWARE_HOME),
200
            "FIWARE_OFFICIAL_PORTAL": getattr(settings, "FIWARE_OFFICIAL_PORTAL", False),
201
            "FIWARE_PORTALS": getattr(settings, "FIWARE_PORTALS", ()),
202
        }
203

204
        if IDM_SUPPORT_ENABLED:
13!
UNCOV
205
            context["FIWARE_IDM_SERVER"] = getattr(settings, "FIWARE_IDM_SERVER", wirecloud.fiware.social_auth_backend.FIWARE_LAB_IDM_SERVER)
×
UNCOV
206
            context["FIWARE_IDM_PUBLIC_URL"] = getattr(settings, "FIWARE_IDM_PUBLIC_URL", wirecloud.fiware.social_auth_backend.FIWARE_LAB_IDM_SERVER)
×
207
        else:
208
            context["FIWARE_IDM_SERVER"] = None
13✔
209
            context["FIWARE_IDM_PUBLIC_URL"] = None
13✔
210

211
        return context
13✔
212

213
    def get_api_auth_backends(self):
15✔
214

215
        if IDM_SUPPORT_ENABLED:
12!
UNCOV
216
            return {
×
217
                'Bearer': auth_fiware_token,
218
            }
219
        else:
220
            return {}
12✔
221

222
    def populate(self, wirecloud_user, log):
15✔
223
        updated = False
13✔
224

225
        if not CatalogueResource.objects.filter(vendor="CoNWeT", short_name="bae-browser", version="0.1.1", public=True).exists():
13!
226
            updated = True
13✔
227
            log('Installing bae-browser widget... ', 1, ending='')
13✔
228
            install_component(WgtFile(BAE_BROWSER_WIDGET), public=True)
13✔
229
            log('DONE', 1)
13✔
230

231
        if not CatalogueResource.objects.filter(vendor="CoNWeT", short_name="bae-details", version="0.1.1", public=True).exists():
13!
232
            updated = True
13✔
233
            log('Installing bae-details widget... ', 1, ending='')
13✔
234
            install_component(WgtFile(BAE_DETAILS_WIDGET), public=True)
13✔
235
            log('DONE', 1)
13✔
236

237
        if not CatalogueResource.objects.filter(vendor="CoNWeT", short_name="bae-search-filters", version="0.1.1", public=True).exists():
13!
238
            updated = True
13✔
239
            log('Installing bae-search-filters widget... ', 1, ending='')
13✔
240
            install_component(WgtFile(BAE_SEARCH_FILTERS_WIDGET), public=True)
13✔
241
            log('DONE', 1)
13✔
242

243
        if not CatalogueResource.objects.filter(vendor="CoNWeT", short_name="bae-marketplace", version="0.1.1", public=True).exists():
13!
244
            updated = True
13✔
245
            log('Installing bae-marketplace mashup... ', 1, ending='')
13✔
246
            install_component(WgtFile(BAE_MASHUP), public=True)
13✔
247
            log('DONE', 1)
13✔
248

249
        return updated
13✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc