mirror of
https://github.com/ubicloud/ubicloud.git
synced 2023-08-22 09:38:31 +03:00
This PR introduces foundations of APIs in clover.
We use Roda as web framework. It supports running nested roda apps from
a parent roda app. I divided roda app to two sub roda apps as CloverWeb
and CloverApi to isolate web console and API endpoints. It helps to
enable only necessary plugins and helper function for sub apps. For
example CloverApi doesn't need HTML rendering plugin.
- Move old Clover < Roda class to `clover_web.rb`
- Create new sub roda app for API `clover_api.rb`
- Put common roda app statements to `routes\base.rb`
## API Paths
Currently, API uses Rodauth's JWT plugin, I need to work more on
authentication part.
We focused on 3 different path formats.
- vm/{VM_ID}
- project/{PROJECT_ID}/vm/{VM_NAME}
- project/{PROJECT_ID}/location/{LOCATION_NAME}/vm/{VM_NAME}
Project prefix helps to isolate different projects' resources and
prevents to do mistake on wrong project. Also Vm names aren't globally
unique, so with project prefix we can use vm names in paths.
Location prefix is an investment for future. It will help us to
determine maiden location of a resource.
## API Reference
https://documenter.getpostman.com/view/2986669/2s93zFWJnS
- `GET /api/project`
- `POST /api/project`
```json
{
"name": "PROJECT_NAME"
}
```
- `GET /api/project/{PROJECT_ID}`
- `GET /api/project/{PROJECT_ID}/location/{LOCATION_NAME}/vm`
- `POST /api/project/{PROJECT_ID}/location/{LOCATION_NAME}/vm`
```json
{
"name": "",
"unix_user": "",
"public_key": "",
"size": "",
"boot_image": ""
}
```
- `GET /api/project/{PROJECT_ID}/location/{LOCATION_NAME}/vm/{VM_NAME}`
- `DELETE /api/project/{PROJECT_ID}/location/{LOCATION_NAME}/vm/{VM_NAME}`
## curl Examples
```
BASE_URL="localhost:9292/api"
USER_NAME=""
USER_PASSWORD=""
PROJECT_ID=""
LOCATION="hetzner-hel1"
VM_NAME="test-vm"
# Login
curl "$BASE_URL/login?login=$USER_NAME&password=$USER_PASSWORD" \
-s -I -X POST \
-H "Content-Type: application/json"
JWT_TOKEN="<FROM_LOGIN_REQUEST>"
# List project
curl "$BASE_URL/project" \
-H "Authorization: Bearer $JWT_TOKEN"
# Create a VM
curl "$BASE_URL/project/$PROJECT_ID/location/$LOCATION/vm" \
-X POST \
-H "Authorization: Bearer $JWT_TOKEN" \
-H "Content-Type: application/json" \
--data '{
"name": "test-vm",
"unix_user": "ubi",
"public_key": "ssh-ed25519 ABCDEF",
"size": "c5a.2x",
"boot_image": "ubuntu-jammy"
}'
# Get VM
curl "$BASE_URL/project/$PROJECT_ID/location/$LOCATION/vm/$VM_NAME" \
-H "Authorization: Bearer $JWT_TOKEN"
```
74 lines
1.2 KiB
YAML
74 lines
1.2 KiB
YAML
# Modified from https://www.fastruby.io/blog/ruby/code-quality/how-we-use-rubocop-and-standardrb.html
|
|
require:
|
|
- rubocop-capybara
|
|
- rubocop-erb
|
|
- rubocop-performance
|
|
- rubocop-rake
|
|
- rubocop-rspec
|
|
- rubocop-sequel
|
|
- standard
|
|
|
|
inherit_gem:
|
|
standard: config/base.yml
|
|
|
|
AllCops:
|
|
TargetRubyVersion: 3.2
|
|
NewCops: enable
|
|
Exclude:
|
|
- public/**/*
|
|
- vendor/**/*
|
|
- node_modules/**/*
|
|
|
|
RSpec:
|
|
Enabled: true
|
|
|
|
Performance:
|
|
Enabled: true
|
|
|
|
Rake:
|
|
Enabled: true
|
|
|
|
Sequel:
|
|
Enabled: true
|
|
|
|
RSpec/DescribeMethod:
|
|
Enabled: false
|
|
|
|
Style/FrozenStringLiteralComment:
|
|
Enabled: true
|
|
|
|
Layout/HeredocIndentation:
|
|
Enabled: false
|
|
|
|
Layout/SpaceInsideHashLiteralBraces:
|
|
Exclude:
|
|
- 'views/**/*.erb'
|
|
|
|
RSpec/ExampleLength:
|
|
Enabled: false
|
|
|
|
RSpec/MultipleExpectations:
|
|
Enabled: false
|
|
|
|
RSpec/StubbedMock:
|
|
Enabled: false
|
|
|
|
RSpec/MessageSpies:
|
|
Enabled: false
|
|
|
|
RSpec/SubjectStub:
|
|
Enabled: false
|
|
|
|
RSpec/ExpectInHook:
|
|
Enabled: false
|
|
|
|
RSpec/InstanceVariable:
|
|
Enabled: false
|
|
|
|
# We renamed our repository to "ubicloud", but app class name is Clover.
|
|
# Rubocop is failing for web UI tests.
|
|
# RSpec/FilePath: Spec path should end with clover*vm*_spec.rb
|
|
RSpec/FilePath:
|
|
Exclude:
|
|
- 'spec/routes/**/*.rb'
|