github.com/GoogleCloudPlatform/testgrid@v0.0.174/pkg/api/v1/server.go (about)

     1  /*
     2  Copyright 2021 The TestGrid Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Package v1 (api/v1) is the first versioned implementation of the API
    18  package v1
    19  
    20  import (
    21  	"time"
    22  
    23  	apipb "github.com/GoogleCloudPlatform/testgrid/pb/api/v1"
    24  	"github.com/GoogleCloudPlatform/testgrid/util/gcs"
    25  	"github.com/go-chi/chi"
    26  )
    27  
    28  // Server contains the necessary settings and i/o objects needed to serve this api
    29  type Server struct {
    30  	Client                   gcs.ConditionalClient
    31  	DefaultBucket            string
    32  	TabPathPrefix            string
    33  	SummaryPathPrefix        string
    34  	AccessControlAllowOrigin string
    35  	Timeout                  time.Duration
    36  	defaultCache             *cachedConfig
    37  }
    38  
    39  // Ensure the server implementation conforms to the API
    40  var _ apipb.TestGridDataServer = (*Server)(nil)
    41  
    42  // Route applies all the v1 API functions provided by the Server to the Router given.
    43  // If the router is nil, a new one is instantiated.
    44  func Route(r *chi.Mux, s Server) *chi.Mux {
    45  	if r == nil {
    46  		r = chi.NewRouter()
    47  	}
    48  	r.Get("/dashboard-groups", s.ListDashboardGroupHTTP)
    49  	r.Get("/dashboard-groups/{dashboard-group}", s.GetDashboardGroupHTTP)
    50  	r.Get("/dashboards", s.ListDashboardsHTTP)
    51  	r.Get("/dashboards/{dashboard}/tabs", s.ListDashboardTabsHTTP)
    52  	r.Get("/dashboards/{dashboard}", s.GetDashboardHTTP)
    53  
    54  	r.Get("/dashboards/{dashboard}/tabs/{tab}/headers", s.ListHeadersHTTP)
    55  	r.Get("/dashboards/{dashboard}/tabs/{tab}/rows", s.ListRowsHTTP)
    56  
    57  	r.Get("/dashboards/{dashboard}/tab-summaries", s.ListTabSummariesHTTP)
    58  	r.Get("/dashboards/{dashboard}/tab-summaries/{tab}", s.GetTabSummaryHTTP)
    59  
    60  	r.Get("/dashboard-groups/{dashboard-group}/dashboard-summaries", s.ListDashboardSummariesHTTP)
    61  	r.Get("/dashboards/{dashboard}/summary", s.GetDashboardSummaryHTTP)
    62  	return r
    63  }