数据初始化
If you are deploying Casdoor with other services as a complete application, you may want to provide an out-of-the-box feature for users. This means that users can directly use the application without any configuration.
In such a situation, you can use data initialization to register your service in Casdoor through a configuration file. This file can be pre-defined or dynamically generated by your own service.
使用方式
If there is a configuration file named init_data.json
at the root directory of Casdoor, it will be used to initialize data in Casdoor. All you have to do is place this file in the root directory where Casdoor will run.
If you are using the official Docker image of Casdoor, here are some scripts that can help you to mount init_data.json
into the container.
Docker
If you deploy Casdoor with Docker, you can use the volume
command to mount init_data.json
into the container.
docker run ... -v /path/to/init_data.json:/init_data.json
Kubernetes
If you deploy Casdoor with Kubernetes, you can use the configmap
to store init_data.json
.
apiVersion: v1
kind: ConfigMap
metadata:
name: casdoor-init-data
data:
init_data.json:
您可以通过挂载 configmap
将数据挂载到Casdoor的pods
中。 You can modify your deployment
as follows:
apiVersion: apps/v1
kind: Deployment
...
spec:
template:
...
spec:
containers:
...
volumeMounts:
- mountPath: /init_data.json
name: casdoor-init-data-volume
subPath: init_data.json
volumes:
- configMap:
name: casdoor-init-data
name: casdoor-init-data-volume
文件内容
There is already a template named init_data.json.template
in the root directory of Casdoor repository. 您可以参考此文件来自定义您的数据初始化文件。
The following is the Go struct of each part and their documentation:
对象 | Go 结构体 | 文档 |
---|---|---|
组织机构 | struct | doc |
应用 | struct | doc |
用户 | struct | doc |
提供商 | struct | doc |
证书 | struct | |
ldaps | struct | doc |
If you still feel confused about filling out this template, you can call the RESTful API or use the debug mode of your browser to see the response of GetXXX
to these objects. The responses are in the same format as init_data.json
.