|
| 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 | + "net/url" |
| 19 | + |
| 20 | + "github.com/go-openapi/runtime" |
| 21 | + httptransport "github.com/go-openapi/runtime/client" |
| 22 | + "github.com/go-openapi/strfmt" |
| 23 | + "github.com/sigstore/rekor/pkg/generated/client" |
| 24 | + "github.com/sigstore/rekor/pkg/util" |
| 25 | + "github.com/spf13/viper" |
| 26 | +) |
| 27 | + |
| 28 | +func GetRekorClient(rekorServerURL string) (*client.Rekor, error) { |
| 29 | + url, err := url.Parse(rekorServerURL) |
| 30 | + if err != nil { |
| 31 | + return nil, err |
| 32 | + } |
| 33 | + |
| 34 | + rt := httptransport.New(url.Host, client.DefaultBasePath, []string{url.Scheme}) |
| 35 | + rt.Consumers["application/yaml"] = YamlConsumer() |
| 36 | + rt.Consumers["application/x-pem-file"] = runtime.TextConsumer() |
| 37 | + rt.Consumers["application/pem-certificate-chain"] = runtime.TextConsumer() |
| 38 | + rt.Producers["application/yaml"] = YamlProducer() |
| 39 | + rt.Producers["application/timestamp-query"] = runtime.ByteStreamProducer() |
| 40 | + rt.Consumers["application/timestamp-reply"] = runtime.ByteStreamConsumer() |
| 41 | + |
| 42 | + if viper.GetString("api-key") != "" { |
| 43 | + rt.DefaultAuthentication = httptransport.APIKeyAuth("apiKey", "query", viper.GetString("api-key")) |
| 44 | + } |
| 45 | + |
| 46 | + registry := strfmt.Default |
| 47 | + registry.Add("signedCheckpoint", &util.SignedCheckpoint{}, util.SignedCheckpointValidator) |
| 48 | + return client.New(rt, registry), nil |
| 49 | +} |
0 commit comments