...

Source file src/github.com/sigstore/rekor/pkg/client/rekor_client.go

Documentation: github.com/sigstore/rekor/pkg/client

     1  // Copyright 2021 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 client
    16  
    17  import (
    18  	"crypto/tls"
    19  	"net/http"
    20  	"net/url"
    21  
    22  	"github.com/go-openapi/runtime"
    23  	httptransport "github.com/go-openapi/runtime/client"
    24  	"github.com/go-openapi/strfmt"
    25  	"github.com/hashicorp/go-cleanhttp"
    26  	retryablehttp "github.com/hashicorp/go-retryablehttp"
    27  	"github.com/sigstore/rekor/pkg/generated/client"
    28  	"github.com/sigstore/rekor/pkg/util"
    29  )
    30  
    31  func GetRekorClient(rekorServerURL string, opts ...Option) (*client.Rekor, error) {
    32  	url, err := url.Parse(rekorServerURL)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  	o := makeOptions(opts...)
    37  
    38  	retryableClient := retryablehttp.NewClient()
    39  	defaultTransport := cleanhttp.DefaultTransport()
    40  	if o.InsecureTLS {
    41  		/* #nosec G402 */
    42  		defaultTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
    43  	}
    44  	retryableClient.HTTPClient = &http.Client{
    45  		Transport: defaultTransport,
    46  	}
    47  	retryableClient.RetryMax = int(o.RetryCount)
    48  	retryableClient.Logger = o.Logger
    49  
    50  	httpClient := retryableClient.StandardClient()
    51  	httpClient.Transport = createRoundTripper(httpClient.Transport, o)
    52  
    53  	// sanitize path
    54  	if url.Path == "" {
    55  		url.Path = client.DefaultBasePath
    56  	}
    57  
    58  	rt := httptransport.NewWithClient(url.Host, url.Path, []string{url.Scheme}, httpClient)
    59  	rt.Consumers["application/json"] = runtime.JSONConsumer()
    60  	rt.Consumers["application/x-pem-file"] = runtime.TextConsumer()
    61  	rt.Producers["application/json"] = runtime.JSONProducer()
    62  
    63  	registry := strfmt.Default
    64  	registry.Add("signedCheckpoint", &util.SignedNote{}, util.SignedCheckpointValidator)
    65  	return client.New(rt, registry), nil
    66  }
    67  

View as plain text