Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: resolve #143 #142

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,31 @@ ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))

OS := $(shell uname -s)

lint:
lint: ## Lint check project
which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0)
golangci-lint run --config=$(ROOT)/.golangci.yml $(ROOT)/...

test:
test: ## Test check project
go test ./...

docker-test-up:
docker-test-up: ## Start docker test environment
docker compose -f $(ROOT)/deployment/test/docker-compose.yml up -d

docker-test-down:
docker-test-down: ## Stop docker test environment
docker compose -f $(ROOT)/deployment/test/docker-compose.yml down

docker-local-up:
docker-local-up: ## Start docker local environment
sh -c "$(ROOT)/deployment/local/docker-compose.bash up -d"

logs:
docker compose -f $(ROOT)/deployment/test/docker-compose.yml logs

format:
format: ## Format project
@which gofumpt || (go install mvdan.cc/gofumpt@latest)
@gofumpt -l -w $(ROOT)
@which gci || (go install github.com/daixiang0/gci@latest)
@gci write $(ROOT)
@which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0)
@golangci-lint run --fix

protobuf:
protobuf: ## Generate protobuf
ifneq (,$(findstring NT,$(OS)))
protoc --go-grpc_out=contract/go/ --go-grpc_opt=paths=source_relative --go_out=contract/go --go_opt=paths=source_relative --proto_path=./contract/protobuf/ contract/protobuf/event/event.proto
protoc --go-grpc_out=contract/go/ --go-grpc_opt=paths=source_relative --go_out=contract/go --go_opt=paths=source_relative --proto_path=./contract/protobuf/ contract/protobuf/task/task.proto
Expand All @@ -44,12 +41,16 @@ else
find contract/protobuf/ -name '*.proto' | xargs -I {} protoc --go-grpc_out=contract/go/ --go-grpc_opt=paths=source_relative --go_out=contract/go --go_opt=paths=source_relative --proto_path=contract/protobuf/ {}
endif

swagger-gen:
swagger-gen: ## Generate swagger
@which swag || (go install github.com/swaggo/swag/cmd/swag@latest)
swag fmt
swag init -g ../cmd/manager/main.go -d manager/ --parseDependency --output doc/swagger --instanceName manager
swag init -g ../cmd/source/main.go -d source/ --parseDependency --output doc/swagger --instanceName source
docker compose --env-file ./deployment/local/.env -f ./deployment/local/services/swagger.yml restart swagger

drop-manager-db:
docker compose --env-file ./deployment/local/.env -f ./deployment/local/services/scylladb.yml exec scylladb cqlsh -e "DROP KEYSPACE manager;"
drop-manager-db: ## Drop manager db
docker compose --env-file ./deployment/local/.env -f ./deployment/local/services/scylladb.yml exec scylladb cqlsh -e "DROP KEYSPACE manager;"


help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[.a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
21 changes: 21 additions & 0 deletions cli/api/source/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) Create(name, description, projectID string) types.Request {
return types.Request{
Path: "sources",
Method: http.MethodPost,
AuthorizationRequired: true,
Header: nil,
Body: map[string]string{
"name": name,
"description": description,
"project_id": projectID,
},
}
}
18 changes: 18 additions & 0 deletions cli/api/source/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) Delete(sourceID string) types.Request {
return types.Request{
Path: "sources/%s",
Method: http.MethodDelete,
AuthorizationRequired: true,
URLParams: []any{
sourceID,
},
}
}
19 changes: 19 additions & 0 deletions cli/api/source/disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) Disable(sourceID string) types.Request {
return types.Request{
Path: "sources/%s/disable",
Method: http.MethodGet,
AuthorizationRequired: true,
Header: nil,
URLParams: []any{
sourceID,
},
}
}
19 changes: 19 additions & 0 deletions cli/api/source/enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) Enable(sourceID string) types.Request {
return types.Request{
Path: "sources/%s/enable",
Method: http.MethodGet,
AuthorizationRequired: true,
Header: nil,
URLParams: []any{
sourceID,
},
}
}
19 changes: 19 additions & 0 deletions cli/api/source/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) List(perPage, lastTokenID string) types.Request {
return types.Request{
Path: "sources",
Method: http.MethodGet,
AuthorizationRequired: true,
QueryParams: map[string]string{
"last_token_id": lastTokenID,
"per_page": perPage,
},
}
}
19 changes: 19 additions & 0 deletions cli/api/source/rotatewritekey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) RotateWriteKey(sourceID string) types.Request {
return types.Request{
Path: "sources/%s/rotate-write-key",
Method: http.MethodGet,
AuthorizationRequired: true,
Header: nil,
URLParams: []any{
sourceID,
},
}
}
19 changes: 19 additions & 0 deletions cli/api/source/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) Show(sourceID string) types.Request {
return types.Request{
Path: "sources/%s",
Method: http.MethodGet,
AuthorizationRequired: true,
Header: nil,
URLParams: []any{
sourceID,
},
}
}
23 changes: 23 additions & 0 deletions cli/api/source/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package source

import (
"net/http"

"github.com/ormushq/ormus/cli/api/types"
)

func (c Client) Update(sourceID, name, description string) types.Request {
return types.Request{
Path: "sources/%s",
Method: http.MethodPost,
AuthorizationRequired: true,
Header: nil,
URLParams: []any{
sourceID,
},
Body: map[string]string{
"name": name,
"description": description,
},
}
}
52 changes: 49 additions & 3 deletions cli/cmd/source/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,69 @@ package source

import (
"fmt"
"io"
"log"
"net/http"

"github.com/ormushq/ormus/cli/cmd"
"github.com/spf13/cobra"
)

// createCmd represents the create command.
var createCmd = &cobra.Command{
Use: "create",
Short: "Create a new source within a project.",
Long: `ormus source create --project-id <project-id> --name <source-name> --type <source-type>`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("create called")
Long: `ormus source create --project-id <project-id> --name <source-name> --description <description>`,
Run: func(cmdCobra *cobra.Command, args []string) {
projectID, err := cmdCobra.Flags().GetString("project-id")
if err != nil {
fmt.Println("error on get project-id flag", err)

return
}
name, err := cmdCobra.Flags().GetString("name")
if err != nil {
fmt.Println("error on get name flag", err)

return
}

description, err := cmdCobra.Flags().GetString("description")
if err != nil {
fmt.Println("error on get description flag", err)

return
}

if name == "" || description == "" || projectID == "" {
fmt.Println("name and description and project id is required")

return
}

resp, err := cmd.Client.SendRequest(cmd.Client.Source.Create(name, description, projectID))
if err != nil {
log.Fatal(err)
}
j, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

if resp.StatusCode != http.StatusCreated {
log.Fatal(fmt.Errorf("status not Created ,status code %d, body: %s", resp.StatusCode, j))
}

fmt.Printf("success response : \n%s\n", j)
},
}

func init() {
sourceCmd.AddCommand(createCmd)

createCmd.Flags().String("name", "", "name")
createCmd.Flags().String("description", "", "description")
createCmd.Flags().String("project-id", "", "project-id")
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
37 changes: 34 additions & 3 deletions cli/cmd/source/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,54 @@ package source

import (
"fmt"
"io"
"log"
"net/http"

"github.com/ormushq/ormus/cli/cmd"
"github.com/spf13/cobra"
)

// deleteCmd represents the delete command.
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a source.",
Long: `ormus source delete --project-id <project-id> --source-id <source-id>`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("delete called")
Long: `ormus source delete --source-id <source-id>`,
Run: func(cmdCobra *cobra.Command, args []string) {
sourceID, err := cmdCobra.Flags().GetString("source-id")
if err != nil {
fmt.Println("error on get source id flag", err)

return
}

if sourceID == "" {
fmt.Println("source id is required")

return
}
resp, err := cmd.Client.SendRequest(cmd.Client.Source.Delete(sourceID))
if err != nil {
log.Fatal(err)
}
j, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}

if resp.StatusCode != http.StatusOK {
log.Fatal(fmt.Errorf("status not Ok ,status code %d, body: %s", resp.StatusCode, j))
}

fmt.Printf("success response : \n%s\n", j)
},
}

func init() {
sourceCmd.AddCommand(deleteCmd)

deleteCmd.Flags().String("source-id", "", "source-id")

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
Expand Down
Loading
Loading