diff options
| author | Linus Nordberg <linus@nordberg.se> | 2022-05-24 23:33:38 +0200 | 
|---|---|---|
| committer | Linus Nordberg <linus@nordberg.se> | 2022-05-24 23:33:38 +0200 | 
| commit | c003c2fc189748f082c09a2b4a729eb1c5732668 (patch) | |
| tree | 4430d208e1233a4345b79cd4bd094210ab69a02a /pkg/instance | |
| parent | be80db7ce938e5cd8876b9b371c206dbd359b1eb (diff) | |
wip
Diffstat (limited to 'pkg/instance')
| -rw-r--r-- | pkg/instance/instance.go | 44 | 
1 files changed, 33 insertions, 11 deletions
| diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index f4c0089..78b5d81 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -35,22 +35,44 @@ type Instance struct {  	Signer   crypto.Signer      // provides access to Ed25519 private key  	Stateman state.StateManager // coordinates access to (co)signed tree heads  	DNS      dns.Verifier       // checks if domain name knows a public key +	Role     Role +	Peer     ServiceEndpoint +} + +type Role int64 +const ( +	Primary Role = iota +	Secondary +) + +type ServiceEndpoint struct { +	URL string +	Pubkey types.PublicKey  } -// Handlers returns a list of sigsum handlers  func (i *Instance) Handlers() []Handler { -	return []Handler{ -		Handler{Instance: i, Handler: addLeaf, Endpoint: types.EndpointAddLeaf, Method: http.MethodPost}, -		Handler{Instance: i, Handler: addCosignature, Endpoint: types.EndpointAddCosignature, Method: http.MethodPost}, -		Handler{Instance: i, Handler: getTreeHeadToCosign, Endpoint: types.EndpointGetTreeHeadToCosign, Method: http.MethodGet}, -		Handler{Instance: i, Handler: getTreeHeadCosigned, Endpoint: types.EndpointGetTreeHeadCosigned, Method: http.MethodGet}, -		Handler{Instance: i, Handler: getCheckpoint, Endpoint: types.Endpoint("get-checkpoint"), Method: http.MethodGet}, -		Handler{Instance: i, Handler: getConsistencyProof, Endpoint: types.EndpointGetConsistencyProof, Method: http.MethodGet}, -		Handler{Instance: i, Handler: getInclusionProof, Endpoint: types.EndpointGetInclusionProof, Method: http.MethodGet}, -		Handler{Instance: i, Handler: getLeaves, Endpoint: types.EndpointGetLeaves, Method: http.MethodGet}, +	switch i.Role { +	case Primary: +		return []Handler{ +			Handler{Instance: i, Handler: addLeaf, Endpoint: types.EndpointAddLeaf, Method: http.MethodPost}, +			Handler{Instance: i, Handler: addCosignature, Endpoint: types.EndpointAddCosignature, Method: http.MethodPost}, +			Handler{Instance: i, Handler: getTreeHeadToCosign, Endpoint: types.EndpointGetTreeHeadToCosign, Method: http.MethodGet}, // ToSign -> ToCoSign +			Handler{Instance: i, Handler: getTreeHeadCosigned, Endpoint: types.EndpointGetTreeHeadCosigned, Method: http.MethodGet}, +			Handler{Instance: i, Handler: getCheckpoint, Endpoint: types.Endpoint("get-checkpoint"), Method: http.MethodGet}, +			Handler{Instance: i, Handler: getConsistencyProof, Endpoint: types.EndpointGetConsistencyProof, Method: http.MethodGet}, +			Handler{Instance: i, Handler: getInclusionProof, Endpoint: types.EndpointGetInclusionProof, Method: http.MethodGet}, +			Handler{Instance: i, Handler: getLeaves, Endpoint: types.EndpointGetLeaves, Method: http.MethodGet}, +		} +	case Secondary: +		return []Handler{ +			Handler{Instance: i, Handler: getTreeHeadToCosign, Endpoint: types.EndpointGetSecondaryTreeHead, Method: http.MethodGet}, +		} +	default: +		return []Handler{}  	}  } +  // checkHTTPMethod checks if an HTTP method is supported  func (i *Instance) checkHTTPMethod(m string) bool {  	return m == http.MethodGet || m == http.MethodPost @@ -95,7 +117,7 @@ func (i *Instance) cosignatureRequestFromHTTP(r *http.Request) (*requests.Cosign  func (i *Instance) consistencyProofRequestFromHTTP(r *http.Request) (*requests.ConsistencyProof, error) {  	var req requests.ConsistencyProof  	if err := req.FromURL(r.URL.Path); err != nil { -		return nil, fmt.Errorf("FromASCII: %v", err) +		return nil, fmt.Errorf("FromURL: %v", err)  	}  	if req.OldSize < 1 {  		return nil, fmt.Errorf("OldSize(%d) must be larger than zero", req.OldSize) | 
