SSH Authentication Setup
Establishing a secure connection between the application server and the remote Git repository requires SSH key authentication. Generate a dedicated key pair for the deployment environment:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/magic_api_deploy -N ""
Register the public key (~/.ssh/magic_api_deploy.pub) within the target Git platform under the deployment account's SSH keys section. To prevent host verification prompts during automated operations, append the remote host's fingerprint to the known hosts file:
ssh-keyscan -H gitlab.example.com >> ~/.ssh/known_hosts
Create or modify the SSH client configuration to bind the specific identity file to the Git host:
Host gitlab.example.com
HostName gitlab.example.com
User git
IdentityFile ~/.ssh/magic_api_deploy
IdentitiesOnly yes
StrictHostKeyChecking accept-new
Maven Dependencies
Include the Git storage extension and the AOP starter in the project's dependency management file. The AOP module is required for intercepting script modifications and triggering synchronization events.
<dependencies>
<dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-plugin-git</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies>
Core Configuration
Direct magic-api to use Git as its primary resource backend by adjusting the application properties. The framework will clone the repository to a local workspace, track changes, and push commits automatically when scripts are modified via the UI.
magic-api:
resource:
type: git
git:
url: git@gitlab.example.com:engineering/api-scripts.git
branch: production
privateKey: /home/deployer/.ssh/magic_api_deploy
location: /var/data/magic-api/workspace
Verification Workflow
Launch the Spring Boot application and navigate to the magic-api web interface. Create or modify an endpoint script. Upon saving, the plugin stages the changes, generates a commit message containing the timestamp and operator details, and pushes to the configured remote branch. Verify the synchronization by checking the commit history on the Git platform. Each UI save operation should correspond to a new commit reflecting the exact script diff.
Extended Configuration Reference
A production-ready configuration typically includes security constraints, response formatting, caching policies, and debugging parameters. Below is a comprehensive property set adapted for enterprise deployments:
magic-api:
resource:
type: git
git:
url: git@gitlab.example.com:engineering/api-scripts.git
branch: production
privateKey: /home/deployer/.ssh/magic_api_deploy
location: /var/data/magic-api/workspace
web: /admin/api-ui
prefix: /v1
auto-import-module: db,redis,http
auto-import-package: java.time.*,java.util.*,java.math.*
allow-override: false
sql-column-case: camel
editor-config: classpath:config/ui-editor.json
suport-cross-domain: true
secret-key: ${MAGIC_SYNC_SECRET:change-me-in-prod}
push-path: /_sync
show-sql: true
compile-cache-size: 1024
persistence-response-body: true
date-pattern:
- yyyy-MM-dd
- yyyy-MM-dd'T'HH:mm:ss
- epoch_millis
response: |-
{
status: code == 1 ? 'success' : 'error',
payload: data,
meta: {
traceId: requestTime,
duration: executeTime
}
}
response-code:
success: 1
invalid: 400
expection: 500
banner: false
thread-pool-executor-size: 16
throw-exception: true
backup:
enable: true
max-history: 90
table-name: sys_magic_version_history
crud:
logic-delete-column: is_deleted
logic-delete-value: 1
cache:
capacity: 50000
ttl: 3600
enable: true
page:
size: limit
page: offset
default-page: 1
default-size: 20
security:
username: ${MAGIC_USER:operator}
password: ${MAGIC_PASS:secure-password}
debug:
timeout: 120