feat: domain/storage/billing/config cmds + rainyun domain/storage/billing services

This commit is contained in:
2026-07-28 16:11:03 +08:00
parent b0fbc3e710
commit 096492dd82
8 changed files with 465 additions and 5 deletions
+59
View File
@@ -0,0 +1,59 @@
package rainyun
import (
"context"
"fmt"
"git.yoresee.cc/nightstar/ry/internal/provider"
)
type StorageService struct {
client *client
}
func (s *StorageService) List(ctx context.Context) ([]provider.StorageInstance, error) {
var raw []struct {
ID int `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
}
if err := s.client.get(ctx, "/product/ros/instance", &raw); err != nil {
return nil, err
}
instances := make([]provider.StorageInstance, len(raw))
for i, r := range raw {
instances[i] = provider.StorageInstance{
ID: fmt.Sprintf("%d", r.ID),
Name: r.Name,
Raw: r,
}
}
return instances, nil
}
func (s *StorageService) BucketList(ctx context.Context, instanceID string) ([]provider.Bucket, error) {
type rainyunBucket struct {
ID int `json:"id"`
Name string `json:"name"`
Region string `json:"region"`
}
var raw []rainyunBucket
path := fmt.Sprintf("/product/ros/bucket/%s", instanceID)
if err := s.client.get(ctx, path, &raw); err != nil {
return nil, err
}
buckets := make([]provider.Bucket, len(raw))
for i, r := range raw {
buckets[i] = provider.Bucket{
ID: fmt.Sprintf("%d", r.ID),
Name: r.Name,
}
}
return buckets, nil
}
func (s *StorageService) BucketCreate(ctx context.Context, instanceID, name string) error {
body := map[string]string{"name": name}
path := fmt.Sprintf("/product/ros/bucket/%s", instanceID)
return s.client.post(ctx, path, body, nil)
}