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

Open-MSS / MSS / 10653470575

01 Sep 2024 11:06AM CUT coverage: 70.141% (+0.03%) from 70.113%
10653470575

Pull #2499

github

web-flow
Merge bc9f5bb21 into 0b95679f6
Pull Request #2499: renamed and refactored names for mscolab

10 of 28 new or added lines in 6 files covered. (35.71%)

1 existing line in 1 file now uncovered.

13958 of 19900 relevant lines covered (70.14%)

0.7 hits per line

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

0.0
/mslib/utils/migration/update_json_file_to_version_eight.py
1
# -*- coding: utf-8 -*-
2
"""
3

4
    mslib.utils.update_json_file_to_version_eight
5
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6

7
    updates the old attributes to the new attributes and creates credentials in keyring
8

9
    This file is part of MSS.
10

11
    :copyright: Copyright 2008-2014 Deutsches Zentrum fuer Luft- und Raumfahrt e.V.
12
    :copyright: Copyright 2011-2014 Marc Rautenhaus (mr)
13
    :copyright: Copyright 2016-2024 by the MSS team, see AUTHORS.
14
    :license: APACHE-2.0, see LICENSE for details.
15

16
    Licensed under the Apache License, Version 2.0 (the "License");
17
    you may not use this file except in compliance with the License.
18
    You may obtain a copy of the License at
19

20
       http://www.apache.org/licenses/LICENSE-2.0
21

22
    Unless required by applicable law or agreed to in writing, software
23
    distributed under the License is distributed on an "AS IS" BASIS,
24
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
    See the License for the specific language governing permissions and
26
    limitations under the License.
27
"""
28

29
import fs
×
30
import json
×
31
import logging
×
32
import copy
×
33

34
from keyring.errors import NoKeyringError, PasswordSetError, InitError
×
35
from packaging import version
×
36
from mslib import __version__
×
37
from mslib.utils.auth import save_password_to_keyring
×
38
from mslib.utils.migration.config_before_eight import read_config_file as read_config_file_before_eight
×
39
from mslib.utils.migration.config_before_eight import config_loader as config_loader_before_eight
×
40
from mslib.utils.config import modify_config_file
×
41
from mslib.utils.config import read_config_file, config_loader
×
42
from mslib.msui.constants import MSUI_SETTINGS
×
43

44

45
class JsonConversion:
×
46
    def __init__(self):
×
47
        read_config_file_before_eight()
×
48
        self.wms_login = config_loader_before_eight(dataset="WMS_login")
×
49
        self.msc_login = config_loader_before_eight(dataset="MSC_login")
×
50
        self.MSCOLAB_mailid = config_loader_before_eight(dataset="MSCOLAB_mailid")
×
51
        self.MSCOLAB_password = config_loader_before_eight(dataset="MSCOLAB_password")
×
52

53
    def change_parameters(self):
×
54
        """
55
        adds new parameters and store passwords in the keyring
56
        """
57
        if version.parse(__version__) > version.parse('7.1.0') and version.parse(__version__) < version.parse('9.0.0'):
×
58
            http_auth_login_data = {}
×
59
            for url in self.wms_login.keys():
×
60
                auth_username, auth_password = self.wms_login[url]
×
61
                http_auth_login_data[url] = auth_username
×
62
                try:
×
63
                    save_password_to_keyring(url, auth_username, auth_password)
×
64
                except (NoKeyringError, PasswordSetError, InitError) as ex:
×
65
                    logging.warning("Can't use Keyring on your system to store credentials: %s" % ex)
×
66

67
            for url in self.msc_login.keys():
×
68
                auth_username, auth_password = self.msc_login[url]
×
69
                http_auth_login_data[url] = auth_username
×
70
                try:
×
71
                    save_password_to_keyring(url, auth_username, auth_password)
×
72
                except (NoKeyringError, PasswordSetError, InitError) as ex:
×
73
                    logging.warning("Can't use Keyring on your system to store credentials: %s" % ex)
×
74

75
            data_to_save_in_config_file = {
×
76
                "MSS_auth": http_auth_login_data
77
            }
78
            try:
×
79
                save_password_to_keyring(service_name="MSCOLAB",
×
80
                                         username=self.MSCOLAB_mailid, password=self.MSCOLAB_password)
81
            except (NoKeyringError, PasswordSetError, InitError) as ex:
×
82
                logging.warning("Can't use Keyring on your system to store credentials: %s" % ex)
×
83

84
            filename = MSUI_SETTINGS.replace('\\', '/')
×
85
            dir_name, file_name = fs.path.split(filename)
×
86
            # create the backup file
87
            with fs.open_fs(dir_name) as _fs:
×
88
                fs.copy.copy_file(_fs, file_name, _fs, f"{file_name}.bak")
×
89
            # add the modification
90
            modify_config_file(data_to_save_in_config_file)
×
91
            # read new file
92
            read_config_file()
×
93
            # Todo move this to a separate function to utils
94
            # get all defaults
95
            default_options = config_loader(default=True)
×
96
            # get the data from the local file
97
            json_data = config_loader()
×
98
            save_data = copy.deepcopy(json_data)
×
99

100
            # remove everything we have as defaults
101
            for key in json_data:
×
102
                if json_data[key] == default_options[key] or json_data[key] == {} or json_data[key] == []:
×
103
                    del save_data[key]
×
104

105
            # write new data
106
            with fs.open_fs(dir_name) as _fs:
×
107
                _fs.writetext(file_name, json.dumps(save_data, indent=4))
×
108

109

110
if __name__ == "__main__":
111
    if version.parse(__version__) >= version.parse('8.0.0'):
112
        new_version = JsonConversion()
113
        new_version.change_parameters()
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

© 2025 Coveralls, Inc