...

Source file src/github.com/sigstore/timestamp-authority/pkg/server/restapi.go

Documentation: github.com/sigstore/timestamp-authority/pkg/server

     1  // Copyright 2022 The Sigstore Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package server
    16  
    17  import (
    18  	"time"
    19  
    20  	"github.com/go-openapi/loads"
    21  	"github.com/sigstore/timestamp-authority/pkg/api"
    22  	"github.com/sigstore/timestamp-authority/pkg/generated/restapi"
    23  	"github.com/sigstore/timestamp-authority/pkg/generated/restapi/operations"
    24  	"github.com/sigstore/timestamp-authority/pkg/internal/cmdparams"
    25  )
    26  
    27  // NewRestAPIServer creates a server for serving the rest API TSA service
    28  func NewRestAPIServer(host string,
    29  	port int,
    30  	scheme []string,
    31  	httpReadOnly bool,
    32  	readTimeout, writeTimeout time.Duration) *restapi.Server {
    33  	doc, _ := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
    34  	server := restapi.NewServer(operations.NewTimestampServerAPI(doc))
    35  
    36  	server.Host = host
    37  	server.Port = port
    38  	server.EnabledListeners = scheme
    39  	server.ReadTimeout = readTimeout
    40  	server.WriteTimeout = writeTimeout
    41  	cmdparams.IsHTTPPingOnly = httpReadOnly
    42  	api.ConfigureAPI()
    43  	server.ConfigureAPI()
    44  
    45  	return server
    46  }
    47  

View as plain text