version v3
This commit is contained in:
Binary file not shown.
@@ -563,4 +563,31 @@ def generate_password_reset_token(current_user, user_id):
|
||||
'reset_url': reset_url,
|
||||
'expires_at': reset_token.expires_at.isoformat(),
|
||||
'user_email': user.email
|
||||
})
|
||||
})
|
||||
|
||||
# Version Information
|
||||
@admin_api.route('/version-info', methods=['GET'])
|
||||
@csrf.exempt
|
||||
@token_required
|
||||
def get_version_info(current_user):
|
||||
"""Get version information from environment variables"""
|
||||
try:
|
||||
version_info = {
|
||||
'app_version': os.environ.get('APP_VERSION', 'unknown'),
|
||||
'git_commit': os.environ.get('GIT_COMMIT', 'unknown'),
|
||||
'git_branch': os.environ.get('GIT_BRANCH', 'unknown'),
|
||||
'deployed_at': os.environ.get('DEPLOYED_AT', 'unknown'),
|
||||
'ismaster': os.environ.get('ISMASTER', 'false'),
|
||||
'port': os.environ.get('PORT', 'unknown')
|
||||
}
|
||||
|
||||
return jsonify(version_info)
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Error getting version info: {str(e)}")
|
||||
return jsonify({
|
||||
'error': str(e),
|
||||
'app_version': 'unknown',
|
||||
'git_commit': 'unknown',
|
||||
'git_branch': 'unknown',
|
||||
'deployed_at': 'unknown'
|
||||
}), 500
|
||||
@@ -625,6 +625,93 @@ def init_routes(main_bp):
|
||||
'is_valid': is_valid
|
||||
})
|
||||
|
||||
@main_bp.route('/instances/<int:instance_id>/version-info')
|
||||
@login_required
|
||||
@require_password_change
|
||||
def instance_version_info(instance_id):
|
||||
if not os.environ.get('MASTER', 'false').lower() == 'true':
|
||||
return jsonify({'error': 'Unauthorized'}), 403
|
||||
|
||||
instance = Instance.query.get_or_404(instance_id)
|
||||
|
||||
# Check if instance has a connection token
|
||||
if not instance.connection_token:
|
||||
return jsonify({
|
||||
'error': 'Instance not authenticated',
|
||||
'deployed_version': instance.deployed_version,
|
||||
'deployed_branch': instance.deployed_branch
|
||||
})
|
||||
|
||||
try:
|
||||
# Get JWT token using the connection token
|
||||
jwt_response = requests.post(
|
||||
f"{instance.main_url.rstrip('/')}/api/admin/management-token",
|
||||
headers={
|
||||
'X-API-Key': instance.connection_token,
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
timeout=5
|
||||
)
|
||||
|
||||
if jwt_response.status_code != 200:
|
||||
return jsonify({
|
||||
'error': 'Failed to authenticate with instance',
|
||||
'deployed_version': instance.deployed_version,
|
||||
'deployed_branch': instance.deployed_branch
|
||||
})
|
||||
|
||||
jwt_data = jwt_response.json()
|
||||
jwt_token = jwt_data.get('token')
|
||||
|
||||
if not jwt_token:
|
||||
return jsonify({
|
||||
'error': 'No JWT token received',
|
||||
'deployed_version': instance.deployed_version,
|
||||
'deployed_branch': instance.deployed_branch
|
||||
})
|
||||
|
||||
# Fetch version information from the instance
|
||||
response = requests.get(
|
||||
f"{instance.main_url.rstrip('/')}/api/admin/version-info",
|
||||
headers={
|
||||
'Authorization': f'Bearer {jwt_token}',
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
timeout=5
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
version_data = response.json()
|
||||
|
||||
# Update the instance with the fetched version information
|
||||
instance.deployed_version = version_data.get('app_version', instance.deployed_version)
|
||||
instance.deployed_branch = version_data.get('git_branch', instance.deployed_branch)
|
||||
instance.version_checked_at = datetime.utcnow()
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'deployed_version': instance.deployed_version,
|
||||
'deployed_branch': instance.deployed_branch,
|
||||
'git_commit': version_data.get('git_commit'),
|
||||
'deployed_at': version_data.get('deployed_at'),
|
||||
'version_checked_at': instance.version_checked_at.isoformat() if instance.version_checked_at else None
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
'error': f'Failed to fetch version info: {response.status_code}',
|
||||
'deployed_version': instance.deployed_version,
|
||||
'deployed_branch': instance.deployed_branch
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Error fetching version info: {str(e)}")
|
||||
return jsonify({
|
||||
'error': f'Error fetching version info: {str(e)}',
|
||||
'deployed_version': instance.deployed_version,
|
||||
'deployed_branch': instance.deployed_branch
|
||||
})
|
||||
|
||||
UPLOAD_FOLDER = '/app/uploads/profile_pics'
|
||||
if not os.path.exists(UPLOAD_FOLDER):
|
||||
os.makedirs(UPLOAD_FOLDER)
|
||||
|
||||
Reference in New Issue
Block a user