Skip to content

Commit

Permalink
spike-46 resolve merge conflicts and moved metadata entrypoints and r…
Browse files Browse the repository at this point in the history
…esp reqs to sdk
  • Loading branch information
sahinakyol committed Dec 1, 2024
2 parents fd46ae1 + 7b107aa commit 1241274
Show file tree
Hide file tree
Showing 66 changed files with 822 additions and 1,521 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ go.work.sum
.idea
.code
.history
*.DS_Store
*.iml

# App-specific:
.spike-token
Expand Down
3 changes: 2 additions & 1 deletion app/demo/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"context"
"fmt"

"github.com/spiffe/spike/app/demo/spike"
spike "github.com/spiffe/spike-sdk-go/api"

"github.com/spiffe/spike/pkg/spiffe"
)

Expand Down
18 changes: 10 additions & 8 deletions app/keeper/internal/route/store/keep.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package store
import (
"net/http"

"github.com/spiffe/spike-sdk-go/api/entity/data"
"github.com/spiffe/spike-sdk-go/api/entity/v1/reqres"
"github.com/spiffe/spike-sdk-go/api/errors"

"github.com/spiffe/spike/app/keeper/internal/state"
"github.com/spiffe/spike/internal/entity"
"github.com/spiffe/spike/internal/entity/v1/reqres"
"github.com/spiffe/spike/internal/log"
"github.com/spiffe/spike/internal/net"
)
Expand Down Expand Up @@ -49,31 +51,31 @@ func RouteKeep(

requestBody := net.ReadRequestBody(w, r)
if requestBody == nil {
return entity.ErrReadFailure
return errors.ErrReadFailure
}

request := net.HandleRequest[
reqres.RootKeyCacheRequest, reqres.RootKeyCacheResponse](
requestBody, w,
reqres.RootKeyCacheResponse{Err: reqres.ErrBadInput},
reqres.RootKeyCacheResponse{Err: data.ErrBadInput},
)
if request == nil {
return entity.ErrParseFailure
return errors.ErrParseFailure
}

rootKey := request.RootKey
if rootKey == "" {
return entity.ErrMissingRootKey
return errors.ErrMissingRootKey
}

state.SetRootKey(rootKey)

responseBody := net.MarshalBody(reqres.RootKeyCacheResponse{}, w)
if responseBody == nil {
return entity.ErrMarshalFailure
return errors.ErrMarshalFailure
}

net.Respond(http.StatusOK, responseBody, w)
log.Log().Info(fName, "msg", reqres.ErrSuccess)
log.Log().Info(fName, "msg", data.ErrSuccess)
return nil
}
16 changes: 9 additions & 7 deletions app/keeper/internal/route/store/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package store
import (
"net/http"

"github.com/spiffe/spike-sdk-go/api/entity/data"
"github.com/spiffe/spike-sdk-go/api/entity/v1/reqres"
"github.com/spiffe/spike-sdk-go/api/errors"
"github.com/spiffe/spike/app/keeper/internal/state"
"github.com/spiffe/spike/internal/entity"
"github.com/spiffe/spike/internal/entity/v1/reqres"

"github.com/spiffe/spike/internal/log"
"github.com/spiffe/spike/internal/net"
)
Expand Down Expand Up @@ -53,26 +55,26 @@ func RouteShow(

requestBody := net.ReadRequestBody(w, r)
if requestBody == nil {
return entity.ErrReadFailure
return errors.ErrReadFailure
}

request := net.HandleRequest[
reqres.RootKeyReadRequest, reqres.RootKeyReadResponse](
requestBody, w,
reqres.RootKeyReadResponse{Err: reqres.ErrBadInput},
reqres.RootKeyReadResponse{Err: data.ErrBadInput},
)
if request == nil {
return entity.ErrParseFailure
return errors.ErrParseFailure
}

responseBody := net.MarshalBody(
reqres.RootKeyReadResponse{RootKey: state.RootKey()}, w,
)
if responseBody == nil {
return entity.ErrMarshalFailure
return errors.ErrMarshalFailure
}

net.Respond(http.StatusOK, responseBody, w)
log.Log().Info(fName, "msg", reqres.ErrSuccess)
log.Log().Info(fName, "msg", data.ErrSuccess)
return nil
}
1 change: 0 additions & 1 deletion app/nexus/internal/env/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func BackendStoreType() StoreType {
switch strings.ToLower(st) {
case string(S3):
panic("SPIKE_NEXUS_BACKEND_STORE=s3 is not implemented yet")
return S3
case string(Sqlite):
return Sqlite
case string(Memory):
Expand Down
2 changes: 1 addition & 1 deletion app/nexus/internal/net/cache/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/go-jose/go-jose/v4/json"
"github.com/spiffe/go-spiffe/v2/workloadapi"
"github.com/spiffe/spike-sdk-go/api/entity/v1/reqres"

"github.com/spiffe/spike/app/nexus/internal/net/api"
"github.com/spiffe/spike/internal/auth"
"github.com/spiffe/spike/internal/entity/v1/reqres"
"github.com/spiffe/spike/internal/net"
)

Expand Down
25 changes: 13 additions & 12 deletions app/nexus/internal/route/acl/policy/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
package policy

import (
"github.com/spiffe/spike-sdk-go/api/errors"
"net/http"
"time"

"github.com/spiffe/spike-sdk-go/api/entity/data"
"github.com/spiffe/spike-sdk-go/api/entity/v1/reqres"

state "github.com/spiffe/spike/app/nexus/internal/state/base"
"github.com/spiffe/spike/internal/entity"
"github.com/spiffe/spike/internal/entity/data"
"github.com/spiffe/spike/internal/entity/v1/reqres"
"github.com/spiffe/spike/internal/log"
"github.com/spiffe/spike/internal/net"
"github.com/spiffe/spike/pkg/spiffe"
Expand Down Expand Up @@ -66,16 +67,16 @@ func RoutePutPolicy(

requestBody := net.ReadRequestBody(w, r)
if requestBody == nil {
return entity.ErrParseFailure
return errors.ErrParseFailure
}

request := net.HandleRequest[
reqres.PolicyCreateRequest, reqres.PolicyCreateResponse](
requestBody, w,
reqres.PolicyCreateResponse{Err: reqres.ErrBadInput},
reqres.PolicyCreateResponse{Err: data.ErrBadInput},
)
if request == nil {
return entity.ErrReadFailure
return errors.ErrReadFailure
}

// TODO: sanitize
Expand All @@ -88,7 +89,7 @@ func RoutePutPolicy(
spiffeid, err := spiffe.IdFromRequest(r)
if err != nil {
responseBody := net.MarshalBody(reqres.PolicyCreateResponse{
Err: reqres.ErrUnauthorized,
Err: data.ErrUnauthorized,
}, w)
net.Respond(http.StatusUnauthorized, responseBody, w)
return err
Expand All @@ -100,10 +101,10 @@ func RoutePutPolicy(
)
if !allowed {
responseBody := net.MarshalBody(reqres.PolicyCreateResponse{
Err: reqres.ErrUnauthorized,
Err: data.ErrUnauthorized,
}, w)
net.Respond(http.StatusUnauthorized, responseBody, w)
return entity.ErrUnauthorized
return errors.ErrUnauthorized
}

policy, err := state.CreatePolicy(data.Policy{
Expand All @@ -119,11 +120,11 @@ func RoutePutPolicy(
log.Log().Info(fName, "msg", "Failed to create policy", "err", err)

responseBody := net.MarshalBody(reqres.PolicyCreateResponse{
Err: reqres.ErrInternal,
Err: data.ErrInternal,
}, w)

net.Respond(http.StatusInternalServerError, responseBody, w)
log.Log().Error(fName, "msg", reqres.ErrInternal)
log.Log().Error(fName, "msg", data.ErrInternal)

return err
}
Expand All @@ -133,7 +134,7 @@ func RoutePutPolicy(
}, w)

net.Respond(http.StatusOK, responseBody, w)
log.Log().Info(fName, "msg", reqres.ErrSuccess)
log.Log().Info(fName, "msg", data.ErrSuccess)

return nil
}
29 changes: 15 additions & 14 deletions app/nexus/internal/route/acl/policy/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ package policy
import (
"net/http"

"github.com/spiffe/spike-sdk-go/api/entity/data"
"github.com/spiffe/spike-sdk-go/api/entity/v1/reqres"
"github.com/spiffe/spike-sdk-go/api/errors"

state "github.com/spiffe/spike/app/nexus/internal/state/base"
"github.com/spiffe/spike/internal/entity"
"github.com/spiffe/spike/internal/entity/data"
"github.com/spiffe/spike/internal/entity/v1/reqres"
"github.com/spiffe/spike/internal/log"
"github.com/spiffe/spike/internal/net"
"github.com/spiffe/spike/pkg/spiffe"
Expand Down Expand Up @@ -62,24 +63,24 @@ func RouteDeletePolicy(

requestBody := net.ReadRequestBody(w, r)
if requestBody == nil {
return entity.ErrReadFailure
return errors.ErrReadFailure
}

request := net.HandleRequest[
reqres.PolicyDeleteRequest, reqres.PolicyDeleteResponse](
requestBody, w,
reqres.PolicyDeleteResponse{Err: reqres.ErrBadInput},
reqres.PolicyDeleteResponse{Err: data.ErrBadInput},
)
if request == nil {
return entity.ErrParseFailure
return errors.ErrParseFailure
}

policyId := request.Id

spiffeid, err := spiffe.IdFromRequest(r)
if err != nil {
responseBody := net.MarshalBody(reqres.PolicyDeleteResponse{
Err: reqres.ErrUnauthorized,
Err: data.ErrUnauthorized,
}, w)
net.Respond(http.StatusUnauthorized, responseBody, w)
return err
Expand All @@ -90,34 +91,34 @@ func RouteDeletePolicy(
)
if !allowed {
responseBody := net.MarshalBody(reqres.PolicyDeleteResponse{
Err: reqres.ErrUnauthorized,
Err: data.ErrUnauthorized,
}, w)
net.Respond(http.StatusUnauthorized, responseBody, w)
return entity.ErrUnauthorized
return errors.ErrUnauthorized
}

err = state.DeletePolicy(policyId)
if err != nil {
log.Log().Info(fName, "msg", "Failed to delete policy", "err", err)

responseBody := net.MarshalBody(reqres.PolicyDeleteResponse{
Err: reqres.ErrInternal,
Err: data.ErrInternal,
}, w)
if responseBody == nil {
return entity.ErrMarshalFailure
return errors.ErrMarshalFailure
}

net.Respond(http.StatusInternalServerError, responseBody, w)
log.Log().Info(fName, "msg", reqres.ErrInternal)
log.Log().Info(fName, "msg", data.ErrInternal)
return err
}

responseBody := net.MarshalBody(reqres.PolicyDeleteResponse{}, w)
if responseBody == nil {
return entity.ErrMarshalFailure
return errors.ErrMarshalFailure
}

net.Respond(http.StatusOK, responseBody, w)
log.Log().Info(fName, "msg", reqres.ErrSuccess)
log.Log().Info(fName, "msg", data.ErrSuccess)
return nil
}
23 changes: 12 additions & 11 deletions app/nexus/internal/route/acl/policy/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ package policy
import (
"net/http"

"github.com/spiffe/spike-sdk-go/api/entity/data"
"github.com/spiffe/spike-sdk-go/api/entity/v1/reqres"
"github.com/spiffe/spike-sdk-go/api/errors"

state "github.com/spiffe/spike/app/nexus/internal/state/base"
"github.com/spiffe/spike/internal/entity"
"github.com/spiffe/spike/internal/entity/data"
"github.com/spiffe/spike/internal/entity/v1/reqres"
"github.com/spiffe/spike/internal/log"
"github.com/spiffe/spike/internal/net"
"github.com/spiffe/spike/pkg/spiffe"
Expand Down Expand Up @@ -70,22 +71,22 @@ func RouteListPolicies(

requestBody := net.ReadRequestBody(w, r)
if requestBody == nil {
return entity.ErrReadFailure
return errors.ErrReadFailure
}

request := net.HandleRequest[
reqres.PolicyListRequest, reqres.PolicyListResponse](
requestBody, w,
reqres.PolicyListResponse{Err: reqres.ErrBadInput},
reqres.PolicyListResponse{Err: data.ErrBadInput},
)
if request == nil {
return entity.ErrParseFailure
return errors.ErrParseFailure
}

spiffeid, err := spiffe.IdFromRequest(r)
if err != nil {
responseBody := net.MarshalBody(reqres.PolicyListResponse{
Err: reqres.ErrUnauthorized,
Err: data.ErrUnauthorized,
}, w)
net.Respond(http.StatusUnauthorized, responseBody, w)
return err
Expand All @@ -96,10 +97,10 @@ func RouteListPolicies(
)
if !allowed {
responseBody := net.MarshalBody(reqres.PolicyListResponse{
Err: reqres.ErrUnauthorized,
Err: data.ErrUnauthorized,
}, w)
net.Respond(http.StatusUnauthorized, responseBody, w)
return entity.ErrUnauthorized
return errors.ErrUnauthorized
}

policies := state.ListPolicies()
Expand All @@ -108,10 +109,10 @@ func RouteListPolicies(
Policies: policies,
}, w)
if responseBody == nil {
return entity.ErrMarshalFailure
return errors.ErrMarshalFailure
}

net.Respond(http.StatusOK, responseBody, w)
log.Log().Info(fName, "msg", reqres.ErrSuccess)
log.Log().Info(fName, "msg", data.ErrSuccess)
return nil
}
Loading

0 comments on commit 1241274

Please sign in to comment.