| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package client | 5 package client |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "crypto/x509" | 8 "crypto/x509" |
| 9 "fmt" | 9 "fmt" |
| 10 | 10 |
| 11 "github.com/golang/protobuf/proto" | 11 "github.com/golang/protobuf/proto" |
| 12 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
| 13 "google.golang.org/grpc" | 13 "google.golang.org/grpc" |
| 14 "google.golang.org/grpc/codes" | 14 "google.golang.org/grpc/codes" |
| 15 | 15 |
| 16 "github.com/luci/luci-go/common/clock" | 16 "github.com/luci/luci-go/common/clock" |
| 17 "github.com/luci/luci-go/common/errors" | 17 "github.com/luci/luci-go/common/errors" |
| 18 "github.com/luci/luci-go/common/proto/google" | 18 "github.com/luci/luci-go/common/proto/google" |
| 19 "github.com/luci/luci-go/grpc/grpcutil" | 19 "github.com/luci/luci-go/grpc/grpcutil" |
| 20 | 20 |
| 21 "github.com/luci/luci-go/tokenserver/api/minter/v1" | 21 "github.com/luci/luci-go/tokenserver/api/minter/v1" |
| 22 ) | 22 ) |
| 23 | 23 |
| 24 // Client can make signed requests to the token server. | 24 // Client can make signed requests to the token server. |
| 25 type Client struct { | 25 type Client struct { |
| 26 // Client is interface to use for raw RPC calls to the token server. | 26 // Client is interface to use for raw RPC calls to the token server. |
| 27 // | 27 // |
| 28 // Use minter.NewTokenMinterClient (or NewTokenMinterPRPCClient) to | 28 // Use minter.NewTokenMinterClient (or NewTokenMinterPRPCClient) to |
| 29 // create it. Note that transport-level authentication is not needed. | 29 // create it. Note that transport-level authentication is not needed. |
| 30 » Client minter.TokenMinterClient | 30 » Client TokenMinterClient |
| 31 | 31 |
| 32 // Signer knows how to sign requests using some private key. | 32 // Signer knows how to sign requests using some private key. |
| 33 Signer Signer | 33 Signer Signer |
| 34 } | 34 } |
| 35 | 35 |
| 36 // TokenMinterClient is subset of minter.TokenMinterClient this package uses. |
| 37 type TokenMinterClient interface { |
| 38 // MintMachineToken generates a new token for an authenticated machine. |
| 39 MintMachineToken(context.Context, *minter.MintMachineTokenRequest, ...gr
pc.CallOption) (*minter.MintMachineTokenResponse, error) |
| 40 } |
| 41 |
| 36 // Signer knows how to sign requests using some private key. | 42 // Signer knows how to sign requests using some private key. |
| 37 type Signer interface { | 43 type Signer interface { |
| 38 // Algo returns an algorithm that the signer implements. | 44 // Algo returns an algorithm that the signer implements. |
| 39 Algo(ctx context.Context) (x509.SignatureAlgorithm, error) | 45 Algo(ctx context.Context) (x509.SignatureAlgorithm, error) |
| 40 | 46 |
| 41 // Certificate returns ASN.1 DER blob with the certificate of the signer
. | 47 // Certificate returns ASN.1 DER blob with the certificate of the signer
. |
| 42 Certificate(ctx context.Context) ([]byte, error) | 48 Certificate(ctx context.Context) ([]byte, error) |
| 43 | 49 |
| 44 // Sign signs a blob using the private key. | 50 // Sign signs a blob using the private key. |
| 45 Sign(ctx context.Context, blob []byte) ([]byte, error) | 51 Sign(ctx context.Context, blob []byte) ([]byte, error) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 142 } |
| 137 } | 143 } |
| 138 | 144 |
| 139 // Must not happen. But better return an error than nil-panic if it does
. | 145 // Must not happen. But better return an error than nil-panic if it does
. |
| 140 if resp.TokenResponse == nil { | 146 if resp.TokenResponse == nil { |
| 141 return nil, fmt.Errorf("token server didn't return a token") | 147 return nil, fmt.Errorf("token server didn't return a token") |
| 142 } | 148 } |
| 143 | 149 |
| 144 return resp.TokenResponse, nil | 150 return resp.TokenResponse, nil |
| 145 } | 151 } |
| OLD | NEW |