mirror of https://github.com/jumpserver/jumpserver
Init project structure
parent
ba215335bf
commit
b5c159c967
|
@ -0,0 +1,5 @@
|
|||
|
||||
|
||||
|
||||
## 文档
|
||||
[参考](https://code.simcu.com/jumpserver/jumpserver/tree/master/docs)
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AssetsConfig(AppConfig):
|
||||
name = 'assets'
|
|
@ -0,0 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AuditsConfig(AppConfig):
|
||||
name = 'audits'
|
|
@ -0,0 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
|
@ -0,0 +1,127 @@
|
|||
"""
|
||||
Django settings for jumpserver project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 1.10.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.10/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/1.10/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = '2vym+ky!997d5kkcc64mnz06y1mmui3lut#(^wd=%s_qj$1%xv'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'users.apps.AppConfig',
|
||||
'assets.apps.AppConfig',
|
||||
'perms.apps.AppConfig',
|
||||
'audits.apps.AppConfig',
|
||||
# 'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'jumpserver.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'jumpserver.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/1.10/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'Asia/Shanghai'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/1.10/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATICFILES_DIRS = (
|
||||
os.path.join(BASE_DIR, "static"),
|
||||
)
|
|
@ -0,0 +1,21 @@
|
|||
"""jumpserver URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/1.10/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.conf.urls import url, include
|
||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf.urls import url
|
||||
from django.contrib import admin
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
WSGI config for jumpserver project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
|
||||
|
||||
application = get_wsgi_application()
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jumpserver.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError:
|
||||
# The above import may fail for some other reason. Ensure that the
|
||||
# issue is really that Django is missing to avoid masking other
|
||||
# exceptions on Python 2.
|
||||
try:
|
||||
import django
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
)
|
||||
raise
|
||||
execute_from_command_line(sys.argv)
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PermsConfig(AppConfig):
|
||||
name = 'perms'
|
|
@ -0,0 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
name = 'users'
|
|
@ -0,0 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
|
@ -0,0 +1,4 @@
|
|||
## 代码规范
|
||||
|
||||
[参考](https://code.simcu.com/jumpserver/jumpserver/blob/master/docs/code_style.md)
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
# Jumpserver 项目规范(Draft)
|
||||
|
||||
## 语言框架
|
||||
1. Python 2.7 由于ansible目前不支持python3
|
||||
2. Django 1.10 (最新版本)
|
||||
3. Terminal Websocket使用go实现
|
||||
|
||||
|
||||
## 代码风格
|
||||
|
||||
1. Python方面大致的风格,我们采用[pocoo的Style Guidance](http://www.pocoo.org/internal/styleguide/),但是有些细节部分会尽量放开。
|
||||
2. 前端部分(js, css, html),采用[Google的HTML/CSS Coding Style Guidance](https://google.github.io/styleguide/htmlcssguide.xml)以及[JavaScript Coding Style](http://google.github.io/styleguide/javascriptguide.xml)
|
||||
3. Google的Style指南还规范了各种写法,不光包括Coding Format,请尽量遵守,但Coding Format的原则则必须遵守。
|
||||
4. Go的代码风格由@Tad指定。
|
||||
5. 所有人编码前请仔细阅读相应的代码风格指导规范,编码的时候请严格遵循,相互review代码。
|
||||
|
||||
|
||||
## Django规范
|
||||
1. 尽量使用Class Base View编程,更少代码
|
||||
2. 使用Django Form
|
||||
3. 每个url独立命名,不要硬编码,同理static也是
|
||||
4. 数据库表名手动指定,不要使用默认
|
||||
5. 代码优雅简洁
|
||||
6. 注释明确优美
|
||||
7. 测试案例尽可能完整
|
||||
8. 尽可能利用Django造好的轮子
|
||||
|
||||
|
||||
关于代码风格规范一些补充说明:
|
||||
|
||||
### 基本的代码布局
|
||||
|
||||
#### 缩进
|
||||
|
||||
1. Python严格采用4个空格的缩进,不使用tab(\t),任何python代码都都必须遵守此规定。
|
||||
2. web部分代码(HTML, CSS, JavaScript),Node.js采用2空格缩进,同样不使用tab (\t)。
|
||||
之所以与Python不同,是因为js中有大量回调式的写法,2空格可以显著降低视觉上的负担。
|
||||
|
||||
#### 最大行长度
|
||||
|
||||
按PEP8规范,Python一般限制最大80个字符, 强制遵守。
|
||||
|
||||
**补充说明:HTML代码不受此规范约束。**
|
||||
|
||||
#### 长语句缩进
|
||||
|
||||
Python代码参考pocoo style(注: 参考Flask源码)一致。JavaScript代码参考Google的Coding Format说明。
|
||||
|
||||
#### 空行
|
||||
|
||||
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
|
||||
|
||||
### 语句和表达式
|
||||
|
||||
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
|
||||
|
||||
### 命名约定
|
||||
|
||||
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
|
||||
|
||||
### 文档注释(Docstring,即各方法,类的说明文档注释)
|
||||
|
||||
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
|
||||
|
||||
### 注释(comment)
|
||||
|
||||
Python代码参考pocoo style一致。JavaScript代码参考Google的Coding Format说明。
|
||||
|
||||
## 项目骨架
|
||||
|
||||
## 项目骨架
|
||||
|
||||
说明如下:
|
||||
|
||||
```
|
||||
.
|
||||
├── assets // app目录
|
||||
│ ├── admin.py
|
||||
│ ├── apps.py // 新版本django app设置文件
|
||||
│ ├── api.py // api文件
|
||||
│ ├── __init__.py
|
||||
│ ├── migrations // models Migrations版本控制目录
|
||||
│ │ └── __init__.py
|
||||
│ ├── models.py // 数据模型目录
|
||||
│ ├── static // app下静态资源目录
|
||||
│ │ └── assets // 多一层目录,防止资源重名
|
||||
│ │ │ └── some_image.png
|
||||
│ ├── templates // app下模板目录
|
||||
│ │ └── assets // 多一层目录,防止资源重名
|
||||
│ │ │ └── asset_list.html
|
||||
│ ├── templatetags // 模板标签目录
|
||||
│ ├── tests.py // 测试用例文件
|
||||
│ ├── urls.py // urlconf文件
|
||||
│ └── views.py // views文件
|
||||
├── docs // 所有doc文件放到该目录
|
||||
│ └── README.md
|
||||
├── jumpserver // 项目设置目录
|
||||
│ ├── __init__.py
|
||||
│ ├── settings.py // 项目设置文件
|
||||
│ ├── urls.py // 项目入口urlconf
|
||||
│ └── wsgi.py
|
||||
├── LICENSE
|
||||
├── manage.py
|
||||
├── README.md
|
||||
├── static // 项目静态资源目录
|
||||
└── templates // 项目模板目录
|
||||
```
|
||||
|
||||
|
||||
### Go项目
|
||||
|
||||
请@Tad负责补完。
|
||||
|
||||
|
||||
### API
|
||||
|
||||
这里仅考虑REST API的基本情况。
|
||||
|
||||
#### HTTP Method
|
||||
|
||||
1. 读操作使用GET方法,写操作使用PUT/POST/DELETE方法,其中删除记录的操作使用DELETE方法。
|
||||
2. 使用PUT方法实现的API必须是幂等的(多次执行同样操作,结果相同)。
|
||||
3. POST则是实现非幂等的接口。
|
||||
4. 一般性的CRUD操作,R一般使用GET方法,C使用POST,U使用PUT方法,D使用DELETE方法。
|
||||
|
||||
#### URL
|
||||
|
||||
1. 每个项目的的root path后面整合的时候回指定为项目名,这个不需要各项目组考虑。整合的方案可以采用Nginx来转发,后面可以详细讨论
|
||||
3. 一般性的增删查改(CRUD)API,完全使用HTTP method加上url提供的语义,url中的可变部分(比如上面提到的<role_id>)一般用来传递该API操作的核心实体对象的唯一ID,如果有更多的参数需要提供,GET方法请使用url parameter(例如:"?client_id=xxxxx&app_id=xxxxxx"),PUT/POST/DELETE方法请使用请求体传递参数。
|
||||
|
||||
**其他具体情况具体讨论**
|
Loading…
Reference in New Issue