Skip to content
Open
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
76 changes: 76 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: deploy
permissions:
id-token: write
contents: read
on:
push:
tags:
- "*"
jobs:
deploy-prod:
environment:
name: production
url: https://dashboard-api.string-api.xyz
if: startsWith(github.ref, 'refs/tags/')
name: deploy to ECS - Production
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: setup go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum
- name: install deps
run: |
go mod download

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v1.7.0
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.PROD_ASSUME_ROLE }}

- name: login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Extract tag
id: extract_tag
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}

- name: build,tag and push to Amazon ECR
id: image-builder
env:
ECR_REPO: ${{ secrets.PROD_AWS_ACCT }}.dkr.ecr.us-west-2.amazonaws.com
SERVICE: dashboard-api
IMAGE_TAG: ${{ steps.extract_tag.tag }}
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./cmd/app/main ./cmd/app/main.go
docker build --platform linux/amd64 -t $ECR_REPO/$SERVICE:$IMAGE_TAG ./cmd/app/
docker push $ECR_REPO/$SERVICE:$IMAGE_TAG
echo "image=$ECR_REPO/$SERVICE:$IMAGE_TAG" >> $GITHUB_OUTPUT

- name: get latest task definition
run: |
aws ecs describe-task-definition --task-definition dashboard-api --query taskDefinition > task-definition.json

- name: update task definition
id: task
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: dashboard-api
image: ${{ steps.image-builder.outputs.image }}

- name: deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task.outputs.task-definition }}
cluster: core
service: dashboard-api
wait-for-service-stability: true
4 changes: 2 additions & 2 deletions api/handler/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/String-xyz/dashboard-api/pkg/model"
"github.com/String-xyz/dashboard-api/pkg/service"
"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/String-xyz/go-lib/v2/httperror"
serror "github.com/String-xyz/go-lib/v2/stringerror"
validator "github.com/String-xyz/go-lib/v2/validator"
"github.com/String-xyz/go-lib/v2/validator"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion api/handler/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/String-xyz/dashboard-api/config"
"github.com/String-xyz/dashboard-api/pkg/service"
"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/String-xyz/go-lib/v2/httperror"
serror "github.com/String-xyz/go-lib/v2/stringerror"
"github.com/labstack/echo/v4"
"golang.org/x/crypto/sha3"
Expand Down
47 changes: 41 additions & 6 deletions api/handler/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package handler

import (
"net/http"
"strconv"

"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/String-xyz/go-lib/v2/httperror"
serror "github.com/String-xyz/go-lib/v2/stringerror"
validator "github.com/String-xyz/go-lib/v2/validator"
"github.com/String-xyz/go-lib/v2/validator"
"github.com/pkg/errors"

"github.com/labstack/echo/v4"

"github.com/String-xyz/dashboard-api/pkg/model"
"github.com/String-xyz/dashboard-api/pkg/service"
"github.com/labstack/echo/v4"
)

type Contract interface {
Expand Down Expand Up @@ -57,11 +59,17 @@ func (a contract) Create(c echo.Context) error {
}

body := model.RequestContractCreate{}

if err := c.Bind(&body); err != nil {
common.LogStringError(c, err, "contract: create bind")
return httperror.BadRequest400(c)
}

if err := c.Validate(body); err != nil {
common.LogStringError(c, err, "contract: create validate")
return httperror.InvalidPayload400(c, err)
}

SanitizeChecksums(&body.Address)

m, err := a.service.Create(c.Request().Context(), body, callerId, organizationId)
Expand Down Expand Up @@ -94,7 +102,28 @@ func (a contract) GetAll(c echo.Context) error {

platformId := c.QueryParam("platformId")

m, err := a.service.GetAll(c.Request().Context(), platformId, organizationId)
var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "contract get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "contract get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

m, err := a.service.GetAll(c.Request().Context(), platformId, organizationId, limit, offset)
if err != nil && errors.Cause(err) != serror.NOT_FOUND {
return DefaultErrorHandler(c, err, "contract: get all")
}
Expand Down Expand Up @@ -227,11 +256,17 @@ func (a contract) Update(c echo.Context) error {
}

body := model.RequestContractUpdate{}
err := c.Bind(&body)
if err != nil {

if err := c.Bind(&body); err != nil {
common.LogStringError(c, err, "contract: update bind")
return httperror.BadRequest400(c)
}

if err := c.Validate(body); err != nil {
common.LogStringError(c, err, "contract: update validate")
return httperror.InvalidPayload400(c, err)
}

if body.Address != nil {
SanitizeChecksums(body.Address)
}
Expand Down
47 changes: 37 additions & 10 deletions api/handler/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package handler

import (
"net/http"
"strconv"
"strings"

"github.com/String-xyz/go-lib/v2/common"

"github.com/String-xyz/dashboard-api/pkg/model"
"github.com/String-xyz/dashboard-api/pkg/service"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/String-xyz/go-lib/v2/httperror"
serror "github.com/String-xyz/go-lib/v2/stringerror"
validator "github.com/String-xyz/go-lib/v2/validator"
"github.com/String-xyz/go-lib/v2/validator"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -55,8 +56,8 @@ func (i invite) Send(c echo.Context) error {
}

body := model.RequestInviteSend{}
err := c.Bind(&body)
if err != nil {

if err := c.Bind(&body); err != nil {
common.LogStringError(c, err, "invite: send bind")
return httperror.BadRequest400(c, "invalid payload")
}
Expand Down Expand Up @@ -90,8 +91,8 @@ func (i invite) Accept(c echo.Context) error {
id := c.Param("id")

body := model.RequestInviteAcceptance{}
err := c.Bind(&body)
if err != nil {

if err := c.Bind(&body); err != nil {
common.LogStringError(c, err, "invite: accept bind")
return httperror.BadRequest400(c)
}
Expand Down Expand Up @@ -143,8 +144,29 @@ func (i invite) List(c echo.Context) error {
return httperror.Internal500(c, "missing or invalid organizationId")
}

var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "invite get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "invite get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

status := c.QueryParam("status")
m, err := i.service.List(c.Request().Context(), status, organizationId)
m, err := i.service.List(c.Request().Context(), status, organizationId, limit, offset)
if err != nil && errors.Cause(err) != serror.NOT_FOUND {
return DefaultErrorHandler(c, err, "invite: list")
}
Expand All @@ -166,12 +188,17 @@ func (i invite) Resend(c echo.Context) error {
return httperror.Internal500(c, "missing or invalid callerId")
}

organizationId, ok := c.Get("organizationId").(string)
if !ok {
return httperror.Internal500(c, "missing or invalid organizationId")
}

id := c.Param("id")
if !validator.IsUUID(id) {
return httperror.BadRequest400(c, "invalid id")
}

m, err := i.service.Resend(c.Request().Context(), id, callerId)
m, err := i.service.Resend(c.Request().Context(), id, callerId, organizationId)
if err != nil {
common.LogStringError(c, err, "invite: resend")

Expand Down Expand Up @@ -209,8 +236,8 @@ func (i invite) Update(c echo.Context) error {
}

body := model.RequestInviteUpdate{}
err := c.Bind(&body)
if err != nil {

if err := c.Bind(&body); err != nil {
common.LogStringError(c, err, "invite: update bind")
return httperror.BadRequest400(c)
}
Expand Down
2 changes: 1 addition & 1 deletion api/handler/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/String-xyz/dashboard-api/pkg/model"
"github.com/String-xyz/dashboard-api/pkg/service"
"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/String-xyz/go-lib/v2/httperror"
serror "github.com/String-xyz/go-lib/v2/stringerror"
"github.com/labstack/echo/v4"
)
Expand Down
28 changes: 25 additions & 3 deletions api/handler/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package handler

import (
"net/http"
"strconv"
"strings"

"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/String-xyz/go-lib/v2/httperror"
serror "github.com/String-xyz/go-lib/v2/stringerror"
validator "github.com/String-xyz/go-lib/v2/validator"
"github.com/String-xyz/go-lib/v2/validator"
"github.com/pkg/errors"

"github.com/String-xyz/dashboard-api/pkg/model"
Expand Down Expand Up @@ -47,7 +48,28 @@ func (a member) GetAll(c echo.Context) error {
return httperror.Internal500(c, "missing or invalid organizationId")
}

m, err := a.service.GetAll(c.Request().Context(), organizationId)
var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "member get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "member get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

m, err := a.service.GetAll(c.Request().Context(), organizationId, limit, offset)
if err != nil && errors.Cause(err) != serror.NOT_FOUND {
common.LogStringError(c, err, "member: get all")
return httperror.Internal500(c)
Expand Down
25 changes: 24 additions & 1 deletion api/handler/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package handler

import (
"net/http"
"strconv"

"github.com/String-xyz/dashboard-api/pkg/service"
"github.com/String-xyz/go-lib/v2/common"
"github.com/String-xyz/go-lib/v2/httperror"
"github.com/labstack/echo/v4"
)

Expand All @@ -30,7 +32,28 @@ func NewNetwork(service service.Network) Network {
// @Failure 500 {object} error
// @Router /networks [get]
func (a network) GetAll(c echo.Context) error {
m, err := a.service.GetAll(c.Request().Context())
var err error
var limit int
var offset int
limitStr := c.QueryParam("limit")
offsetStr := c.QueryParam("offset")

if limitStr != "" {
limit, err = strconv.Atoi(limitStr)
if err != nil {
common.LogStringError(c, err, "network get all: invalid limit")
return httperror.BadRequest400(c, "invalid limit")
}
}
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
common.LogStringError(c, err, "network get all: invalid offset")
return httperror.BadRequest400(c, "invalid offset")
}
}

m, err := a.service.GetAll(c.Request().Context(), limit, offset)
if err != nil {
common.LogStringError(c, err, "network: get all")
return DefaultErrorHandler(c, err, "network: get all")
Expand Down
2 changes: 1 addition & 1 deletion api/handler/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/String-xyz/dashboard-api/pkg/model"
"github.com/String-xyz/dashboard-api/pkg/service"
"github.com/String-xyz/go-lib/v2/common"
httperror "github.com/String-xyz/go-lib/v2/httperror"
"github.com/String-xyz/go-lib/v2/httperror"
serror "github.com/String-xyz/go-lib/v2/stringerror"
"github.com/labstack/echo/v4"
)
Expand Down
Loading