forked from quay/clair
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: v2 api with gRPC and gRPC-gateway
Newly designed API defines Ancestry as a set of layers and shrinked the api to only the most used apis: post ancestry, get layer, get notification, delete notification Fixes quay#98
- Loading branch information
1 parent
abd7d2e
commit 5b2d7f7
Showing
18 changed files
with
2,492 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
language: go | ||
|
||
go: | ||
- 1.8 | ||
|
||
sudo: required | ||
|
||
install: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2017 clair authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package token | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"time" | ||
|
||
fernet "github.com/fernet/fernet-go" | ||
) | ||
|
||
// Unmarshal decrypts a token using provided key | ||
// and decode the result into interface. | ||
func Unmarshal(token string, key string, v interface{}) error { | ||
k, _ := fernet.DecodeKey(key) | ||
msg := fernet.VerifyAndDecrypt([]byte(token), time.Hour, []*fernet.Key{k}) | ||
if msg == nil { | ||
return errors.New("invalid or expired pagination token") | ||
} | ||
|
||
return json.NewDecoder(bytes.NewBuffer(msg)).Decode(&v) | ||
} | ||
|
||
// Marshal encodes an interface into json bytes and encrypts it. | ||
func Marshal(v interface{}, key string) ([]byte, error) { | ||
var buf bytes.Buffer | ||
err := json.NewEncoder(&buf).Encode(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
k, _ := fernet.DecodeKey(key) | ||
return fernet.EncryptAndSign(buf.Bytes(), k) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
all: | ||
protoc -I/usr/local/include -I. \ | ||
-I${GOPATH}/src \ | ||
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ | ||
--go_out=plugins=grpc:. \ | ||
clair.proto | ||
protoc -I/usr/local/include -I. \ | ||
-I${GOPATH}/src \ | ||
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ | ||
--grpc-gateway_out=logtostderr=true:. \ | ||
clair.proto | ||
protoc -I/usr/local/include -I. \ | ||
-I${GOPATH}/src \ | ||
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ | ||
--swagger_out=logtostderr=true:. \ | ||
clair.proto | ||
go generate . |
Oops, something went wrong.