Skip to content

Commit

Permalink
Merge branch 'staging' of https://github.com/mindsdb/mindsdb into sta…
Browse files Browse the repository at this point in the history
…ging
  • Loading branch information
StpMax committed Feb 1, 2023
2 parents 33920a8 + 97a0ee6 commit 715220a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mindsdb/api/http/namespaces/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get(self):
config = Config()
return {
'auth': {
'required': config['auth']['required'],
'http_auth_enabled': config['auth']['http_auth_enabled'],
'username': config['auth']['username'],
'password': config['auth']['password']
}
Expand Down
8 changes: 5 additions & 3 deletions mindsdb/api/http/namespaces/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def check_auth() -> bool:
bool: True if user authentication is approved
'''
config = Config()
if config['auth']['required'] is False:
if config['auth']['http_auth_enabled'] is False:
return True
return session.get('username') == config['auth']['username']

Expand Down Expand Up @@ -96,14 +96,16 @@ def get(self):
environment = 'cloud'
elif config.get('aws_marketplace', False):
environment = 'aws_marketplace'
else:
environment = 'local'

auth_provider = 'local' if config['auth']['required'] else 'disabled'
auth_provider = 'local' if config['auth']['http_auth_enabled'] else 'disabled'

resp = {
'environment': environment,
'auth': {
'confirmed': check_auth(),
'required': config['auth']['required'],
'http_auth_enabled': config['auth']['http_auth_enabled'],
'provider': auth_provider
}
}
Expand Down
2 changes: 1 addition & 1 deletion mindsdb/api/http/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def before_request():

# region routes where auth is required
if (
config['auth']['required'] is True
config['auth']['http_auth_enabled'] is True
and any(request.path.startswith(f'/api{ns.path}') for ns in protected_namespaces)
and check_auth() is False
):
Expand Down
17 changes: 10 additions & 7 deletions mindsdb/utilities/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import json
from copy import deepcopy
from pathlib import Path

from mindsdb.utilities.fs import create_directory, get_or_create_data_dir

Expand Down Expand Up @@ -35,13 +36,15 @@ def __init__(self):
if self.use_docker_env:
self.use_docker_env = True

current_config_mtime = os.path.getmtime(self.config_path)
if (
config is None
or config_mtime != current_config_mtime
):
if Path(self.config_path).is_file():
current_config_mtime = os.path.getmtime(self.config_path)
if config_mtime != current_config_mtime:
config = self.init_config()
config_mtime = current_config_mtime

if config is None:
config = self.init_config()
config_mtime = current_config_mtime

self._config = config

def init_config(self):
Expand Down Expand Up @@ -94,7 +97,7 @@ def init_config(self):
'storage_dir': os.environ['MINDSDB_STORAGE_DIR'],
'paths': paths,
'auth': {
'required': False,
'http_auth_enabled': False,
'username': 'mindsdb',
'password': ''
},
Expand Down
14 changes: 7 additions & 7 deletions tests/integration_tests/flows/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,25 @@ def test_auth(self):

response = session.get(f'{HTTP_API_ROOT}/status')
assert response.status_code == 200
assert response.json()['auth']['required'] is False
assert response.json()['auth']['http_auth_enabled'] is False

response = session.get(f'{HTTP_API_ROOT}/config/')
assert response.status_code == 200
assert response.json()['auth']['required'] is False
assert response.json()['auth']['http_auth_enabled'] is False

response = session.get(f'{HTTP_API_ROOT}/tree/')
assert response.status_code == 200

response = session.put(f'{HTTP_API_ROOT}/config/', json={
'required': True,
'http_auth_enabled': True,
'username': '',
'password': ''
})
assert response.status_code == 400

response = session.put(f'{HTTP_API_ROOT}/config/', json={
'auth': {
'required': True,
'http_auth_enabled': True,
'username': 'mindsdb',
'password': 'mindsdb'
}
Expand All @@ -134,7 +134,7 @@ def test_auth(self):

response = session.get(f'{HTTP_API_ROOT}/status')
assert response.status_code == 200
assert response.json()['auth']['required'] is True
assert response.json()['auth']['http_auth_enabled'] is True

response = session.get(f'{HTTP_API_ROOT}/tree/')
assert response.status_code == 403
Expand All @@ -151,15 +151,15 @@ def test_auth(self):

response = session.put(f'{HTTP_API_ROOT}/config/', json={
'auth': {
'required': False,
'http_auth_enabled': False,
'username': 'mindsdb',
'password': 'mindsdb'
}
})

response = session.get(f'{HTTP_API_ROOT}/status')
assert response.status_code == 200
assert response.json()['auth']['required'] is False
assert response.json()['auth']['http_auth_enabled'] is False

def test_gui_is_served(self):
"""
Expand Down

0 comments on commit 715220a

Please sign in to comment.