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

Split pkg/server from pkg/api #616

Merged
merged 1 commit into from
May 26, 2022
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ issues:
- errcheck
- gosec
# the following section is due to the legacy API being deprecated
- path: pkg/api/legacy_server.go
- path: pkg/server/legacy_server.go
linters:
- staticcheck
text: SA1019
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ ifeq ($(DIFF), 1)
GIT_TREESTATE = "dirty"
endif

FULCIO_PKG=github.com/sigstore/fulcio/pkg/api
LDFLAGS=-X $(FULCIO_PKG).gitVersion=$(GIT_VERSION) -X $(FULCIO_PKG).gitCommit=$(GIT_HASH) -X $(FULCIO_PKG).gitTreeState=$(GIT_TREESTATE) -X $(FULCIO_PKG).buildDate=$(BUILD_DATE)
FULCIO_VERSION_PKG=github.com/sigstore/fulcio/pkg/server
LDFLAGS=-X $(FULCIO_VERSION_PKG).gitVersion=$(GIT_VERSION) -X $(FULCIO_VERSION_PKG).gitCommit=$(GIT_HASH) -X $(FULCIO_VERSION_PKG).gitTreeState=$(GIT_TREESTATE) -X $(FULCIO_VERSION_PKG).buildDate=$(BUILD_DATE)

KO_PREFIX ?= gcr.io/projectsigstore
export KO_DOCKER_REPO=$(KO_PREFIX)
Expand Down
8 changes: 4 additions & 4 deletions cmd/app/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import (
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/sigstore/fulcio/pkg/api"
"github.com/sigstore/fulcio/pkg/ca"
"github.com/sigstore/fulcio/pkg/config"
gw "github.com/sigstore/fulcio/pkg/generated/protobuf"
gw_legacy "github.com/sigstore/fulcio/pkg/generated/protobuf/legacy"
"github.com/sigstore/fulcio/pkg/log"
"github.com/sigstore/fulcio/pkg/server"
"github.com/spf13/viper"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -75,7 +75,7 @@ func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, ba
)),
grpc.MaxRecvMsgSize(int(maxMsgSize)))

grpcCAServer := api.NewGRPCCAServer(ctClient, baseca)
grpcCAServer := server.NewGRPCCAServer(ctClient, baseca)
// Register your gRPC service implementations.
gw.RegisterCAServer(myServer, grpcCAServer)

Expand All @@ -86,7 +86,7 @@ func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, ba
func (g *grpcServer) setupPrometheus(reg *prometheus.Registry) {
grpcMetrics := grpc_prometheus.DefaultServerMetrics
grpcMetrics.EnableHandlingTimeHistogram()
reg.MustRegister(grpcMetrics, api.MetricLatency, api.RequestsCount)
reg.MustRegister(grpcMetrics, server.MetricLatency, server.RequestsCount)
grpc_prometheus.Register(g.Server)
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func createLegacyGRPCServer(cfg *config.FulcioConfig, v2Server gw.CAServer) (*gr
)),
grpc.MaxRecvMsgSize(int(maxMsgSize)))

legacyGRPCCAServer := api.NewLegacyGRPCCAServer(v2Server)
legacyGRPCCAServer := server.NewLegacyGRPCCAServer(v2Server)

// Register your gRPC service implementations.
gw_legacy.RegisterCAServer(myServer, legacyGRPCCAServer)
Expand Down
18 changes: 9 additions & 9 deletions cmd/app/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sigstore/fulcio/pkg/api"
gw "github.com/sigstore/fulcio/pkg/generated/protobuf"
legacy_gw "github.com/sigstore/fulcio/pkg/generated/protobuf/legacy"
"github.com/sigstore/fulcio/pkg/log"
"github.com/sigstore/fulcio/pkg/server"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
Expand All @@ -43,7 +43,7 @@ type httpServer struct {

func extractOIDCTokenFromAuthHeader(ctx context.Context, req *http.Request) metadata.MD {
token := strings.Replace(req.Header.Get("Authorization"), "Bearer ", "", 1)
return metadata.Pairs(api.MetadataOIDCTokenKey, token)
return metadata.Pairs(server.MetadataOIDCTokenKey, token)
}

func createHTTPServer(ctx context.Context, serverEndpoint string, grpcServer, legacyGRPCServer *grpcServer) httpServer {
Expand All @@ -63,9 +63,9 @@ func createHTTPServer(ctx context.Context, serverEndpoint string, grpcServer, le
}

// Limit request size
handler := api.WithMaxBytes(mux, maxMsgSize)
handler = promhttp.InstrumentHandlerDuration(api.MetricLatency, handler)
handler = promhttp.InstrumentHandlerCounter(api.RequestsCount, handler)
handler := server.WithMaxBytes(mux, maxMsgSize)
handler = promhttp.InstrumentHandlerDuration(server.MetricLatency, handler)
handler = promhttp.InstrumentHandlerCounter(server.RequestsCount, handler)

api := http.Server{
Addr: serverEndpoint,
Expand Down Expand Up @@ -96,20 +96,20 @@ func setResponseCodeModifier(ctx context.Context, w http.ResponseWriter, _ proto
}

// set SCT if present ahead of modifying response code
if vals := md.HeaderMD.Get(api.SCTMetadataKey); len(vals) > 0 {
delete(md.HeaderMD, api.SCTMetadataKey)
if vals := md.HeaderMD.Get(server.SCTMetadataKey); len(vals) > 0 {
delete(md.HeaderMD, server.SCTMetadataKey)
delete(w.Header(), "Grpc-Metadata-sct")
w.Header().Set("SCT", vals[0])
}

// set http status code
if vals := md.HeaderMD.Get(api.HTTPResponseCodeMetadataKey); len(vals) > 0 {
if vals := md.HeaderMD.Get(server.HTTPResponseCodeMetadataKey); len(vals) > 0 {
code, err := strconv.Atoi(vals[0])
if err != nil {
return err
}
// delete the headers to not expose any grpc-metadata in http response
delete(md.HeaderMD, api.HTTPResponseCodeMetadataKey)
delete(md.HeaderMD, server.HTTPResponseCodeMetadataKey)
delete(w.Header(), "Grpc-Metadata-X-Http-Code")
w.WriteHeader(code)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/app/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package app
import (
"fmt"

"github.com/sigstore/fulcio/pkg/api"
"github.com/sigstore/fulcio/pkg/server"
"github.com/spf13/cobra"
)

Expand All @@ -43,7 +43,7 @@ func newVersionCmd() *cobra.Command {
}

func runVersion(opts *versionOptions) error {
v := api.VersionInfo()
v := server.VersionInfo()
res := v.String()

if opts.json {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/error.go → pkg/server/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package api
package server

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/grpc_server.go → pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package api
package server

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package api
package server

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/legacy_server.go → pkg/server/legacy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package api
package server

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/max_bytes.go → pkg/server/max_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package api
package server

import "net/http"

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/max_bytes_test.go → pkg/server/max_bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package api
package server

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/metrics.go → pkg/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package api
package server

import (
"github.com/prometheus/client_golang/prometheus"
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/version.go → pkg/server/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//

package api
package server

import (
"encoding/json"
Expand Down