Skip to content

Commit

Permalink
Changed CLI and endpoint interfaces.
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Bhatt <[email protected]>
  • Loading branch information
UtkarshBhatthere committed Dec 13, 2023
1 parent e10b393 commit d693ae0
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 308 deletions.
57 changes: 46 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ jobs:
path: "*.snap"
retention-days: 5

lint-check:
name: Build microceph snap
runs-on: ubuntu-22.04
env:
SNAPCRAFT_BUILD_ENVIRONMENT: "lxd"
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install dependencies
run: |
# Python script dependencies
sudo python -m pip install --upgrade pip
sudo pip install flake8 pep8-naming
- name: Lint check help scripts.
run: |
flake8 ./scripts/ --count --show-source --statistics
unit-tests:
name: Run Unit tests
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -85,11 +106,7 @@ jobs:
run: |
# Python script dependencies
sudo python -m pip install --upgrade pip
sudo pip install flake8 pep8-naming boto3
- name: Lint check
run: |
flake8 . --count --show-source --statistics
sudo pip install boto3
- name: Install and setup
run: |
Expand Down Expand Up @@ -219,7 +236,11 @@ jobs:
run: ~/actionutils.sh free_runner_disk

- name: Install dependencies
run: ~/actionutils.sh setup_lxd
run: |
# Python script dependencies
sudo python -m pip install --upgrade pip
sudo pip install boto3
~/actionutils.sh setup_lxd
- name: Create containers with loopback devices
run: ~/actionutils.sh create_containers
Expand Down Expand Up @@ -314,6 +335,12 @@ jobs:
- name: Copy utils
run: cp tests/scripts/actionutils.sh $HOME

- name: Install dependencies
run: |
# Python script dependencies
sudo python -m pip install --upgrade pip
sudo pip install boto3
- name: Clear FORWARD firewall rules
run: ~/actionutils.sh cleaript

Expand Down Expand Up @@ -370,7 +397,8 @@ jobs:
run: ~/actionutils.sh free_runner_disk

- name: Install dependencies
run: ~/actionutils.sh setup_lxd
run: |
~/actionutils.sh setup_lxd
- name: Create containers with loopback devices
run: ~/actionutils.sh create_containers
Expand All @@ -394,15 +422,22 @@ jobs:
- name: Enable RGW
run: ~/actionutils.sh headexec enable_rgw

- name: Exercise RGW
run: ~/actionutils.sh headexec testrgw
- name: Exercise RGW before upgrade
run: ~/actionutils.sh headexec testrgw_old

- name: Install local build
run: ~/actionutils.sh install_multinode

- name: Wait until 3 OSDs are up
run: ~/actionutils.sh headexec wait_for_osds 3

- name: Install boto3 on head node.
run: |
~/actionutils.sh headexec install_boto3
- name: Exercise RGW again
run: ~/actionutils.sh headexec testrgw

run: |
# Copy S3 app to head node.
lxc file push ./scripts/ -r node-wrk0/root/
~/actionutils.sh headexec testrgw
2 changes: 2 additions & 0 deletions docs/.custom_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Pre
mds
mon
rgw
radosgw
rbd
RBD
MgrReports
Expand All @@ -59,3 +60,4 @@ qemu
writethrough
writeback
IOPS
json
4 changes: 2 additions & 2 deletions docs/how-to/s3-user.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Use S3 user management on MicroCeph
===================================
Manage S3 users on MicroCeph
=============================

MicroCeph provides an easy to use interface for creating, viewing and deleting s3 users for interfacing with the RGW endpoint.
This enables smooth and easy access to Object Storage.
Expand Down
8 changes: 8 additions & 0 deletions microceph/api/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package api

import "github.com/canonical/microcluster/rest"

// Top level client API
var clientCmd = rest.Endpoint{
Path: "client",
}
5 changes: 0 additions & 5 deletions microceph/api/client_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ import (
"github.com/canonical/microcluster/state"
)

// Top level client API
var clientCmd = rest.Endpoint{
Path: "client",
}

// client configs API
var clientConfigsCmd = rest.Endpoint{
Path: "client/configs",
Expand Down
16 changes: 8 additions & 8 deletions microceph/api/s3.go → microceph/api/client_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
)

// /1.0/resources endpoint.
var s3Cmd = rest.Endpoint{
Path: "services/rgw/user",
Get: rest.EndpointAction{Handler: cmdS3Get, ProxyTarget: true},
Put: rest.EndpointAction{Handler: cmdS3Put, ProxyTarget: true},
Delete: rest.EndpointAction{Handler: cmdS3Delete, ProxyTarget: true},
var clientS3Cmd = rest.Endpoint{
Path: "client/s3",
Get: rest.EndpointAction{Handler: cmdClientS3Get, ProxyTarget: true},
Put: rest.EndpointAction{Handler: cmdClientS3Put, ProxyTarget: true},
Delete: rest.EndpointAction{Handler: cmdClientS3Delete, ProxyTarget: true},
}

func cmdS3Get(s *state.State, r *http.Request) response.Response {
func cmdClientS3Get(s *state.State, r *http.Request) response.Response {
var err error
var req types.S3User

Expand All @@ -44,7 +44,7 @@ func cmdS3Get(s *state.State, r *http.Request) response.Response {
}
}

func cmdS3Put(s *state.State, r *http.Request) response.Response {
func cmdClientS3Put(s *state.State, r *http.Request) response.Response {
var err error
var req types.S3User

Expand All @@ -61,7 +61,7 @@ func cmdS3Put(s *state.State, r *http.Request) response.Response {
return response.SyncResponse(true, output)
}

func cmdS3Delete(s *state.State, r *http.Request) response.Response {
func cmdClientS3Delete(s *state.State, r *http.Request) response.Response {
var err error
var req types.S3User

Expand Down
2 changes: 1 addition & 1 deletion microceph/api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ var Endpoints = []rest.Endpoint{
clientCmd,
clientConfigsCmd,
clientConfigsKeyCmd,
s3Cmd,
clientS3Cmd,
}
8 changes: 4 additions & 4 deletions microceph/client/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GetS3User(ctx context.Context, c *client.Client, user *types.S3User) (strin
defer cancel()

ret := ""
err := c.Query(queryCtx, "GET", api.NewURL().Path("services", "rgw", "user"), user, &ret)
err := c.Query(queryCtx, "GET", api.NewURL().Path("client", "s3"), user, &ret)
if err != nil {
logger.Error(err.Error())
return ret, err
Expand All @@ -31,7 +31,7 @@ func ListS3Users(ctx context.Context, c *client.Client) ([]string, error) {

ret := []string{} // List of usernames
// GET request with no user name fetches all users.
err := c.Query(queryCtx, "GET", api.NewURL().Path("services", "rgw", "user"), &types.S3User{Name: ""}, &ret)
err := c.Query(queryCtx, "GET", api.NewURL().Path("client", "s3"), &types.S3User{Name: ""}, &ret)
if err != nil {
logger.Error(err.Error())
return ret, err
Expand All @@ -45,7 +45,7 @@ func CreateS3User(ctx context.Context, c *client.Client, user *types.S3User) (st
defer cancel()

ret := ""
err := c.Query(queryCtx, "PUT", api.NewURL().Path("services", "rgw", "user"), user, &ret)
err := c.Query(queryCtx, "PUT", api.NewURL().Path("client", "s3"), user, &ret)
if err != nil {
logger.Error(err.Error())
return ret, err
Expand All @@ -59,7 +59,7 @@ func DeleteS3User(ctx context.Context, c *client.Client, user *types.S3User) err
defer cancel()

ret := types.S3User{}
err := c.Query(queryCtx, "DELETE", api.NewURL().Path("services", "rgw", "user"), user, &ret)
err := c.Query(queryCtx, "DELETE", api.NewURL().Path("client", "s3"), user, &ret)
if err != nil {
logger.Error(err.Error())
return err
Expand Down
5 changes: 5 additions & 0 deletions microceph/cmd/microceph/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

type cmdClient struct {
common *CmdControl
client *cmdClient
}

func (c *cmdClient) Command() *cobra.Command {
Expand All @@ -18,6 +19,10 @@ func (c *cmdClient) Command() *cobra.Command {
clientConfigCmd := cmdClientConfig{common: c.common, client: c}
cmd.AddCommand(clientConfigCmd.Command())

// S3 Subcommand
clientS3Cmd := cmdClientS3{common: c.common, client: c.client}
cmd.AddCommand(clientS3Cmd.Command())

// Workaround for subcommand usage errors. See: https://github.com/spf13/cobra/issues/706
cmd.Args = cobra.NoArgs
cmd.Run = func(cmd *cobra.Command, args []string) { _ = cmd.Usage() }
Expand Down
Loading

0 comments on commit d693ae0

Please sign in to comment.