diff --git a/.drone.sh b/.drone.sh index 8e1afe77bd..b06cb1e41c 100755 --- a/.drone.sh +++ b/.drone.sh @@ -3,15 +3,7 @@ # only execute this script as part of the pipeline. [ -z "$CI" ] && echo "missing ci environment variable" && exit 2 -# only execute the script when github token exists. -[ -z "$SSH_KEY" ] && echo "missing ssh key" && exit 3 - -# write the ssh key. mkdir /root/.ssh -echo -n "$SSH_KEY" > /root/.ssh/id_rsa -chmod 600 /root/.ssh/id_rsa - -# add github.com to our known hosts. touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts ssh-keyscan -H github.com > /etc/ssh/ssh_known_hosts 2> /dev/null @@ -19,10 +11,9 @@ ssh-keyscan -H github.com > /etc/ssh/ssh_known_hosts 2> /dev/null # clone the extras project. set -e set -x -git clone git@github.com:drone/drone-enterprise.git extras # build a static binary with the build number and extra features. -go build -ldflags '-extldflags "-static" -X github.com/drone/drone/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/drone-server github.com/drone/drone/extras/cmd/drone-server +go build -ldflags '-extldflags "-static" -X github.com/drone/drone/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/drone-server github.com/drone/drone/cmd/drone-server GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-X github.com/drone/drone/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/drone-agent github.com/drone/drone/cmd/drone-agent GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags '-X github.com/drone/drone/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/linux/arm64/drone-agent github.com/drone/drone/cmd/drone-agent GOOS=linux GOARCH=arm CGO_ENABLED=0 GOARM=7 go build -ldflags '-X github.com/drone/drone/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/linux/arm/drone-agent github.com/drone/drone/cmd/drone-agent diff --git a/.drone.yml b/.drone.yml index 6511abb33c..0d45f70308 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ pipeline: publish_server_alpine: image: plugins/docker - repo: drone/drone + repo: gboo/drone-server dockerfile: Dockerfile.alpine secrets: [ docker_username, docker_password ] tag: [ alpine ] @@ -49,7 +49,7 @@ pipeline: publish_server: image: plugins/docker - repo: drone/drone + repo: gboo/drone-server secrets: [ docker_username, docker_password ] tag: [ latest ] when: @@ -58,7 +58,7 @@ pipeline: publish_agent_alpine: image: plugins/docker - repo: drone/agent + repo: gboo/drone-agent dockerfile: Dockerfile.agent.alpine secrets: [ docker_username, docker_password ] tag: [ alpine ] @@ -68,7 +68,7 @@ pipeline: publish_agent_arm: image: plugins/docker - repo: drone/agent + repo: gboo/drone-agent dockerfile: Dockerfile.agent.linux.arm secrets: [ docker_username, docker_password ] tag: [ linux-arm ] @@ -78,7 +78,7 @@ pipeline: publish_agent_arm64: image: plugins/docker - repo: drone/agent + repo: gboo/drone-agent dockerfile: Dockerfile.agent.linux.arm64 secrets: [ docker_username, docker_password ] tag: [ linux-arm64 ] @@ -88,7 +88,7 @@ pipeline: publish_agent_amd64: image: plugins/docker - repo: drone/agent + repo: gboo/drone-agent dockerfile: Dockerfile.agent secrets: [ docker_username, docker_password ] tag: [ latest ] @@ -98,16 +98,16 @@ pipeline: release_server_alpine: image: plugins/docker - repo: drone/drone + repo: gboo/drone-server dockerfile: Dockerfile.alpine secrets: [ docker_username, docker_password ] - tag: [ 0.8-alpine ] + tag: ${DRONE_TAG} when: event: tag release_agent_alpine: image: plugins/docker - repo: drone/agent + repo: gboo/drone-agent dockerfile: Dockerfile.agent.alpine secrets: [ docker_username, docker_password ] tag: [ 0.8-alpine ] @@ -116,18 +116,18 @@ pipeline: release_server: image: plugins/docker - repo: drone/drone + repo: gboo/drone-server secrets: [ docker_username, docker_password ] - tag: [ 0.8, 0.8.2 ] + tag: [ 0.8, 0.8.6 ] when: event: tag release_agent: image: plugins/docker - repo: drone/agent + repo: gboo/drone-agent dockerfile: Dockerfile.agent secrets: [ docker_username, docker_password ] - tag: [ 0.8, 0.8.2 ] + tag: [ 0.8, 0.8.6 ] when: event: tag diff --git a/.gitignore b/.gitignore index c07e1ad423..ff6612453f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ extras/ release/ server/swagger/files/*.json +.idea/ diff --git a/BUILDING b/BUILDING new file mode 100644 index 0000000000..0e51069af8 --- /dev/null +++ b/BUILDING @@ -0,0 +1,13 @@ +1. Install go 1.9 or later +2. Install dependencies + + go get -u github.com/drone/drone-ui/dist + go get -u golang.org/x/net/context + go get -u golang.org/x/net/context/ctxhttp + go get -u github.com/golang/protobuf/proto + go get -u github.com/golang/protobuf/protoc-gen-go + +3. Install binaries to $GOPATH/bin + + go install github.com/drone/drone/cmd/drone-agent + go install github.com/drone/drone/cmd/drone-server diff --git a/Dockerfile.agent.alpine b/Dockerfile.agent.alpine index a2bb3ce291..eac573ebd4 100644 --- a/Dockerfile.agent.alpine +++ b/Dockerfile.agent.alpine @@ -1,4 +1,4 @@ -FROM alpine:3.6 +FROM alpine:3.7 RUN apk add -U --no-cache ca-certificates diff --git a/Dockerfile.alpine b/Dockerfile.alpine index a22797c864..2d7047220a 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,4 +1,4 @@ -FROM alpine:3.6 +FROM alpine:3.7 EXPOSE 8000 9000 80 443 RUN apk add -U --no-cache ca-certificates diff --git a/LICENSE b/LICENSE index 7a4a3ea242..04b10d8b6b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,202 +1,80 @@ +The Drone Community Edition (the "Community Edition") is licensed under the +Apache License, Version 2.0 (the "Apache License"). You may obtain a copy of +the Apache License at - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. \ No newline at end of file + http://www.apache.org/licenses/LICENSE-2.0 + +The Drone Enterprise Edition (the "Enterprise Edition") is licensed under +the Drone Enterprise License, Version 1.1 (the "Enterprise License"). A copy +of the Enterprise License is provided below. + +The source files in this repository have a header indicating which license +they are under. The BUILDING file provides instructions for creating the +Community Edition distribution subject to the terms of the Apache License. + +----------------------------------------------------------------------------- + +Licensor: Drone.IO, Inc +Licensed Work: Drone Enterprise Edition + +Additional Use Grant: Usage of the software is free for entities with both: + (a) annual gross revenue under (USD) $1 million + (according to GAAP, or the equivalent in its country + of domicile); and (b) less than (USD) $5 million in + aggregate debt and equity funding. + +Change Date: 2022-01-01 + +Change License: Apache-2.0 + +Notice + +The Drone Enterprise License (this document, or the "License") is not an Open +Source license. However, the Licensed Work will eventually be made available +under an Open Source License, as stated in this License. + +----------------------------------------------------------------------------- + +Drone Enterprise License 1.1 + +Terms + +The Licensor hereby grants you the right to copy, modify, create derivative +works, redistribute, and make non-production use of the Licensed Work. The +Licensor may make an Additional Use Grant, above, permitting limited +production use. + +Effective on the Change Date, or the fourth anniversary of the first publicly +available distribution of a specific version of the Licensed Work under this +License, whichever comes first, the Licensor hereby grants you rights under +the terms of the Change License, and the rights granted in the paragraph +above terminate. + +If your use of the Licensed Work does not comply with the requirements +currently in effect as described in this License, you must purchase a +commercial license from the Licensor, its affiliated entities, or authorized +resellers, or you must refrain from using the Licensed Work. + +All copies of the original and modified Licensed Work, and derivative works +of the Licensed Work, are subject to this License. This License applies +separately for each version of the Licensed Work and the Change Date may vary +for each version of the Licensed Work released by Licensor. + +You must conspicuously display this License on each original or modified copy +of the Licensed Work. If you receive the Licensed Work in original or +modified form from a third party, the terms and conditions set forth in this +License apply to your use of that work. + +Any use of the Licensed Work in violation of this License will automatically +terminate your rights under this License for the current and all other +versions of the Licensed Work. + +This License does not grant you any right in any trademark or logo of +Licensor or its affiliates (provided that you may use a trademark or logo of +Licensor as expressly required by this License). + +TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +TITLE. diff --git a/README.md b/README.md index 84874de6a8..0756d387e1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,23 @@ -Drone is a Continuous Delivery system built on container technology. Drone uses a simple yaml configuration file, a superset of docker-compose, to define and execute Pipelines inside Docker containers. +## Gbo's fork + +### Patches + + - [Fallback to remote yaml when no .drone.yml found](https://github.com/drone/drone/compare/master...gboddin:feature/fallback-cleaned) + - [Filter with refspec](https://github.com/drone/drone/compare/master...gboddin:feature/with-refspec-pipeline) + - [OSS build](https://github.com/drone/drone/compare/master...gboddin:feature/drone-build-oss) + +### Images + - gboo/drone-server + - gboo/drone-agent + +### Fork disclaimer + +- Resolves user's specific needs +- No support +- Voids any Enterprise support +- Licensing terms by Drone is still applies when using non-free work ( see source headers ) + +Drone is a Continuous Delivery system built on container technology. Drone uses a simple YAML configuration file, a superset of docker-compose, to define and execute Pipelines inside Docker containers.
diff --git a/cmd/drone-agent/agent.go b/cmd/drone-agent/agent.go index 21341c95e0..fa71d75eda 100644 --- a/cmd/drone-agent/agent.go +++ b/cmd/drone-agent/agent.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 main import ( @@ -12,6 +26,7 @@ import ( "time" "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" "google.golang.org/grpc/metadata" "github.com/cncd/pipeline/pipeline" @@ -33,7 +48,7 @@ func loop(c *cli.Context) error { Labels: map[string]string{ "platform": c.String("platform"), }, - Expr: c.String("drone-filter"), + Expr: c.String("filter"), } hostname := c.String("hostname") @@ -75,6 +90,10 @@ func loop(c *cli.Context) error { username: c.String("username"), password: c.String("password"), }), + grpc.WithKeepaliveParams(keepalive.ClientParameters{ + Time: c.Duration("keepalive-time"), + Timeout: c.Duration("keepalive-timeout"), + }), ) if err != nil { diff --git a/cmd/drone-agent/health.go b/cmd/drone-agent/health.go index 99c68fca17..1f41abac03 100644 --- a/cmd/drone-agent/health.go +++ b/cmd/drone-agent/health.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 main import ( diff --git a/cmd/drone-agent/health_test.go b/cmd/drone-agent/health_test.go index 17505c867f..fbe23593f0 100644 --- a/cmd/drone-agent/health_test.go +++ b/cmd/drone-agent/health_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 main import ( diff --git a/cmd/drone-agent/main.go b/cmd/drone-agent/main.go index c23ed702b4..01f7459fa2 100644 --- a/cmd/drone-agent/main.go +++ b/cmd/drone-agent/main.go @@ -1,8 +1,23 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 main import ( "fmt" "os" + "time" "github.com/drone/drone/version" @@ -39,12 +54,12 @@ func main() { cli.StringFlag{ EnvVar: "DRONE_PASSWORD,DRONE_SECRET", Name: "password", - Usage: "drone auth password", + Usage: "server-agent shared password", }, cli.BoolTFlag{ EnvVar: "DRONE_DEBUG", Name: "debug", - Usage: "start the agent in debug mode", + Usage: "enable agent debug mode", }, cli.BoolFlag{ EnvVar: "DRONE_DEBUG_PRETTY", @@ -59,26 +74,40 @@ func main() { cli.StringFlag{ EnvVar: "DRONE_HOSTNAME,HOSTNAME", Name: "hostname", + Usage: "agent hostname", }, cli.StringFlag{ EnvVar: "DRONE_PLATFORM", Name: "platform", + Usage: "restrict builds by platform conditions", Value: "linux/amd64", }, cli.StringFlag{ EnvVar: "DRONE_FILTER", Name: "filter", - Usage: "filter expression used to restrict builds by label", + Usage: "filter expression to restrict builds by label", }, cli.IntFlag{ EnvVar: "DRONE_MAX_PROCS", Name: "max-procs", + Usage: "agent parallel builds", Value: 1, }, cli.BoolTFlag{ EnvVar: "DRONE_HEALTHCHECK", Name: "healthcheck", - Usage: "enables the healthcheck endpoint", + Usage: "enable healthcheck endpoint", + }, + cli.DurationFlag{ + EnvVar: "DRONE_KEEPALIVE_TIME", + Name: "keepalive-time", + Usage: "after a duration of this time of no activity, the agent pings the server to check if the transport is still alive", + }, + cli.DurationFlag{ + EnvVar: "DRONE_KEEPALIVE_TIMEOUT", + Name: "keepalive-timeout", + Usage: "after pinging for a keepalive check, the agent waits for a duration of this time before closing the connection if no activity", + Value: time.Second * 20, }, } diff --git a/cmd/drone-server/main.go b/cmd/drone-server/main.go index af2137f5c3..3eda1ca165 100644 --- a/cmd/drone-server/main.go +++ b/cmd/drone-server/main.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 main import ( diff --git a/cmd/drone-server/server.go b/cmd/drone-server/server.go index d2eb604898..f36527bd1e 100644 --- a/cmd/drone-server/server.go +++ b/cmd/drone-server/server.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 main import ( @@ -13,6 +27,7 @@ import ( "time" "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" "google.golang.org/grpc/metadata" "golang.org/x/crypto/acme/autocert" @@ -38,12 +53,12 @@ var flags = []cli.Flag{ cli.BoolFlag{ EnvVar: "DRONE_DEBUG", Name: "debug", - Usage: "start the server in debug mode", + Usage: "enable server debug mode", }, cli.StringFlag{ EnvVar: "DRONE_SERVER_HOST,DRONE_HOST", Name: "server-host", - Usage: "server host", + Usage: "server fully qualified url (://)", }, cli.StringFlag{ EnvVar: "DRONE_SERVER_ADDR", @@ -54,22 +69,22 @@ var flags = []cli.Flag{ cli.StringFlag{ EnvVar: "DRONE_SERVER_CERT", Name: "server-cert", - Usage: "server ssl cert", + Usage: "server ssl cert path", }, cli.StringFlag{ EnvVar: "DRONE_SERVER_KEY", Name: "server-key", - Usage: "server ssl key", + Usage: "server ssl key path", }, cli.BoolFlag{ EnvVar: "DRONE_LETS_ENCRYPT", Name: "lets-encrypt", - Usage: "lets encrypt enabled", + Usage: "enable let's encrypt", }, cli.BoolFlag{ EnvVar: "DRONE_QUIC", Name: "quic", - Usage: "start the server with quic enabled", + Usage: "enable quic", }, cli.StringFlag{ EnvVar: "DRONE_WWW", @@ -90,7 +105,7 @@ var flags = []cli.Flag{ cli.BoolFlag{ EnvVar: "DRONE_OPEN", Name: "open", - Usage: "open user registration", + Usage: "enable open user registration", }, cli.StringFlag{ EnvVar: "DRONE_REPO_CONFIG", @@ -101,12 +116,13 @@ var flags = []cli.Flag{ cli.DurationFlag{ EnvVar: "DRONE_SESSION_EXPIRES", Name: "session-expires", - Usage: "Set the session expiration time default 72h", + Usage: "session expiration time", Value: time.Hour * 72, }, cli.StringSliceFlag{ EnvVar: "DRONE_ESCALATE", Name: "escalate", + Usage: "images to run in privileged mode", Value: &cli.StringSlice{ "plugins/docker", "plugins/gcr", @@ -124,7 +140,7 @@ var flags = []cli.Flag{ cli.StringFlag{ EnvVar: "DRONE_AGENT_SECRET,DRONE_SECRET", Name: "agent-secret", - Usage: "agent secret passcode", + Usage: "server-agent shared password", }, cli.StringFlag{ EnvVar: "DRONE_SECRET_ENDPOINT", @@ -153,32 +169,44 @@ var flags = []cli.Flag{ Usage: "database driver configuration string", Value: "drone.sqlite", }, + cli.StringFlag{ + EnvVar: "DRONE_PROMETHEUS_AUTH_TOKEN", + Name: "prometheus-auth-token", + Usage: "token to secure prometheus metrics endpoint", + Value: "", + }, // // resource limit parameters // cli.Int64Flag{ - Name: "limit-mem-swap", EnvVar: "DRONE_LIMIT_MEM_SWAP", + Name: "limit-mem-swap", + Usage: "maximum swappable memory allowed in bytes", }, cli.Int64Flag{ - Name: "limit-mem", EnvVar: "DRONE_LIMIT_MEM", + Name: "limit-mem", + Usage: "maximum memory allowed in bytes", }, cli.Int64Flag{ - Name: "limit-shm-size", EnvVar: "DRONE_LIMIT_SHM_SIZE", + Name: "limit-shm-size", + Usage: "docker compose /dev/shm allowed in bytes", }, cli.Int64Flag{ - Name: "limit-cpu-quota", EnvVar: "DRONE_LIMIT_CPU_QUOTA", + Name: "limit-cpu-quota", + Usage: "impose a cpu quota", }, cli.Int64Flag{ - Name: "limit-cpu-shares", EnvVar: "DRONE_LIMIT_CPU_SHARES", + Name: "limit-cpu-shares", + Usage: "change the cpu shares", }, cli.StringFlag{ - Name: "limit-cpu-set", EnvVar: "DRONE_LIMIT_CPU_SET", + Name: "limit-cpu-set", + Usage: "set the cpus allowed to execute containers", }, // // remote parameters @@ -288,6 +316,12 @@ var flags = []cli.Flag{ Usage: "gitea server address", Value: "https://try.gitea.io", }, + cli.StringFlag{ + EnvVar: "DRONE_GITEA_CONTEXT", + Name: "gitea-context", + Usage: "gitea status context", + Value: "continuous-integration/drone", + }, cli.StringFlag{ EnvVar: "DRONE_GITEA_GIT_USERNAME", Name: "gitea-git-username", @@ -461,6 +495,11 @@ var flags = []cli.Flag{ Name: "coding-skip-verify", Usage: "coding skip ssl verification", }, + cli.DurationFlag{ + EnvVar: "DRONE_KEEPALIVE_MIN_TIME", + Name: "keepalive-min-time", + Usage: "server-side enforcement policy on the minimum amount of time a client should wait before sending a keepalive ping.", + }, } func server(c *cli.Context) error { @@ -477,6 +516,18 @@ func server(c *cli.Context) error { logrus.Fatalln("DRONE_HOST is not properly configured") } + if !strings.Contains(c.String("server-host"), "://") { + logrus.Fatalln( + "DRONE_HOST must be :// format", + ) + } + + if strings.HasSuffix(c.String("server-host"), "/") { + logrus.Fatalln( + "DRONE_HOST must not have trailing slash", + ) + } + remote_, err := SetupRemote(c) if err != nil { logrus.Fatal(err) @@ -515,6 +566,9 @@ func server(c *cli.Context) error { s := grpc.NewServer( grpc.StreamInterceptor(auther.streamInterceptor), grpc.UnaryInterceptor(auther.unaryIntercaptor), + grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ + MinTime: c.Duration("keepalive-min-time"), + }), ) ss := new(droneserver.DroneServer) ss.Queue = droneserver.Config.Services.Queue @@ -536,7 +590,7 @@ func server(c *cli.Context) error { // start the server with tls enabled if c.String("server-cert") != "" { g.Go(func() error { - return http.ListenAndServe(":http", handler) + return http.ListenAndServe(":http", http.HandlerFunc(redirect)) }) g.Go(func() error { serve := &http.Server{ @@ -564,24 +618,23 @@ func server(c *cli.Context) error { // start the server with lets encrypt enabled // listen on ports 443 and 80 + address, err := url.Parse(c.String("server-host")) + if err != nil { + return err + } + + dir := cacheDir() + os.MkdirAll(dir, 0700) + + manager := &autocert.Manager{ + Prompt: autocert.AcceptTOS, + HostPolicy: autocert.HostWhitelist(address.Host), + Cache: autocert.DirCache(dir), + } g.Go(func() error { - return http.ListenAndServe(":http", handler) + return http.ListenAndServe(":http", manager.HTTPHandler(http.HandlerFunc(redirect))) }) - g.Go(func() error { - address, err := url.Parse(c.String("server-host")) - if err != nil { - return err - } - - dir := cacheDir() - os.MkdirAll(dir, 0700) - - manager := autocert.Manager{ - Prompt: autocert.AcceptTOS, - HostPolicy: autocert.HostWhitelist(address.Host), - Cache: autocert.DirCache(dir), - } serve := &http.Server{ Addr: ":https", Handler: handler, @@ -644,6 +697,9 @@ func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) { // droneserver.Config.Server.Open = cli.Bool("open") // droneserver.Config.Server.Orgs = sliceToMap(cli.StringSlice("orgs")) // droneserver.Config.Server.Admins = sliceToMap(cli.StringSlice("admin")) + + // prometheus + droneserver.Config.Prometheus.AuthToken = c.String("prometheus-auth-token") } type authorizer struct { @@ -675,6 +731,18 @@ func (a *authorizer) authorize(ctx context.Context) error { return errors.New("missing agent token") } +func redirect(w http.ResponseWriter, req *http.Request) { + var serverHost string = droneserver.Config.Server.Host + serverHost = strings.TrimPrefix(serverHost, "http://") + serverHost = strings.TrimPrefix(serverHost, "https://") + req.URL.Scheme = "https" + req.URL.Host = serverHost + + w.Header().Set("Strict-Transport-Security", "max-age=31536000") + + http.Redirect(w, req, req.URL.String(), http.StatusMovedPermanently) +} + func cacheDir() string { const base = "golang-autocert" if xdg := os.Getenv("XDG_CACHE_HOME"); xdg != "" { diff --git a/cmd/drone-server/setup.go b/cmd/drone-server/setup.go index fabc6fac84..248b49a4dc 100644 --- a/cmd/drone-server/setup.go +++ b/cmd/drone-server/setup.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 main import ( @@ -101,6 +115,7 @@ func setupGogs(c *cli.Context) (remote.Remote, error) { func setupGitea(c *cli.Context) (remote.Remote, error) { return gitea.New(gitea.Opts{ URL: c.String("gitea-server"), + Context: c.String("gitea-context"), Username: c.String("gitea-git-username"), Password: c.String("gitea-git-password"), PrivateMode: c.Bool("gitea-private-mode"), diff --git a/model/build.go b/model/build.go index e55d926377..f1c7e00e26 100644 --- a/model/build.go +++ b/model/build.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // swagger:model build diff --git a/model/build_test.go b/model/build_test.go index 1ac176cb1a..9220ac3d30 100644 --- a/model/build_test.go +++ b/model/build_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( diff --git a/model/cc.go b/model/cc.go index 590beb753a..f78b8076b0 100644 --- a/model/cc.go +++ b/model/cc.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( diff --git a/model/cc_test.go b/model/cc_test.go index 4d16727408..b5081c23ed 100644 --- a/model/cc_test.go +++ b/model/cc_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( diff --git a/model/config.go b/model/config.go index 572947596a..8eae6e34c1 100644 --- a/model/config.go +++ b/model/config.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // ConfigStore persists pipeline configuration to storage. diff --git a/model/const.go b/model/const.go index 2cfd2e994b..7b1bc465ee 100644 --- a/model/const.go +++ b/model/const.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model const ( diff --git a/model/environ.go b/model/environ.go index 3e3e00b5b6..ee2d0d5f51 100644 --- a/model/environ.go +++ b/model/environ.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( diff --git a/model/event.go b/model/event.go index e04803afc5..a230a88009 100644 --- a/model/event.go +++ b/model/event.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // EventType defines the possible types of build events. diff --git a/model/feed.go b/model/feed.go index 8e766e2192..35d7b9baca 100644 --- a/model/feed.go +++ b/model/feed.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // Feed represents an item in the user's feed or timeline. diff --git a/model/file.go b/model/file.go index fd41401785..3bf52a5ee3 100644 --- a/model/file.go +++ b/model/file.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import "io" diff --git a/model/limit.go b/model/limit.go index 46f50df191..2465700f4f 100644 --- a/model/limit.go +++ b/model/limit.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // Limiter defines an interface for limiting repository creation. @@ -10,7 +24,7 @@ type Limiter interface { LimitBuild(*User, *Repo, *Build) error } -// NoLimit impliments the Limiter interface without enforcing any +// NoLimit implements the Limiter interface without enforcing any // actual limits. All limiting functions are no-ops. type NoLimit struct{} diff --git a/model/netrc.go b/model/netrc.go index 1bb8e67adb..78661c852d 100644 --- a/model/netrc.go +++ b/model/netrc.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model type Netrc struct { diff --git a/model/perm.go b/model/perm.go index f0aa5e1842..03ba293509 100644 --- a/model/perm.go +++ b/model/perm.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // PermStore persists repository permissions information to storage. diff --git a/model/proc.go b/model/proc.go index d73001bdb3..c547725e62 100644 --- a/model/proc.go +++ b/model/proc.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // ProcStore persists process information to storage. diff --git a/model/queue.go b/model/queue.go index 660d3b7e7b..c5fdcdfdfe 100644 --- a/model/queue.go +++ b/model/queue.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( diff --git a/model/registry.go b/model/registry.go index 5f074800dc..f2ba1d0a8d 100644 --- a/model/registry.go +++ b/model/registry.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import "errors" diff --git a/model/repo.go b/model/repo.go index 4b22cf53d7..40a523931e 100644 --- a/model/repo.go +++ b/model/repo.go @@ -1,8 +1,22 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( - "strings" "fmt" + "strings" ) type RepoLite struct { diff --git a/model/resource_limit.go b/model/resource_limit.go index af2b68c7c6..ef18478706 100644 --- a/model/resource_limit.go +++ b/model/resource_limit.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // ResourceLimit is the resource limit to set on pipeline steps diff --git a/model/secret.go b/model/secret.go index 1cfd8a1081..4135b23879 100644 --- a/model/secret.go +++ b/model/secret.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( diff --git a/model/secret_test.go b/model/secret_test.go index 02c7cb248b..364d3b8da1 100644 --- a/model/secret_test.go +++ b/model/secret_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( diff --git a/model/sender.go b/model/sender.go index 7655067c75..e3bef4e5cb 100644 --- a/model/sender.go +++ b/model/sender.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model type SenderService interface { diff --git a/model/settings.go b/model/settings.go index b3722655fd..1f73a89e55 100644 --- a/model/settings.go +++ b/model/settings.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // Settings defines system configuration parameters. diff --git a/model/team.go b/model/team.go index c91d58666e..b4c4d9afaa 100644 --- a/model/team.go +++ b/model/team.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model // Team represents a team or organization in the remote version control system. diff --git a/model/user.go b/model/user.go index 37ac19af35..8936ceb154 100644 --- a/model/user.go +++ b/model/user.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import ( @@ -30,7 +44,7 @@ type User struct { // Secret is the oauth2 token secret. Secret string `json:"-" meddler:"user_secret"` - // Expiry is the token and secret expriation timestamp. + // Expiry is the token and secret expiration timestamp. Expiry int64 `json:"-" meddler:"user_expiry"` // Email is the email address for this user. diff --git a/model/user_test.go b/model/user_test.go index 27b568f516..fc7e9c39da 100644 --- a/model/user_test.go +++ b/model/user_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 model import "testing" diff --git a/plugins/secrets/plugin.go b/plugins/secrets/plugin.go new file mode 100644 index 0000000000..0ec22c5e94 --- /dev/null +++ b/plugins/secrets/plugin.go @@ -0,0 +1,48 @@ +// Copyright 2018 Drone.IO Inc +// Use of this software is governed by the Drone Enterpise License +// that can be found in the LICENSE file. + +package secrets + +import ( + "github.com/drone/drone/model" + "github.com/drone/drone/store" +) + +// NewDefault returns the Store wrapped as a Service. +func NewDefault(store store.Store) model.SecretService { + return New(store) +} + +// Plugin defines the required interface for implementing a remote +// secret plugin and sourcing secrets from an external source. +type Plugin interface { + SecretListBuild(*model.Repo, *model.Build) ([]*model.Secret, error) +} + +// Extend exetends the base secret service with the plugin. +func Extend(base model.SecretService, with Plugin) model.SecretService { + return &extender{base, with} +} + +type extender struct { + model.SecretService + plugin Plugin +} + +// extends the base secret service and combines the secret list with the +// secret list returned by the plugin. +func (e *extender) SecretListBuild(repo *model.Repo, build *model.Build) ([]*model.Secret, error) { + base, err := e.SecretService.SecretListBuild(repo, build) + if err != nil { + return nil, err + } + with, err := e.plugin.SecretListBuild(repo, build) + if err != nil { + return nil, err + } + for _, secret := range base { + with = append(with, secret) + } + return with, nil +} diff --git a/plugins/secrets/plugin_test.go b/plugins/secrets/plugin_test.go new file mode 100644 index 0000000000..3f411aea63 --- /dev/null +++ b/plugins/secrets/plugin_test.go @@ -0,0 +1,68 @@ +// Copyright 2018 Drone.IO Inc +// Use of this software is governed by the Drone Enterpise License +// that can be found in the LICENSE file. + +package secrets + +import ( + "testing" + + "github.com/drone/drone/model" +) + +func TestExtends(t *testing.T) { + base := &mocker{} + base.list = []*model.Secret{ + {Name: "foo"}, + {Name: "bar"}, + } + + with := &mocker{} + with.list = []*model.Secret{ + {Name: "baz"}, + {Name: "qux"}, + } + + extended := Extend(base, with) + list, err := extended.SecretListBuild(nil, nil) + if err != nil { + t.Errorf("Expected combined secret list, got error %q", err) + } + + if got, want := list[0], with.list[0]; got != want { + t.Errorf("Expected correct precedence. Want %s, got %s", want.Name, got.Name) + } + if got, want := list[1], with.list[1]; got != want { + t.Errorf("Expected correct precedence. Want %s, got %s", want.Name, got.Name) + } + if got, want := list[2], base.list[0]; got != want { + t.Errorf("Expected correct precedence. Want %s, got %s", want.Name, got.Name) + } + if got, want := list[3], base.list[1]; got != want { + t.Errorf("Expected correct precedence. Want %s, got %s", want.Name, got.Name) + } +} + +type mocker struct { + list []*model.Secret + error error +} + +func (m *mocker) SecretFind(*model.Repo, string) (*model.Secret, error) { + return nil, nil +} +func (m *mocker) SecretList(*model.Repo) ([]*model.Secret, error) { + return nil, nil +} +func (m *mocker) SecretListBuild(*model.Repo, *model.Build) ([]*model.Secret, error) { + return m.list, m.error +} +func (m *mocker) SecretCreate(*model.Repo, *model.Secret) error { + return nil +} +func (m *mocker) SecretUpdate(*model.Repo, *model.Secret) error { + return nil +} +func (m *mocker) SecretDelete(*model.Repo, string) error { + return nil +} diff --git a/plugins/secrets/vault/fixtures/fakeJwt b/plugins/secrets/vault/fixtures/fakeJwt new file mode 100644 index 0000000000..1e3abd126a --- /dev/null +++ b/plugins/secrets/vault/fixtures/fakeJwt @@ -0,0 +1 @@ +fakeJwt diff --git a/plugins/secrets/vault/kubernetes.go b/plugins/secrets/vault/kubernetes.go new file mode 100644 index 0000000000..32a88f5000 --- /dev/null +++ b/plugins/secrets/vault/kubernetes.go @@ -0,0 +1,48 @@ +package vault + +import ( + "fmt" + "github.com/drone/drone/plugins/internal" + "io/ioutil" + "time" +) + +/* +Vault JSON Response +{ + "auth": { + "client_token" = "token", + "lease_duration" = 1234 + } +} +*/ +type vaultAuth struct { + Token string `json:"client_token"` + Lease int `json:"lease_duration"` +} +type vaultResp struct { + Auth vaultAuth +} + +func getKubernetesToken(addr, role, mount, tokenFile string) (string, time.Duration, error) { + b, err := ioutil.ReadFile(tokenFile) + if err != nil { + return "", 0, err + } + + var resp vaultResp + path := fmt.Sprintf("%s/v1/auth/%s/login", addr, mount) + data := map[string]string{ + "jwt": string(b), + "role": role, + } + + err = internal.Send("POST", path, data, &resp) + if err != nil { + return "", 0, err + } + + ttl := time.Duration(resp.Auth.Lease) * time.Second + + return resp.Auth.Token, ttl, nil +} diff --git a/plugins/secrets/vault/kubernetes_test.go b/plugins/secrets/vault/kubernetes_test.go new file mode 100644 index 0000000000..42cfe6370a --- /dev/null +++ b/plugins/secrets/vault/kubernetes_test.go @@ -0,0 +1,69 @@ +package vault + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/http/httptest" + "testing" + "time" +) + +func TestGetKubernetesToken(t *testing.T) { + fakeRole := "fakeRole" + fakeMountPoint := "kubernetes" + fakeJwtFile := "fixtures/fakeJwt" + b, _ := ioutil.ReadFile(fakeJwtFile) + fakeJwt := string(b) + fakeClientToken := "fakeClientToken" + fakeLeaseSeconds := 86400 + fakeLeaseDuration := time.Duration(fakeLeaseSeconds) * time.Second + fakeResp := fmt.Sprintf("{\"auth\": {\"client_token\": \"%s\", \"lease_duration\": %d}}", fakeClientToken, fakeLeaseSeconds) + expectedPath := "/v1/auth/kubernetes/login" + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + if r.Method != "POST" { + t.Errorf("Expected 'POST' request, got '%s'", r.Method) + } + if r.URL.EscapedPath() != expectedPath { + t.Errorf("Expected request to '%s', got '%s'", expectedPath, r.URL.EscapedPath()) + } + + var postdata struct { + Jwt string + Role string + } + err := json.NewDecoder(r.Body).Decode(&postdata) + if err != nil { + t.Errorf("Encountered error parsing request JSON: %s", err) + } + + jwt := postdata.Jwt + + if jwt != fakeJwt { + t.Errorf("Expected request to have jwt with value '%s', got: '%s'", fakeJwt, jwt) + } + role := postdata.Role + if role != fakeRole { + t.Errorf("Expected request to have role with value '%s', got: '%s'", fakeRole, role) + } + + fmt.Fprintf(w, fakeResp) + })) + defer ts.Close() + + url := ts.URL + token, ttl, err := getKubernetesToken(url, fakeRole, fakeMountPoint, fakeJwtFile) + if err != nil { + t.Errorf("getKubernetesToken returned an error: %s", err) + } + + if token != fakeClientToken { + t.Errorf("Expected returned token to have value '%s', got: '%s'", fakeClientToken, token) + } + if ttl != fakeLeaseDuration { + t.Errorf("Expected TTL to have value '%s', got: '%s'", fakeLeaseDuration.Seconds(), ttl.Seconds()) + } +} diff --git a/plugins/secrets/vault/opts.go b/plugins/secrets/vault/opts.go new file mode 100644 index 0000000000..7b4eaa7ebc --- /dev/null +++ b/plugins/secrets/vault/opts.go @@ -0,0 +1,45 @@ +// Copyright 2018 Drone.IO Inc +// Use of this software is governed by the Drone Enterpise License +// that can be found in the LICENSE file. + +package vault + +import "time" + +// Opts sets custom options for the vault client. +type Opts func(v *vault) + +// WithTTL returns an options that sets a TTL used to +// refresh periodic tokens. +func WithTTL(d time.Duration) Opts { + return func(v *vault) { + v.ttl = d + } +} + +// WithRenewal returns an options that sets the renewal +// period used to refresh periodic tokens +func WithRenewal(d time.Duration) Opts { + return func(v *vault) { + v.renew = d + } +} + +// WithAuth returns an options that sets the vault +// method to use for authentication +func WithAuth(method string) Opts { + return func(v *vault) { + v.auth = method + } +} + +// WithKubernetes returns an options that sets +// kubernetes-auth parameters required to retrieve +// an initial vault token +func WithKubernetesAuth(addr, role, mount string) Opts { + return func(v *vault) { + v.kubeAuth.addr = addr + v.kubeAuth.role = role + v.kubeAuth.mount = mount + } +} diff --git a/plugins/secrets/vault/opts_test.go b/plugins/secrets/vault/opts_test.go new file mode 100644 index 0000000000..8739071518 --- /dev/null +++ b/plugins/secrets/vault/opts_test.go @@ -0,0 +1,56 @@ +// Copyright 2018 Drone.IO Inc +// Use of this software is governed by the Drone Enterpise License +// that can be found in the LICENSE file. + +package vault + +import ( + "testing" + "time" +) + +func TestWithTTL(t *testing.T) { + v := new(vault) + opt := WithTTL(time.Hour) + opt(v) + if got, want := v.ttl, time.Hour; got != want { + t.Errorf("Want ttl %v, got %v", want, got) + } +} + +func TestWithRenewal(t *testing.T) { + v := new(vault) + opt := WithRenewal(time.Hour) + opt(v) + if got, want := v.renew, time.Hour; got != want { + t.Errorf("Want renewal %v, got %v", want, got) + } +} + +func TestWithAuth(t *testing.T) { + v := new(vault) + method := "kubernetes" + opt := WithAuth(method) + opt(v) + if got, want := v.auth, method; got != want { + t.Errorf("Want auth %v, got %v", want, got) + } +} + +func TestWithKubernetesAuth(t *testing.T) { + v := new(vault) + addr := "https://address.fake" + role := "fakeRole" + mount := "kubernetes" + opt := WithKubernetesAuth(addr, role, mount) + opt(v) + if got, want := v.kubeAuth.addr, addr; got != want { + t.Errorf("Want addr %v, got %v", want, got) + } + if got, want := v.kubeAuth.role, role; got != want { + t.Errorf("Want role %v, got %v", want, got) + } + if got, want := v.kubeAuth.mount, mount; got != want { + t.Errorf("Want mount %v, got %v", want, got) + } +} diff --git a/plugins/secrets/vault/vault.go b/plugins/secrets/vault/vault.go new file mode 100644 index 0000000000..ebad6859b1 --- /dev/null +++ b/plugins/secrets/vault/vault.go @@ -0,0 +1,269 @@ +// Copyright 2018 Drone.IO Inc +// Use of this software is governed by the Drone Enterpise License +// that can be found in the LICENSE file. + +package vault + +import ( + "path" + "strings" + "time" + + "github.com/Sirupsen/logrus" + "github.com/drone/drone/model" + "github.com/drone/drone/plugins/secrets" + + "github.com/hashicorp/vault/api" + "gopkg.in/yaml.v2" +) + +// yaml configuration representation +// +// secrets: +// docker_username: +// file: path/to/docker/username +// docker_password: +// file: path/to/docker/password +// +type vaultConfig struct { + Secrets map[string]struct { + Driver string + DriverOpts struct { + Path string + Key string + } `yaml:"driver_opts"` + + // deprecated. do not use. + Vault string + Path string + File string + } +} + +type vault struct { + store model.ConfigStore + client *api.Client + ttl time.Duration + renew time.Duration + auth string + kubeAuth kubeAuth + done chan struct{} +} + +type kubeAuth struct { + addr, role, mount string +} + +// New returns a new store with secrets loaded from vault. +func New(store model.ConfigStore, opts ...Opts) (secrets.Plugin, error) { + client, err := api.NewClient(nil) + if err != nil { + return nil, err + } + v := &vault{ + store: store, + client: client, + } + for _, opt := range opts { + opt(v) + } + if v.auth == "kubernetes" { + err = v.initKubernetes() + if err != nil { + return nil, err + } + } + v.start() // start the refresh process. + return v, nil +} + +func (v *vault) initKubernetes() error { + token, ttl, err := getKubernetesToken( + v.kubeAuth.addr, + v.kubeAuth.role, + v.kubeAuth.mount, + "/var/run/secrets/kubernetes.io/serviceaccount/token", + ) + if err != nil { + logrus.Debugf("vault: failed to obtain token via kubernetes-auth backend: %s", err) + return err + } + + v.client.SetToken(token) + v.ttl = ttl + v.renew = ttl / 2 + return nil +} + +func (v *vault) SecretListBuild(repo *model.Repo, build *model.Build) ([]*model.Secret, error) { + return v.list(repo, build) +} + +func (v *vault) list(repo *model.Repo, build *model.Build) ([]*model.Secret, error) { + conf, err := v.store.ConfigLoad(build.ConfigID) + if err != nil { + return nil, err + } + var ( + in = []byte(conf.Data) + out = new(vaultConfig) + + secrets []*model.Secret + ) + err = yaml.Unmarshal(in, out) + if err != nil { + return nil, err + } + for key, val := range out.Secrets { + var path, field string + switch { + case val.Path != "": + path = val.Path + case val.File != "": + path = val.File + case val.Vault != "": + path = val.Vault + case val.DriverOpts.Path != "": + path = val.DriverOpts.Path + field = val.DriverOpts.Key + } + if field == "" { + field = "value" + } + + if path == "" { + continue + } + + logrus.Debugf("vault: read secret: %s", path) + + vaultSecret, err := v.get(path, field) + if err != nil { + logrus.Debugf("vault: read secret failed: %s: %s", path, err) + return nil, err + } + if vaultSecret == nil { + logrus.Debugf("vault: read secret failed: %s: not found or empty value", path) + continue + } + if !vaultSecret.Match(repo.FullName) { + logrus.Debugf("vault: read secret: %s: restricted: %s", path, repo.FullName) + continue + } + + logrus.Debugf("vault: read secret success: %s", err) + + secrets = append(secrets, &model.Secret{ + Name: key, + Value: vaultSecret.Value, + Events: vaultSecret.Event, + Images: vaultSecret.Image, + }) + } + return secrets, nil +} + +func (v *vault) get(path, key string) (*vaultSecret, error) { + secret, err := v.client.Logical().Read(path) + if err != nil { + return nil, err + } + if secret == nil || secret.Data == nil { + return nil, nil + } + return parseVaultSecret(secret.Data, key), nil +} + +// start starts the renewal loop. +func (v *vault) start() { + if v.renew == 0 || v.ttl == 0 { + logrus.Debugf("vault: token renewal disabled") + return + } + if v.done != nil { + close(v.done) + } + logrus.Infof("vault: token renewal enabled: renew every %v", v.renew) + v.done = make(chan struct{}) + if v.renew != 0 { + go v.renewLoop() + } +} + +// stop stops the renewal loop. +func (v *vault) stop() { + close(v.done) +} + +func (v *vault) renewLoop() { + for { + select { + case <-time.After(v.renew): + incr := int(v.ttl / time.Second) + + logrus.Debugf("vault: refreshing token: increment %v", v.ttl) + _, err := v.client.Auth().Token().RenewSelf(incr) + if err != nil { + logrus.Errorf("vault: refreshing token failed: %s", err) + } else { + logrus.Debugf("vault: refreshing token succeeded") + } + case <-v.done: + return + } + } +} + +type vaultSecret struct { + Value string + Image []string + Event []string + Repo []string +} + +func parseVaultSecret(data map[string]interface{}, key string) *vaultSecret { + secret := new(vaultSecret) + + if vvalue, ok := data[key]; ok { + if svalue, ok := vvalue.(string); ok { + secret.Value = svalue + } + } + if vimage, ok := data["image"]; ok { + if simage, ok := vimage.(string); ok { + secret.Image = strings.Split(simage, ",") + } + } + if vevent, ok := data["event"]; ok { + if sevent, ok := vevent.(string); ok { + secret.Event = strings.Split(sevent, ",") + } + } + if vrepo, ok := data["repo"]; ok { + if srepo, ok := vrepo.(string); ok { + secret.Repo = strings.Split(srepo, ",") + } + } + if secret.Event == nil { + secret.Event = []string{} + } + if secret.Image == nil { + secret.Image = []string{} + } + if secret.Repo == nil { + secret.Repo = []string{} + } + return secret +} + +func (v *vaultSecret) Match(name string) bool { + if len(v.Repo) == 0 { + return true + } + for _, pattern := range v.Repo { + if ok, _ := path.Match(pattern, name); ok { + return true + } + } + return false +} diff --git a/plugins/secrets/vault/vault_test.go b/plugins/secrets/vault/vault_test.go new file mode 100644 index 0000000000..cceb5a98f6 --- /dev/null +++ b/plugins/secrets/vault/vault_test.go @@ -0,0 +1,108 @@ +// Copyright 2018 Drone.IO Inc +// Use of this software is governed by the Drone Enterpise License +// that can be found in the LICENSE file. + +package vault + +import ( + "os" + "reflect" + "testing" + + "github.com/hashicorp/vault/api" + "github.com/kr/pretty" +) + +// Use the following snippet to spin up a local vault +// server for integration testing: +// +// docker run --cap-add=IPC_LOCK -e 'VAULT_DEV_ROOT_TOKEN_ID=dummy' -p 8200:8200 vault +// export VAULT_ADDR=http://127.0.0.1:8200 +// export VAULT_TOKEN=dummy + +func TestVaultGet(t *testing.T) { + if os.Getenv("VAULT_TOKEN") == "" { + t.SkipNow() + return + } + + client, err := api.NewClient(nil) + if err != nil { + t.Error(err) + return + } + + _, err = client.Logical().Write("secret/testing/drone/a", map[string]interface{}{ + "value": "hello", + "fr": "bonjour", + "image": "golang", + "event": "push,pull_request", + "repo": "octocat/hello-world,github/*", + }) + if err != nil { + t.Error(err) + return + } + + plugin := vault{client: client} + secret, err := plugin.get("secret/testing/drone/a", "value") + if err != nil { + t.Error(err) + return + } + if got, want := secret.Value, "hello"; got != want { + t.Errorf("Expect secret value %s, got %s", want, got) + } + + secret, err = plugin.get("secret/testing/drone/a", "fr") + if err != nil { + t.Error(err) + return + } + if got, want := secret.Value, "bonjour"; got != want { + t.Errorf("Expect secret value %s, got %s", want, got) + } + + secret, err = plugin.get("secret/testing/drone/404", "value") + if err != nil { + t.Errorf("Expect silent failure when secret does not exist, got %s", err) + } + if secret != nil { + t.Errorf("Expect nil secret when path does not exist") + } +} + +func TestVaultSecretParse(t *testing.T) { + data := map[string]interface{}{ + "value": "password", + "event": "push,tag", + "image": "plugins/s3,plugins/ec2", + "repo": "octocat/hello-world,github/*", + } + want := vaultSecret{ + Value: "password", + Event: []string{"push", "tag"}, + Image: []string{"plugins/s3", "plugins/ec2"}, + Repo: []string{"octocat/hello-world", "github/*"}, + } + got := parseVaultSecret(data, "value") + if !reflect.DeepEqual(want, *got) { + t.Errorf("Failed read Secret.Data") + pretty.Fdiff(os.Stderr, want, got) + } +} + +func TestVaultSecretMatch(t *testing.T) { + secret := vaultSecret{ + Repo: []string{"octocat/hello-world", "github/*"}, + } + if secret.Match("octocat/*") { + t.Errorf("Expect octocat/* does not match") + } + if !secret.Match("octocat/hello-world") { + t.Errorf("Expect octocat/hello-world does match") + } + if !secret.Match("github/hello-world") { + t.Errorf("Expect github/hello-world does match wildcard") + } +} diff --git a/plugins/sender/plugin.go b/plugins/sender/plugin.go index 313f24ed71..a875989cb8 100644 --- a/plugins/sender/plugin.go +++ b/plugins/sender/plugin.go @@ -19,7 +19,7 @@ func NewRemote(endpoint string) model.SenderService { func (p *plugin) SenderAllowed(user *model.User, repo *model.Repo, build *model.Build, conf *model.Config) (bool, error) { path := fmt.Sprintf("%s/senders/%s/%s/%s/verify", p.endpoint, repo.Owner, repo.Name, build.Sender) data := map[string]interface{}{ - "build": build, + "build": build, "config": conf, } err := internal.Send("POST", path, &data, nil) diff --git a/remote/bitbucket/bitbucket.go b/remote/bitbucket/bitbucket.go index 3632fa2629..35ec84f28d 100644 --- a/remote/bitbucket/bitbucket.go +++ b/remote/bitbucket/bitbucket.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucket import ( @@ -162,17 +176,27 @@ func (c *config) Perm(u *model.User, owner, name string) (*model.Perm, error) { client := c.newClient(u) perms := new(model.Perm) - _, err := client.FindRepo(owner, name) + repo, err := client.FindRepo(owner, name) if err != nil { return perms, err } - _, err = client.ListHooks(owner, name, &internal.ListOpts{}) - if err == nil { - perms.Push = true + perm, err := client.GetPermission(repo.FullName) + if err != nil { + return perms, err + } + + switch perm.Permission { + case "admin": perms.Admin = true + fallthrough + case "write": + perms.Push = true + fallthrough + default: + perms.Pull = true } - perms.Pull = true + return perms, nil } diff --git a/remote/bitbucket/bitbucket_test.go b/remote/bitbucket/bitbucket_test.go index f00b19875b..91172321b1 100644 --- a/remote/bitbucket/bitbucket_test.go +++ b/remote/bitbucket/bitbucket_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucket import ( @@ -147,19 +161,30 @@ func Test_bitbucket(t *testing.T) { g.It("Should authorize read access", func() { perm, err := c.Perm( fakeUser, - fakeRepoNoHooks.Owner, - fakeRepoNoHooks.Name, + fakeRepoReadOnly.Owner, + fakeRepoReadOnly.Name, ) g.Assert(err == nil).IsTrue() g.Assert(perm.Pull).IsTrue() g.Assert(perm.Push).IsFalse() g.Assert(perm.Admin).IsFalse() }) + g.It("Should authorize write access", func() { + perm, err := c.Perm( + fakeUser, + fakeRepoWriteOnly.Owner, + fakeRepoWriteOnly.Name, + ) + g.Assert(err == nil).IsTrue() + g.Assert(perm.Pull).IsTrue() + g.Assert(perm.Push).IsTrue() + g.Assert(perm.Admin).IsFalse() + }) g.It("Should authorize admin access", func() { perm, err := c.Perm( fakeUser, - fakeRepo.Owner, - fakeRepo.Name, + fakeRepoAdmin.Owner, + fakeRepoAdmin.Name, ) g.Assert(err == nil).IsTrue() g.Assert(perm.Pull).IsTrue() @@ -336,6 +361,24 @@ var ( FullName: "test_name/hook_empty", } + fakeRepoReadOnly = &model.Repo{ + Owner: "test_name", + Name: "permission_read", + FullName: "test_name/permission_read", + } + + fakeRepoWriteOnly = &model.Repo{ + Owner: "test_name", + Name: "permission_write", + FullName: "test_name/permission_write", + } + + fakeRepoAdmin = &model.Repo{ + Owner: "test_name", + Name: "permission_admin", + FullName: "test_name/permission_admin", + } + fakeBuild = &model.Build{ Commit: "9ecad50", } diff --git a/remote/bitbucket/convert.go b/remote/bitbucket/convert.go index b5627bc716..985ae46323 100644 --- a/remote/bitbucket/convert.go +++ b/remote/bitbucket/convert.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucket import ( diff --git a/remote/bitbucket/convert_test.go b/remote/bitbucket/convert_test.go index 74903f5c6a..cc0d590ad2 100644 --- a/remote/bitbucket/convert_test.go +++ b/remote/bitbucket/convert_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucket import ( diff --git a/remote/bitbucket/fixtures/handler.go b/remote/bitbucket/fixtures/handler.go index 96aff73e0a..f0565995ba 100644 --- a/remote/bitbucket/fixtures/handler.go +++ b/remote/bitbucket/fixtures/handler.go @@ -1,6 +1,21 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures import ( + "fmt" "net/http" "github.com/gin-gonic/gin" @@ -22,6 +37,7 @@ func Handler() http.Handler { e.GET("/2.0/repositories/:owner", getUserRepos) e.GET("/2.0/teams/", getUserTeams) e.GET("/2.0/user/", getUser) + e.GET("/2.0/user/permissions/repositories", getPermissions) return e } @@ -56,6 +72,8 @@ func getRepo(c *gin.Context) { switch c.Param("name") { case "not_found", "repo_unknown", "repo_not_found": c.String(404, "") + case "permission_read", "permission_write", "permission_admin": + c.String(200, fmt.Sprintf(permissionRepoPayload, c.Param("name"))) default: c.String(200, repoPayload) } @@ -130,6 +148,24 @@ func getUserRepos(c *gin.Context) { } } +func permission(p string) string { + return fmt.Sprintf(permissionPayload, p) +} + +func getPermissions(c *gin.Context) { + query := c.Request.URL.Query()["q"][0] + switch query { + case `repository.full_name="test_name/permission_read"`: + c.String(200, permission("read")) + case `repository.full_name="test_name/permission_write"`: + c.String(200, permission("write")) + case `repository.full_name="test_name/permission_admin"`: + c.String(200, permission("admin")) + default: + c.String(200, permission("read")) + } +} + const tokenPayload = ` { "access_token":"2YotnFZFEjr1zCsicMWpAA", @@ -156,6 +192,14 @@ const repoPayload = ` } ` +const permissionRepoPayload = ` +{ + "full_name": "test_name/%s", + "scm": "git", + "is_private": true +} +` + const repoHookPayload = ` { "pagelen": 10, @@ -224,3 +268,15 @@ const userTeamPayload = ` ] } ` + +const permissionPayload = ` +{ + "pagelen": 1, + "values": [ + { + "permission": "%s" + } + ], + "page": 1 +} +` diff --git a/remote/bitbucket/fixtures/hooks.go b/remote/bitbucket/fixtures/hooks.go index 2ee0823ad3..4d30623397 100644 --- a/remote/bitbucket/fixtures/hooks.go +++ b/remote/bitbucket/fixtures/hooks.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures const HookPush = ` diff --git a/remote/bitbucket/internal/client.go b/remote/bitbucket/internal/client.go index 781b3d07b9..71ea12a7a8 100644 --- a/remote/bitbucket/internal/client.go +++ b/remote/bitbucket/internal/client.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( @@ -20,15 +34,16 @@ const ( ) const ( - pathUser = "%s/2.0/user/" - pathEmails = "%s/2.0/user/emails" - pathTeams = "%s/2.0/teams/?%s" - pathRepo = "%s/2.0/repositories/%s/%s" - pathRepos = "%s/2.0/repositories/%s?%s" - pathHook = "%s/2.0/repositories/%s/%s/hooks/%s" - pathHooks = "%s/2.0/repositories/%s/%s/hooks?%s" - pathSource = "%s/1.0/repositories/%s/%s/src/%s/%s" - pathStatus = "%s/2.0/repositories/%s/%s/commit/%s/statuses/build" + pathUser = "%s/2.0/user/" + pathEmails = "%s/2.0/user/emails" + pathPermissions = "%s/2.0/user/permissions/repositories?q=repository.full_name=%q" + pathTeams = "%s/2.0/teams/?%s" + pathRepo = "%s/2.0/repositories/%s/%s" + pathRepos = "%s/2.0/repositories/%s?%s" + pathHook = "%s/2.0/repositories/%s/%s/hooks/%s" + pathHooks = "%s/2.0/repositories/%s/%s/hooks?%s" + pathSource = "%s/1.0/repositories/%s/%s/src/%s/%s" + pathStatus = "%s/2.0/repositories/%s/%s/commit/%s/statuses/build" ) type Client struct { @@ -138,6 +153,22 @@ func (c *Client) CreateStatus(owner, name, revision string, status *BuildStatus) return c.do(uri, post, status, nil) } +func (c *Client) GetPermission(fullName string) (*RepoPerm, error) { + out := new(RepoPermResp) + uri := fmt.Sprintf(pathPermissions, c.base, fullName) + err := c.do(uri, get, nil, out) + + if err != nil { + return nil, err + } + + if len(out.Values) == 0 { + return nil, fmt.Errorf("no permissions in repository %s", fullName) + } else { + return out.Values[0], nil + } +} + func (c *Client) do(rawurl, method string, in, out interface{}) error { uri, err := url.Parse(rawurl) diff --git a/remote/bitbucket/internal/types.go b/remote/bitbucket/internal/types.go index b92d22e08e..652b037cc0 100644 --- a/remote/bitbucket/internal/types.go +++ b/remote/bitbucket/internal/types.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( @@ -210,3 +224,13 @@ type Error struct { func (e Error) Error() string { return e.Body.Message } + +type RepoPermResp struct { + Page int `json:"page"` + Pages int `json:"pagelen"` + Values []*RepoPerm `json:"values"` +} + +type RepoPerm struct { + Permission string `json:"permission"` +} diff --git a/remote/bitbucket/parse.go b/remote/bitbucket/parse.go index 7ab385d38c..dd0c3743ae 100644 --- a/remote/bitbucket/parse.go +++ b/remote/bitbucket/parse.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucket import ( diff --git a/remote/bitbucket/parse_test.go b/remote/bitbucket/parse_test.go index eee2bda365..6a2261908d 100644 --- a/remote/bitbucket/parse_test.go +++ b/remote/bitbucket/parse_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucket import ( diff --git a/remote/bitbucketserver/bitbucketserver.go b/remote/bitbucketserver/bitbucketserver.go index b041b5ce4a..057fa510b2 100644 --- a/remote/bitbucketserver/bitbucketserver.go +++ b/remote/bitbucketserver/bitbucketserver.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucketserver // WARNING! This is an work-in-progress patch and does not yet conform to the coding, diff --git a/remote/bitbucketserver/convert.go b/remote/bitbucketserver/convert.go index cf1f6b71a3..4ea5d9ae0d 100644 --- a/remote/bitbucketserver/convert.go +++ b/remote/bitbucketserver/convert.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucketserver import ( diff --git a/remote/bitbucketserver/convert_test.go b/remote/bitbucketserver/convert_test.go index 2860d601f7..c364efdc86 100644 --- a/remote/bitbucketserver/convert_test.go +++ b/remote/bitbucketserver/convert_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucketserver import ( diff --git a/remote/bitbucketserver/internal/client.go b/remote/bitbucketserver/internal/client.go index 3b9d84c474..b569fcb181 100644 --- a/remote/bitbucketserver/internal/client.go +++ b/remote/bitbucketserver/internal/client.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( diff --git a/remote/bitbucketserver/internal/types.go b/remote/bitbucketserver/internal/types.go index ec74e3cb99..a1ff81b1c1 100644 --- a/remote/bitbucketserver/internal/types.go +++ b/remote/bitbucketserver/internal/types.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal type User struct { diff --git a/remote/bitbucketserver/parse.go b/remote/bitbucketserver/parse.go index be53525382..0ec3e127ce 100644 --- a/remote/bitbucketserver/parse.go +++ b/remote/bitbucketserver/parse.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 bitbucketserver import ( diff --git a/remote/coding/coding.go b/remote/coding/coding.go index 4d98ffe9dd..eb516a908a 100644 --- a/remote/coding/coding.go +++ b/remote/coding/coding.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 coding import ( diff --git a/remote/coding/coding_test.go b/remote/coding/coding_test.go index 149ba996c9..6d3daa9710 100644 --- a/remote/coding/coding_test.go +++ b/remote/coding/coding_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 coding import ( diff --git a/remote/coding/fixtures/handler.go b/remote/coding/fixtures/handler.go index cf5cbb434a..a0e7ce8b8c 100644 --- a/remote/coding/fixtures/handler.go +++ b/remote/coding/fixtures/handler.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures import ( diff --git a/remote/coding/fixtures/hooks.go b/remote/coding/fixtures/hooks.go index 8253a6af57..6a7a63ff26 100644 --- a/remote/coding/fixtures/hooks.go +++ b/remote/coding/fixtures/hooks.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures const PushHook = ` diff --git a/remote/coding/hook.go b/remote/coding/hook.go index d073f16681..241e18babe 100644 --- a/remote/coding/hook.go +++ b/remote/coding/hook.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 coding import ( diff --git a/remote/coding/hook_test.go b/remote/coding/hook_test.go index 66483e42ff..f6f77e495a 100644 --- a/remote/coding/hook_test.go +++ b/remote/coding/hook_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 coding import ( diff --git a/remote/coding/internal/coding.go b/remote/coding/internal/coding.go index f6fc98fddf..430241f4a0 100644 --- a/remote/coding/internal/coding.go +++ b/remote/coding/internal/coding.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( diff --git a/remote/coding/internal/error.go b/remote/coding/internal/error.go index fefb9bc3eb..4de2d47be7 100644 --- a/remote/coding/internal/error.go +++ b/remote/coding/internal/error.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( diff --git a/remote/coding/internal/file.go b/remote/coding/internal/file.go index 358a21ae6b..664c4a035f 100644 --- a/remote/coding/internal/file.go +++ b/remote/coding/internal/file.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( diff --git a/remote/coding/internal/project.go b/remote/coding/internal/project.go index f799c78d83..6d7557795b 100644 --- a/remote/coding/internal/project.go +++ b/remote/coding/internal/project.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( diff --git a/remote/coding/internal/user.go b/remote/coding/internal/user.go index 0867483a5a..b6ca421545 100644 --- a/remote/coding/internal/user.go +++ b/remote/coding/internal/user.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( diff --git a/remote/coding/internal/webhook.go b/remote/coding/internal/webhook.go index 3bc0e833a3..d172518983 100644 --- a/remote/coding/internal/webhook.go +++ b/remote/coding/internal/webhook.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 internal import ( diff --git a/remote/coding/util.go b/remote/coding/util.go index 9a553ea043..abe8b4e3dd 100644 --- a/remote/coding/util.go +++ b/remote/coding/util.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 coding import ( diff --git a/remote/coding/util_test.go b/remote/coding/util_test.go index 704b82e97c..4cd98a607e 100644 --- a/remote/coding/util_test.go +++ b/remote/coding/util_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 coding import ( diff --git a/remote/context.go b/remote/context.go index 16ad2b84ed..5bfccc036e 100644 --- a/remote/context.go +++ b/remote/context.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 remote import ( diff --git a/remote/errors.go b/remote/errors.go index 0ad31e7691..d3df06ecdf 100644 --- a/remote/errors.go +++ b/remote/errors.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 remote // AuthError represents remote authentication error. diff --git a/remote/gerrit/gerrit.go b/remote/gerrit/gerrit.go index 4ddc6a32b8..93ade56624 100644 --- a/remote/gerrit/gerrit.go +++ b/remote/gerrit/gerrit.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gerrit import ( @@ -11,7 +25,7 @@ import ( ) // IMPORTANT Gerrit support is not yet implemented. This file is a placeholder -// for future implementaiton. +// for future implementation. // Opts defines configuration options. type Opts struct { @@ -52,7 +66,7 @@ func New(opts Opts) (remote.Remote, error) { }, nil } -// Login authenticates an account with Gerrit using oauth authenticaiton. The +// Login authenticates an account with Gerrit using oauth authentication. The // Gerrit account details are returned when the user is successfully authenticated. func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User, error) { return nil, nil diff --git a/remote/gitea/fixtures/handler.go b/remote/gitea/fixtures/handler.go index ca6d319afc..70bf85f3a4 100644 --- a/remote/gitea/fixtures/handler.go +++ b/remote/gitea/fixtures/handler.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures import ( diff --git a/remote/gitea/fixtures/hooks.go b/remote/gitea/fixtures/hooks.go index 0765a8c07d..0893403652 100644 --- a/remote/gitea/fixtures/hooks.go +++ b/remote/gitea/fixtures/hooks.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures // HookPush is a sample Gitea push hook @@ -46,6 +60,7 @@ const HookPush = ` "login": "gordon", "id": 1, "username": "gordon", + "email": "gordon@golang.org", "avatar_url": "http://gitea.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87" } } @@ -53,6 +68,7 @@ const HookPush = ` // HookPushTag is a sample Gitea tag hook const HookPushTag = `{ + "sha": "ef98532add3b2feb7a137426bba1248724367df5", "secret": "l26Un7G7HXogLAvsyf2hOA4EMARSTsR3", "ref": "v1.0.0", "ref_type": "tag", @@ -102,13 +118,11 @@ const HookPullRequest = `{ "email": "gordon@golang.org", "avatar_url": "http://gitea.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87" }, - "base_branch": "master", "base": { "label": "master", "ref": "master", "sha": "9353195a19e45482665306e466c832c46560532d" }, - "head_branch": "feature/changes", "head": { "label": "feature/changes", "ref": "feature/changes", diff --git a/remote/gitea/gitea.go b/remote/gitea/gitea.go index e9d1fa2d25..1773007f90 100644 --- a/remote/gitea/gitea.go +++ b/remote/gitea/gitea.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitea import ( @@ -15,6 +29,7 @@ import ( // Opts defines configuration options. type Opts struct { URL string // Gitea server url. + Context string // Context to display in status check Username string // Optional machine account username. Password string // Optional machine account password. PrivateMode bool // Gitea is running in private mode. @@ -23,6 +38,7 @@ type Opts struct { type client struct { URL string + Context string Machine string Username string Password string @@ -97,6 +113,7 @@ func New(opts Opts) (remote.Remote, error) { } return &client{ URL: opts.URL, + Context: opts.Context, Machine: url.Host, Username: opts.Username, Password: opts.Password, @@ -105,7 +122,7 @@ func New(opts Opts) (remote.Remote, error) { }, nil } -// Login authenticates an account with Gitea using basic authenticaiton. The +// Login authenticates an account with Gitea using basic authentication. The // Gitea account details are returned when the user is successfully authenticated. func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User, error) { var ( @@ -252,7 +269,7 @@ func (c *client) Status(u *model.User, r *model.Repo, b *model.Build, link strin State: status, TargetURL: link, Description: desc, - Context: "", + Context: c.Context, }, ) @@ -271,8 +288,8 @@ func (c *client) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) { }, nil } return &model.Netrc{ - Login: u.Token, - Password: "x-oauth-basic", + Login: u.Login, + Password: u.Token, Machine: c.Machine, }, nil } diff --git a/remote/gitea/gitea_test.go b/remote/gitea/gitea_test.go index 15f00e0a7c..17f3610f1c 100644 --- a/remote/gitea/gitea_test.go +++ b/remote/gitea/gitea_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitea import ( @@ -30,12 +44,14 @@ func Test_gitea(t *testing.T) { g.It("Should return client with specified options", func() { remote, _ := New(Opts{ URL: "http://localhost:8080", + Context: "continuous-integration/test", Username: "someuser", Password: "password", SkipVerify: true, PrivateMode: true, }) g.Assert(remote.(*client).URL).Equal("http://localhost:8080") + g.Assert(remote.(*client).Context).Equal("continuous-integration/test") g.Assert(remote.(*client).Machine).Equal("localhost") g.Assert(remote.(*client).Username).Equal("someuser") g.Assert(remote.(*client).Password).Equal("password") @@ -55,8 +71,8 @@ func Test_gitea(t *testing.T) { }) netrc, _ := remote.Netrc(fakeUser, nil) g.Assert(netrc.Machine).Equal("gitea.com") - g.Assert(netrc.Login).Equal(fakeUser.Token) - g.Assert(netrc.Password).Equal("x-oauth-basic") + g.Assert(netrc.Login).Equal(fakeUser.Login) + g.Assert(netrc.Password).Equal(fakeUser.Token) }) g.It("Should return a netrc with the machine account", func() { remote, _ := New(Opts{ diff --git a/remote/gitea/helper.go b/remote/gitea/helper.go index d625dc0407..0b0a918ac6 100644 --- a/remote/gitea/helper.go +++ b/remote/gitea/helper.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitea import ( @@ -77,7 +91,7 @@ func buildFromPush(hook *pushHook) *model.Build { Message: hook.Commits[0].Message, Avatar: avatar, Author: author, - Email: hook.Pusher.Email, + Email: hook.Sender.Email, Timestamp: time.Now().UTC().Unix(), Sender: sender, } @@ -100,9 +114,9 @@ func buildFromTag(hook *pushHook) *model.Build { return &model.Build{ Event: model.EventTag, - Commit: hook.After, + Commit: hook.Sha, Ref: fmt.Sprintf("refs/tags/%s", hook.Ref), - Link: fmt.Sprintf("%s/src/%s", hook.Repo.URL, hook.Ref), + Link: fmt.Sprintf("%s/src/tag/%s", hook.Repo.URL, hook.Ref), Branch: fmt.Sprintf("refs/tags/%s", hook.Ref), Message: fmt.Sprintf("created tag %s", hook.Ref), Avatar: avatar, @@ -127,15 +141,15 @@ func buildFromPullRequest(hook *pullRequestHook) *model.Build { Commit: hook.PullRequest.Head.Sha, Link: hook.PullRequest.URL, Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), - Branch: hook.PullRequest.BaseBranch, + Branch: hook.PullRequest.Base.Ref, Message: hook.PullRequest.Title, Author: hook.PullRequest.User.Username, Avatar: avatar, Sender: sender, Title: hook.PullRequest.Title, Refspec: fmt.Sprintf("%s:%s", - hook.PullRequest.HeadBranch, - hook.PullRequest.BaseBranch, + hook.PullRequest.Head.Ref, + hook.PullRequest.Base.Ref, ), } return build diff --git a/remote/gitea/helper_test.go b/remote/gitea/helper_test.go index 4bdcdc41bd..30c4272995 100644 --- a/remote/gitea/helper_test.go +++ b/remote/gitea/helper_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitea import ( @@ -44,6 +58,7 @@ func Test_parse(t *testing.T) { hook, err := parsePush(buf) g.Assert(err == nil).IsTrue() g.Assert(hook.Ref).Equal("v1.0.0") + g.Assert(hook.Sha).Equal("ef98532add3b2feb7a137426bba1248724367df5") g.Assert(hook.Repo.Name).Equal("hello-world") g.Assert(hook.Repo.URL).Equal("http://gitea.golang.org/gordon/hello-world") g.Assert(hook.Repo.FullName).Equal("gordon/hello-world") @@ -105,6 +120,18 @@ func Test_parse(t *testing.T) { g.Assert(repo.Link).Equal(hook.Repo.URL) }) + g.It("Should return a Build struct from a tag hook", func() { + buf := bytes.NewBufferString(fixtures.HookPushTag) + hook, _ := parsePush(buf) + build := buildFromTag(hook) + g.Assert(build.Event).Equal(model.EventTag) + g.Assert(build.Commit).Equal(hook.Sha) + g.Assert(build.Ref).Equal("refs/tags/v1.0.0") + g.Assert(build.Branch).Equal("refs/tags/v1.0.0") + g.Assert(build.Link).Equal("http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0") + g.Assert(build.Message).Equal("created tag v1.0.0") + }) + g.It("Should return a Build struct from a pull_request hook", func() { buf := bytes.NewBufferString(fixtures.HookPullRequest) hook, _ := parsePullRequest(buf) @@ -114,6 +141,7 @@ func Test_parse(t *testing.T) { g.Assert(build.Ref).Equal("refs/pull/1/head") g.Assert(build.Link).Equal(hook.PullRequest.URL) g.Assert(build.Branch).Equal("master") + g.Assert(build.Refspec).Equal("feature/changes:master") g.Assert(build.Message).Equal(hook.PullRequest.Title) g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(build.Author).Equal(hook.PullRequest.User.Username) @@ -132,9 +160,21 @@ func Test_parse(t *testing.T) { g.It("Should return a Perm struct from a Gitea Perm", func() { perms := []gitea.Permission{ - {true, true, true}, - {true, true, false}, - {true, false, false}, + { + Admin: true, + Push: true, + Pull: true, + }, + { + Admin: true, + Push: true, + Pull: false, + }, + { + Admin: true, + Push: false, + Pull: false, + }, } for _, from := range perms { perm := toPerm(&from) diff --git a/remote/gitea/parse.go b/remote/gitea/parse.go index 650fae2376..64a330c9a8 100644 --- a/remote/gitea/parse.go +++ b/remote/gitea/parse.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitea import ( @@ -14,7 +28,7 @@ const ( hookPullRequest = "pull_request" actionOpen = "opened" - actionSync = "synchronize" + actionSync = "synchronized" stateOpen = "open" diff --git a/remote/gitea/parse_test.go b/remote/gitea/parse_test.go index 3ac0cb79a6..d38c3f6f59 100644 --- a/remote/gitea/parse_test.go +++ b/remote/gitea/parse_test.go @@ -1 +1,15 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitea diff --git a/remote/gitea/types.go b/remote/gitea/types.go index f648f8de12..4f0de583aa 100644 --- a/remote/gitea/types.go +++ b/remote/gitea/types.go @@ -1,6 +1,21 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitea type pushHook struct { + Sha string `json:"sha"` Ref string `json:"ref"` Before string `json:"before"` After string `json:"after"` @@ -37,6 +52,7 @@ type pushHook struct { ID int64 `json:"id"` Login string `json:"login"` Username string `json:"username"` + Email string `json:"email"` Avatar string `json:"avatar_url"` } `json:"sender"` } @@ -53,16 +69,14 @@ type pullRequestHook struct { Email string `json:"email"` Avatar string `json:"avatar_url"` } `json:"user"` - Title string `json:"title"` - Body string `json:"body"` - Labels []string `json:"labels"` - State string `json:"state"` - URL string `json:"html_url"` - Mergeable bool `json:"mergeable"` - Merged bool `json:"merged"` - MergeBase string `json:"merge_base"` - BaseBranch string `json:"base_branch"` - Base struct { + Title string `json:"title"` + Body string `json:"body"` + State string `json:"state"` + URL string `json:"html_url"` + Mergeable bool `json:"mergeable"` + Merged bool `json:"merged"` + MergeBase string `json:"merge_base"` + Base struct { Label string `json:"label"` Ref string `json:"ref"` Sha string `json:"sha"` @@ -81,8 +95,7 @@ type pullRequestHook struct { } `json:"owner"` } `json:"repo"` } `json:"base"` - HeadBranch string `json:"head_branch"` - Head struct { + Head struct { Label string `json:"label"` Ref string `json:"ref"` Sha string `json:"sha"` diff --git a/remote/github/convert.go b/remote/github/convert.go index c535f5e006..dedeb37858 100644 --- a/remote/github/convert.go +++ b/remote/github/convert.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 github import ( diff --git a/remote/github/convert_test.go b/remote/github/convert_test.go index b6ce845e0b..f0076c28ae 100644 --- a/remote/github/convert_test.go +++ b/remote/github/convert_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 github import ( diff --git a/remote/github/fixtures/handler.go b/remote/github/fixtures/handler.go index ce4aa3d408..d3e0c314d8 100644 --- a/remote/github/fixtures/handler.go +++ b/remote/github/fixtures/handler.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures import ( diff --git a/remote/github/fixtures/hooks.go b/remote/github/fixtures/hooks.go index da9baac6da..8bb36e6ee8 100644 --- a/remote/github/fixtures/hooks.go +++ b/remote/github/fixtures/hooks.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures // HookPush is a sample push hook. diff --git a/remote/github/github.go b/remote/github/github.go index 097c8e758d..aed0bfd8a4 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 github import ( diff --git a/remote/github/github_test.go b/remote/github/github_test.go index bada35cdac..1b41f1366d 100644 --- a/remote/github/github_test.go +++ b/remote/github/github_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 github import ( diff --git a/remote/github/parse.go b/remote/github/parse.go index 36b6fcf208..dac4b3489d 100644 --- a/remote/github/parse.go +++ b/remote/github/parse.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 github import ( diff --git a/remote/github/parse_test.go b/remote/github/parse_test.go index 8152e16cfd..2619782b53 100644 --- a/remote/github/parse_test.go +++ b/remote/github/parse_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 github import ( diff --git a/remote/github/types.go b/remote/github/types.go index b8ed282e8d..c7882ada13 100644 --- a/remote/github/types.go +++ b/remote/github/types.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 github type webhook struct { diff --git a/remote/gitlab/client/drone.go b/remote/gitlab/client/drone.go index 8915e84555..4d6ca1e550 100644 --- a/remote/gitlab/client/drone.go +++ b/remote/gitlab/client/drone.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client const ( diff --git a/remote/gitlab/client/gitlab.go b/remote/gitlab/client/gitlab.go index 1b4bad7498..d5f47b2e03 100644 --- a/remote/gitlab/client/gitlab.go +++ b/remote/gitlab/client/gitlab.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab/client/groups.go b/remote/gitlab/client/groups.go index 0e8f30d286..651419937b 100644 --- a/remote/gitlab/client/groups.go +++ b/remote/gitlab/client/groups.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab/client/hook.go b/remote/gitlab/client/hook.go index 8ea89689e7..5ffeeb9e7b 100644 --- a/remote/gitlab/client/hook.go +++ b/remote/gitlab/client/hook.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab/client/project.go b/remote/gitlab/client/project.go index 47565dd516..3ee761ef60 100644 --- a/remote/gitlab/client/project.go +++ b/remote/gitlab/client/project.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( @@ -44,8 +58,8 @@ func (g *Client) AllProjects(hide_archives bool) ([]*Project, error) { // Get a list of projects owned by the authenticated user. func (c *Client) Projects(page int, per_page int, hide_archives bool) ([]*Project, error) { projectsOptions := QMap{ - "page": strconv.Itoa(page), - "per_page": strconv.Itoa(per_page), + "page": strconv.Itoa(page), + "per_page": strconv.Itoa(per_page), "membership": "true", } @@ -131,7 +145,7 @@ func (c *Client) SetStatus(id, sha, state, desc, ref, link string) error { func (c *Client) SearchProjectId(namespace string, name string) (id int, err error) { url, opaque := c.ResourceUrl(projectsUrl, nil, QMap{ - "query": strings.ToLower(name), + "query": strings.ToLower(name), "membership": "true", }) diff --git a/remote/gitlab/client/types.go b/remote/gitlab/client/types.go index b950a6d773..eb158869d9 100644 --- a/remote/gitlab/client/types.go +++ b/remote/gitlab/client/types.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client type QMap map[string]string diff --git a/remote/gitlab/client/user.go b/remote/gitlab/client/user.go index bafc7c47d4..d14cef2b3a 100644 --- a/remote/gitlab/client/user.go +++ b/remote/gitlab/client/user.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab/client/util.go b/remote/gitlab/client/util.go index c7418525b9..c446d230e2 100644 --- a/remote/gitlab/client/util.go +++ b/remote/gitlab/client/util.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab/gitlab.go b/remote/gitlab/gitlab.go index a920ca4323..455b2b87de 100644 --- a/remote/gitlab/gitlab.go +++ b/remote/gitlab/gitlab.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitlab import ( diff --git a/remote/gitlab/gitlab_test.go b/remote/gitlab/gitlab_test.go index 6e4f7003f7..4e168a9617 100644 --- a/remote/gitlab/gitlab_test.go +++ b/remote/gitlab/gitlab_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitlab import ( diff --git a/remote/gitlab/helper.go b/remote/gitlab/helper.go index 03c5092a53..e2a740c73d 100644 --- a/remote/gitlab/helper.go +++ b/remote/gitlab/helper.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitlab import ( diff --git a/remote/gitlab/testdata/hooks.go b/remote/gitlab/testdata/hooks.go index d7e01450b3..ff5ad57bfe 100644 --- a/remote/gitlab/testdata/hooks.go +++ b/remote/gitlab/testdata/hooks.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata var TagHook = []byte(` diff --git a/remote/gitlab/testdata/oauth.go b/remote/gitlab/testdata/oauth.go index 95119d70ae..6b975e577d 100644 --- a/remote/gitlab/testdata/oauth.go +++ b/remote/gitlab/testdata/oauth.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata var accessTokenPayload = []byte(`access_token=sekret&scope=api&token_type=bearer`) diff --git a/remote/gitlab/testdata/projects.go b/remote/gitlab/testdata/projects.go index 1dd069e3f6..eb3cfc3977 100644 --- a/remote/gitlab/testdata/projects.go +++ b/remote/gitlab/testdata/projects.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata // sample repository list diff --git a/remote/gitlab/testdata/testdata.go b/remote/gitlab/testdata/testdata.go index 032d4d5882..63db0c4f22 100644 --- a/remote/gitlab/testdata/testdata.go +++ b/remote/gitlab/testdata/testdata.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata import ( diff --git a/remote/gitlab/testdata/users.go b/remote/gitlab/testdata/users.go index e7d5636971..247adc9aa1 100644 --- a/remote/gitlab/testdata/users.go +++ b/remote/gitlab/testdata/users.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata var currentUserPayload = []byte(` diff --git a/remote/gitlab3/client/drone.go b/remote/gitlab3/client/drone.go index 8915e84555..4d6ca1e550 100644 --- a/remote/gitlab3/client/drone.go +++ b/remote/gitlab3/client/drone.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client const ( diff --git a/remote/gitlab3/client/gitlab.go b/remote/gitlab3/client/gitlab.go index 1b4bad7498..d5f47b2e03 100644 --- a/remote/gitlab3/client/gitlab.go +++ b/remote/gitlab3/client/gitlab.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab3/client/groups.go b/remote/gitlab3/client/groups.go index 0e8f30d286..651419937b 100644 --- a/remote/gitlab3/client/groups.go +++ b/remote/gitlab3/client/groups.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab3/client/hook.go b/remote/gitlab3/client/hook.go index 8ea89689e7..5ffeeb9e7b 100644 --- a/remote/gitlab3/client/hook.go +++ b/remote/gitlab3/client/hook.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab3/client/project.go b/remote/gitlab3/client/project.go index f21f1a48a4..32f559f16f 100644 --- a/remote/gitlab3/client/project.go +++ b/remote/gitlab3/client/project.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab3/client/types.go b/remote/gitlab3/client/types.go index 0c6424e03e..bf6ff1356f 100644 --- a/remote/gitlab3/client/types.go +++ b/remote/gitlab3/client/types.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client type QMap map[string]string diff --git a/remote/gitlab3/client/user.go b/remote/gitlab3/client/user.go index bafc7c47d4..d14cef2b3a 100644 --- a/remote/gitlab3/client/user.go +++ b/remote/gitlab3/client/user.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab3/client/util.go b/remote/gitlab3/client/util.go index c7418525b9..c446d230e2 100644 --- a/remote/gitlab3/client/util.go +++ b/remote/gitlab3/client/util.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 client import ( diff --git a/remote/gitlab3/gitlab.go b/remote/gitlab3/gitlab.go index 5bc62958e5..1515d7d4c1 100644 --- a/remote/gitlab3/gitlab.go +++ b/remote/gitlab3/gitlab.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitlab3 import ( diff --git a/remote/gitlab3/gitlab_test.go b/remote/gitlab3/gitlab_test.go index 7d69493c0b..bc98ae73bb 100644 --- a/remote/gitlab3/gitlab_test.go +++ b/remote/gitlab3/gitlab_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitlab3 import ( diff --git a/remote/gitlab3/helper.go b/remote/gitlab3/helper.go index 93f66ef18c..ad6d7f3c41 100644 --- a/remote/gitlab3/helper.go +++ b/remote/gitlab3/helper.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gitlab3 import ( diff --git a/remote/gitlab3/testdata/hooks.go b/remote/gitlab3/testdata/hooks.go index d7e01450b3..ff5ad57bfe 100644 --- a/remote/gitlab3/testdata/hooks.go +++ b/remote/gitlab3/testdata/hooks.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata var TagHook = []byte(` diff --git a/remote/gitlab3/testdata/oauth.go b/remote/gitlab3/testdata/oauth.go index 95119d70ae..6b975e577d 100644 --- a/remote/gitlab3/testdata/oauth.go +++ b/remote/gitlab3/testdata/oauth.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata var accessTokenPayload = []byte(`access_token=sekret&scope=api&token_type=bearer`) diff --git a/remote/gitlab3/testdata/projects.go b/remote/gitlab3/testdata/projects.go index 1dd069e3f6..eb3cfc3977 100644 --- a/remote/gitlab3/testdata/projects.go +++ b/remote/gitlab3/testdata/projects.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata // sample repository list diff --git a/remote/gitlab3/testdata/testdata.go b/remote/gitlab3/testdata/testdata.go index 2fa2322b65..d9ea8995a1 100644 --- a/remote/gitlab3/testdata/testdata.go +++ b/remote/gitlab3/testdata/testdata.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata import ( diff --git a/remote/gitlab3/testdata/users.go b/remote/gitlab3/testdata/users.go index e7d5636971..247adc9aa1 100644 --- a/remote/gitlab3/testdata/users.go +++ b/remote/gitlab3/testdata/users.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 testdata var currentUserPayload = []byte(` diff --git a/remote/gogs/fixtures/handler.go b/remote/gogs/fixtures/handler.go index 5904a1dd33..4726c9c640 100644 --- a/remote/gogs/fixtures/handler.go +++ b/remote/gogs/fixtures/handler.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures import ( diff --git a/remote/gogs/fixtures/hooks.go b/remote/gogs/fixtures/hooks.go index e9c19dba52..cf2a542122 100644 --- a/remote/gogs/fixtures/hooks.go +++ b/remote/gogs/fixtures/hooks.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 fixtures // Sample Gogs push hook @@ -44,6 +58,7 @@ var HookPush = ` "sender": { "login": "gordon", "id": 1, + "email": "gordon@golang.org", "avatar_url": "http://gogs.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87" } } diff --git a/remote/gogs/gogs.go b/remote/gogs/gogs.go index 97dcf45a6d..cc57e2a447 100644 --- a/remote/gogs/gogs.go +++ b/remote/gogs/gogs.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gogs import ( @@ -52,7 +66,7 @@ func New(opts Opts) (remote.Remote, error) { }, nil } -// Login authenticates an account with Gogs using basic authenticaiton. The +// Login authenticates an account with Gogs using basic authentication. The // Gogs account details are returned when the user is successfully authenticated. func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User, error) { var ( diff --git a/remote/gogs/gogs_test.go b/remote/gogs/gogs_test.go index bfd8728c94..468cae520c 100644 --- a/remote/gogs/gogs_test.go +++ b/remote/gogs/gogs_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gogs import ( diff --git a/remote/gogs/helper.go b/remote/gogs/helper.go index 8b9420ed72..0d2db2f816 100644 --- a/remote/gogs/helper.go +++ b/remote/gogs/helper.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gogs import ( @@ -77,7 +91,7 @@ func buildFromPush(hook *pushHook) *model.Build { Message: hook.Commits[0].Message, Avatar: avatar, Author: author, - Email: hook.Pusher.Email, + Email: hook.Sender.Email, Timestamp: time.Now().UTC().Unix(), Sender: sender, } diff --git a/remote/gogs/helper_test.go b/remote/gogs/helper_test.go index 41ec32eba3..758bd1226c 100644 --- a/remote/gogs/helper_test.go +++ b/remote/gogs/helper_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gogs import ( diff --git a/remote/gogs/parse.go b/remote/gogs/parse.go index 6b3c1b60d6..f0e1f47e00 100644 --- a/remote/gogs/parse.go +++ b/remote/gogs/parse.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gogs import ( @@ -14,7 +28,7 @@ const ( hookPullRequest = "pull_request" actionOpen = "opened" - actionSync = "synchronize" + actionSync = "synchronized" stateOpen = "open" diff --git a/remote/gogs/parse_test.go b/remote/gogs/parse_test.go index be8cf935b0..29ad74267a 100644 --- a/remote/gogs/parse_test.go +++ b/remote/gogs/parse_test.go @@ -1 +1,15 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gogs diff --git a/remote/gogs/types.go b/remote/gogs/types.go index 611004455e..9b62c3e28e 100644 --- a/remote/gogs/types.go +++ b/remote/gogs/types.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 gogs type pushHook struct { @@ -37,6 +51,7 @@ type pushHook struct { ID int64 `json:"id"` Login string `json:"login"` Username string `json:"username"` + Email string `json:"email"` Avatar string `json:"avatar_url"` } `json:"sender"` } @@ -55,7 +70,6 @@ type pullRequestHook struct { } `json:"user"` Title string `json:"title"` Body string `json:"body"` - Labels []string `json:"labels"` State string `json:"state"` URL string `json:"html_url"` Mergeable bool `json:"mergeable"` diff --git a/remote/mock/remote.go b/remote/mock/remote.go index f97a677fdd..2b8cf32f0a 100644 --- a/remote/mock/remote.go +++ b/remote/mock/remote.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 mock import ( diff --git a/remote/remote.go b/remote/remote.go index bdd441fcc9..880e840628 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 remote //go:generate mockery -name Remote -output mock -case=underscore @@ -103,12 +117,12 @@ func Perm(c context.Context, u *model.User, owner, repo string) (*model.Perm, er // File fetches a file from the remote repository and returns in string format. func File(c context.Context, u *model.User, r *model.Repo, b *model.Build, f string) (out []byte, err error) { - for i := 0; i < 5; i++ { + for i := 0; i < 12; i++ { out, err = FromContext(c).File(u, r, b, f) if err == nil { return } - time.Sleep(1 * time.Second) + time.Sleep(5 * time.Second) } return } @@ -154,3 +168,18 @@ func Refresh(c context.Context, u *model.User) (bool, error) { } return refresher.Refresh(u) } + +// FileBackoff fetches the file using an exponential backoff. +// TODO replace this with a proper backoff +func FileBackoff(remote Remote, u *model.User, r *model.Repo, b *model.Build, f string) (out []byte, err error) { + for i := 0; i < 5; i++ { + select { + case <-time.After(time.Second * time.Duration(i)): + out, err = remote.File(u, r, b, f) + if err == nil { + return + } + } + } + return +} diff --git a/router/middleware/config.go b/router/middleware/config.go index c90c9ac850..87c857246a 100644 --- a/router/middleware/config.go +++ b/router/middleware/config.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 middleware import ( diff --git a/router/middleware/header/header.go b/router/middleware/header/header.go index 7b82154abd..c3a6ba0bc1 100644 --- a/router/middleware/header/header.go +++ b/router/middleware/header/header.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 header import ( diff --git a/router/middleware/remote.go b/router/middleware/remote.go index cfc7482388..401303302e 100644 --- a/router/middleware/remote.go +++ b/router/middleware/remote.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 middleware import ( diff --git a/router/middleware/session/agent.go b/router/middleware/session/agent.go index d1a31c66ce..7c49fa7260 100644 --- a/router/middleware/session/agent.go +++ b/router/middleware/session/agent.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 session import ( diff --git a/router/middleware/session/repo.go b/router/middleware/session/repo.go index 2822d0095e..526735bafe 100644 --- a/router/middleware/session/repo.go +++ b/router/middleware/session/repo.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 session import ( diff --git a/router/middleware/session/repo_test.go b/router/middleware/session/repo_test.go index 349b4e3ac7..6e2899a346 100644 --- a/router/middleware/session/repo_test.go +++ b/router/middleware/session/repo_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 session import ( diff --git a/router/middleware/session/user.go b/router/middleware/session/user.go index f965014a68..81da03d8ea 100644 --- a/router/middleware/session/user.go +++ b/router/middleware/session/user.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 session import ( diff --git a/router/middleware/store.go b/router/middleware/store.go index 09e52d3878..f3bd305286 100644 --- a/router/middleware/store.go +++ b/router/middleware/store.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 middleware import ( diff --git a/router/middleware/token/token.go b/router/middleware/token/token.go index 52440194a0..8ba2926960 100644 --- a/router/middleware/token/token.go +++ b/router/middleware/token/token.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 ( diff --git a/router/middleware/version.go b/router/middleware/version.go index 87170010a3..fc2a7f552e 100644 --- a/router/middleware/version.go +++ b/router/middleware/version.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 middleware import ( diff --git a/router/router.go b/router/router.go index 64dd996840..6d5fbcd181 100644 --- a/router/router.go +++ b/router/router.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 router import ( @@ -99,10 +113,11 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl repo.POST("/move", session.MustRepoAdmin(), server.MoveRepo) repo.POST("/builds/:number", session.MustPush, server.PostBuild) - repo.DELETE("/builds/:number", session.MustAdmin(), server.ZombieKill) + repo.DELETE("/builds/:number", session.MustRepoAdmin(), server.ZombieKill) repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval) repo.POST("/builds/:number/decline", session.MustPush, server.PostDecline) repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild) + repo.DELETE("/logs/:number", session.MustPush, server.DeleteBuildLogs) } badges := e.Group("/api/badges/:owner/:name") @@ -163,10 +178,7 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl monitor := e.Group("/metrics") { - monitor.GET("", - session.MustAdmin(), - metrics.PromHandler(), - ) + monitor.GET("", metrics.PromHandler()) } e.GET("/version", server.Version) @@ -174,10 +186,3 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl return e } - -// type FileHandler interface { -// Index(res http.ResponseWriter, data interface{}) error -// Login(res http.ResponseWriter, data interface{}) error -// Error(res http.ResponseWriter, data interface{}) error -// Asset(res http.ResponseWriter, req *http.Request) -// } diff --git a/server/badge.go b/server/badge.go index ed3947de87..b8c5162f87 100644 --- a/server/badge.go +++ b/server/badge.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( @@ -72,7 +86,7 @@ func GetCC(c *gin.Context) { return } - builds, err := store.GetBuildList(c, repo) + builds, err := store.GetBuildList(c, repo, 1) if err != nil || len(builds) == 0 { c.AbortWithStatus(404) return diff --git a/server/build.go b/server/build.go index 245467edc7..f1d6e89746 100644 --- a/server/build.go +++ b/server/build.go @@ -1,6 +1,21 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( + "bytes" "context" "encoding/json" "fmt" @@ -24,7 +39,13 @@ import ( func GetBuilds(c *gin.Context) { repo := session.Repo(c) - builds, err := store.GetBuildList(c, repo) + page, err := strconv.Atoi(c.DefaultQuery("page", "1")) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + return + } + + builds, err := store.GetBuildList(c, repo, page) if err != nil { c.AbortWithStatus(http.StatusInternalServerError) return @@ -301,7 +322,7 @@ func PostApproval(c *gin.Context) { uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number) err = remote_.Status(user, repo, build, uri) if err != nil { - logrus.Errorf("error setting commit status for %s/%d", repo.FullName, build.Number) + logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err) } }() @@ -427,7 +448,7 @@ func PostDecline(c *gin.Context) { uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number) err = remote_.Status(user, repo, build, uri) if err != nil { - logrus.Errorf("error setting commit status for %s/%d", repo.FullName, build.Number) + logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err) } c.JSON(200, build) @@ -475,11 +496,8 @@ func PostBuild(c *gin.Context) { } switch build.Status { - case model.StatusPending, - model.StatusRunning, - model.StatusDeclined, - model.StatusBlocked, - model.StatusError: + case model.StatusDeclined, + model.StatusBlocked: c.String(500, "cannot restart a build with status %s", build.Status) return } @@ -663,3 +681,54 @@ func PostBuild(c *gin.Context) { Config.Services.Queue.Push(context.Background(), task) } } + +// +/// +// + +func DeleteBuildLogs(c *gin.Context) { + repo := session.Repo(c) + user := session.User(c) + num, _ := strconv.Atoi(c.Params.ByName("number")) + + build, err := store.GetBuildNumber(c, repo, num) + if err != nil { + c.AbortWithError(404, err) + return + } + + procs, err := store.FromContext(c).ProcList(build) + if err != nil { + c.AbortWithError(404, err) + return + } + + switch build.Status { + case model.StatusRunning, model.StatusPending: + c.String(400, "Cannot delete logs for a pending or running build") + return + } + + for _, proc := range procs { + t := time.Now().UTC() + buf := bytes.NewBufferString(fmt.Sprintf(deleteStr, proc.Name, user.Login, t.Format(time.UnixDate))) + lerr := store.FromContext(c).LogSave(proc, buf) + if lerr != nil { + err = lerr + } + } + if err != nil { + c.String(400, "There was a problem deleting your logs. %s", err) + return + } + + c.String(204, "") +} + +var deleteStr = `[ + { + "proc": %q, + "pos": 0, + "out": "logs purged by %s on %s\n" + } +]` diff --git a/server/debug/debug.go b/server/debug/debug.go index d4e2346d44..09c8e41a94 100644 --- a/server/debug/debug.go +++ b/server/debug/debug.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 debug import ( diff --git a/server/file.go b/server/file.go index f360c82d4b..1027391ce3 100644 --- a/server/file.go +++ b/server/file.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/server/hook.go b/server/hook.go index ba81fc4c99..92712014ca 100644 --- a/server/hook.go +++ b/server/hook.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( @@ -6,6 +20,7 @@ import ( "encoding/json" "fmt" "math/rand" + "net/url" "regexp" "strconv" "strings" @@ -30,6 +45,9 @@ import ( "github.com/cncd/pipeline/pipeline/rpc" "github.com/cncd/pubsub" "github.com/cncd/queue" + "net/http" + "os" + "io/ioutil" ) // @@ -52,6 +70,7 @@ func GetQueueInfo(c *gin.Context) { } func PostHook(c *gin.Context) { + remote_ := remote.FromContext(c) tmprepo, build, err := remote_.Hook(c.Request) @@ -142,13 +161,39 @@ func PostHook(c *gin.Context) { } } + var confb []byte // fetch the build file from the database - confb, err := remote_.File(user, repo, build, repo.Config) + repo_confb, err := remote.FileBackoff(remote_, user, repo, build, repo.Config) + if err != nil { - logrus.Errorf("error: %s: cannot find %s in %s: %s", repo.FullName, repo.Config, build.Ref, err) - c.AbortWithError(404, err) - return + // if failed, check if we have a fallback in the server config + if len(os.Getenv("DRONE_SERVER_YAML_FALLBACK")) > 0 { + // download it + resp, err := http.Get(fmt.Sprintf("%s?event=%s&repo=%s&branch=%s&refspec=%s", + os.Getenv("DRONE_SERVER_YAML_FALLBACK"), build.Event, repo.FullName, build.Branch, build.Refspec)) + if err != nil { + logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err) + c.AbortWithError(404, err) + return + } + defer resp.Body.Close() + fallback_confb, err := ioutil.ReadAll(resp.Body) + + if err != nil { + logrus.Errorf("failure to get fallback build config %s for %s. %s", + os.Getenv("DRONE_SERVER_YAML_FALLBACK") , repo.FullName, err) + c.AbortWithError(404, err) + return + } + // Use fallback as config + confb = fallback_confb + } + } else { + // Use repo config + confb = repo_confb } + + // fetch the build file from the database sha := shasum(confb) conf, err := Config.Storage.Config.ConfigFind(repo, sha) if err != nil { @@ -246,7 +291,7 @@ func PostHook(c *gin.Context) { uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number) err = remote_.Status(user, repo, build, uri) if err != nil { - logrus.Errorf("error setting commit status for %s/%d", repo.FullName, build.Number) + logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err) } }() @@ -346,12 +391,18 @@ func PostHook(c *gin.Context) { // return the metadata from the cli context. func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model.Proc, link string) frontend.Metadata { + host := link + uri, err := url.Parse(link) + if err == nil { + host = uri.Host + } return frontend.Metadata{ Repo: frontend.Repo{ Name: repo.FullName, Link: repo.Link, Remote: repo.Clone, Private: repo.IsPrivate, + Branch: repo.Branch, }, Curr: frontend.Build{ Number: build.Number, @@ -405,6 +456,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model. Sys: frontend.System{ Name: "drone", Link: link, + Host: host, Arch: "linux/amd64", }, } diff --git a/server/hook_test.go b/server/hook_test.go index 51af94e661..5aedd8c8c0 100644 --- a/server/hook_test.go +++ b/server/hook_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( @@ -13,11 +27,11 @@ func TestMultilineEnvsubst(t *testing.T) { Message: `aaa bbb`, }, - Last: &model.Build{}, + Last: &model.Build{}, Netrc: &model.Netrc{}, - Secs: []*model.Secret{}, - Regs: []*model.Registry{}, - Link: "", + Secs: []*model.Secret{}, + Regs: []*model.Registry{}, + Link: "", Yaml: `pipeline: xxx: image: scratch diff --git a/server/login.go b/server/login.go index 0a41ff3955..558f153245 100644 --- a/server/login.go +++ b/server/login.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/server/metrics/prometheus.go b/server/metrics/prometheus.go index 1eea896165..b91b5e2a7b 100644 --- a/server/metrics/prometheus.go +++ b/server/metrics/prometheus.go @@ -1,14 +1,59 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 metrics import ( - "github.com/gin-gonic/gin" + "errors" + "fmt" + "github.com/drone/drone/server" + "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus/promhttp" ) +var ( + // errInvalidToken is returned when the api request token is invalid. + errInvalidToken = errors.New("Invalid or missing token") +) + // PromHandler will pass the call from /api/metrics/prometheus to prometheus func PromHandler() gin.HandlerFunc { + handler := promhttp.Handler() + return func(c *gin.Context) { - promhttp.Handler().ServeHTTP(c.Writer, c.Request) + token := server.Config.Prometheus.AuthToken + + if token == "" { + handler.ServeHTTP(c.Writer, c.Request) + return + } + + header := c.Request.Header.Get("Authorization") + + if header == "" { + c.String(401, errInvalidToken.Error()) + return + } + + bearer := fmt.Sprintf("Bearer %s", token) + + if header != bearer { + c.String(401, errInvalidToken.Error()) + return + } + + handler.ServeHTTP(c.Writer, c.Request) } } diff --git a/server/registry.go b/server/registry.go index d1a46b6afa..879edae6d3 100644 --- a/server/registry.go +++ b/server/registry.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/server/repo.go b/server/repo.go index 972a18e929..bb57f70bc5 100644 --- a/server/repo.go +++ b/server/repo.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( @@ -100,7 +114,7 @@ func PatchRepo(c *gin.Context) { return } - if (in.IsTrusted != nil || in.Timeout != nil || in.BuildCounter != nil) && !user.Admin { + if (in.IsTrusted != nil || in.Timeout != nil) && !user.Admin { c.String(403, "Insufficient privileges") return } diff --git a/server/rpc.go b/server/rpc.go index ba747e95bb..0bdec222b9 100644 --- a/server/rpc.go +++ b/server/rpc.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( @@ -66,6 +80,9 @@ var Config = struct { // Orgs map[string]struct{} // Admins map[string]struct{} } + Prometheus struct { + AuthToken string + } Pipeline struct { Limits model.ResourceLimit Volumes []string @@ -428,7 +445,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error { uri := fmt.Sprintf("%s/%s/%d", s.host, repo.FullName, build.Number) err = s.remote.Status(user, repo, build, uri) if err != nil { - logrus.Errorf("error setting commit status for %s/%d", repo.FullName, build.Number) + logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err) } } } @@ -527,6 +544,7 @@ func (s *DroneServer) Next(c oldcontext.Context, req *proto.NextRequest) (*proto } filter := rpc.Filter{ Labels: req.GetFilter().GetLabels(), + Expr: req.GetFilter().GetExpr(), } res := new(proto.NextReply) diff --git a/server/secret.go b/server/secret.go index 34bed546b9..deb04c786d 100644 --- a/server/secret.go +++ b/server/secret.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/server/stream.go b/server/stream.go index d8625e90af..6dd19a9bad 100644 --- a/server/stream.go +++ b/server/stream.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( @@ -64,7 +78,7 @@ func EventStreamSSE(c *gin.Context) { go func() { // TODO remove this from global config - Config.Services.Pubsub.Subscribe(c, "topic/events", func(m pubsub.Message) { + Config.Services.Pubsub.Subscribe(ctx, "topic/events", func(m pubsub.Message) { name := m.Labels["repo"] priv := m.Labels["private"] if repo[name] || priv == "false" { diff --git a/server/swagger/doc.go b/server/swagger/doc.go index 2642c47d47..56d093fd2d 100644 --- a/server/swagger/doc.go +++ b/server/swagger/doc.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 classification Drone API. // // Schemes: http, https diff --git a/server/swagger/swagger.go b/server/swagger/swagger.go index 2e7a006f1d..e23ba78b2c 100644 --- a/server/swagger/swagger.go +++ b/server/swagger/swagger.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 swagger import ( diff --git a/server/sync.go b/server/sync.go index 9d42835f66..6e9091ac32 100644 --- a/server/sync.go +++ b/server/sync.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/server/user.go b/server/user.go index 00402ae712..41f4d59138 100644 --- a/server/user.go +++ b/server/user.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/server/users.go b/server/users.go index 410e8b8d21..49d78683c8 100644 --- a/server/users.go +++ b/server/users.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/server/web/opts.go b/server/web/opts.go index d3e70b0528..32ba6d5939 100644 --- a/server/web/opts.go +++ b/server/web/opts.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 web import "time" @@ -12,7 +26,7 @@ type Options struct { // Option configures the website handler. type Option func(*Options) -// WithSync configures the website hanlder with the duration value +// WithSync configures the website handler with the duration value // used to determine if the user account requires synchronization. func WithSync(d time.Duration) Option { return func(o *Options) { @@ -20,7 +34,7 @@ func WithSync(d time.Duration) Option { } } -// WithDir configures the website hanlder with the directory value +// WithDir configures the website handler with the directory value // used to serve the website from the local filesystem. func WithDir(s string) Option { return func(o *Options) { @@ -28,7 +42,7 @@ func WithDir(s string) Option { } } -// WithDocs configures the website hanlder with the documentation +// WithDocs configures the website handler with the documentation // website address, which should be included in the user interface. func WithDocs(s string) Option { return func(o *Options) { diff --git a/server/web/opts_test.go b/server/web/opts_test.go index 188ec09da3..a217f2f024 100644 --- a/server/web/opts_test.go +++ b/server/web/opts_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 web import ( diff --git a/server/web/template.go b/server/web/template.go index dd93a74a04..509f20c367 100644 --- a/server/web/template.go +++ b/server/web/template.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 web import ( diff --git a/server/web/template_test.go b/server/web/template_test.go index 3a0895ff08..6ad8a28509 100644 --- a/server/web/template_test.go +++ b/server/web/template_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 web import ( diff --git a/server/web/web.go b/server/web/web.go index 58cb5dcee9..2a46358088 100644 --- a/server/web/web.go +++ b/server/web/web.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 web import ( diff --git a/server/z.go b/server/z.go index 69df93ada0..fcc036f5a9 100644 --- a/server/z.go +++ b/server/z.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 server import ( diff --git a/shared/httputil/httputil.go b/shared/httputil/httputil.go index 86cc7b5a11..011e233053 100644 --- a/shared/httputil/httputil.go +++ b/shared/httputil/httputil.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 httputil import ( diff --git a/shared/token/token.go b/shared/token/token.go index d4f83a2b84..0753a18464 100644 --- a/shared/token/token.go +++ b/shared/token/token.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 ( diff --git a/store/context.go b/store/context.go index 10112dde53..135c9c8404 100644 --- a/store/context.go +++ b/store/context.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 store import ( diff --git a/store/datastore/builds.go b/store/datastore/builds.go index 6793fa027b..9033e7ee10 100644 --- a/store/datastore/builds.go +++ b/store/datastore/builds.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( @@ -45,9 +59,9 @@ func (db *datastore) GetBuildLastBefore(repo *model.Repo, branch string, num int return build, err } -func (db *datastore) GetBuildList(repo *model.Repo) ([]*model.Build, error) { +func (db *datastore) GetBuildList(repo *model.Repo, page int) ([]*model.Build, error) { var builds = []*model.Build{} - var err = meddler.QueryAll(db, &builds, rebind(buildListQuery), repo.ID) + var err = meddler.QueryAll(db, &builds, rebind(buildListQuery), repo.ID, 50*(page-1)) return builds, err } @@ -130,7 +144,7 @@ SELECT * FROM builds WHERE build_repo_id = ? ORDER BY build_number DESC -LIMIT 50 +LIMIT 50 OFFSET ? ` const buildNumberQuery = ` diff --git a/store/datastore/builds_test.go b/store/datastore/builds_test.go index 4aed2d3265..3411733c8a 100644 --- a/store/datastore/builds_test.go +++ b/store/datastore/builds_test.go @@ -1,6 +1,21 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( + "fmt" "testing" "github.com/drone/drone/model" @@ -46,6 +61,11 @@ func TestBuilds(t *testing.T) { g.Assert(build.ID != 0).IsTrue() g.Assert(build.Number).Equal(1) g.Assert(build.Commit).Equal("85f8c029b902ed9400bc600bac301a0aadb144ac") + + count, err := s.GetBuildCount() + g.Assert(err == nil).IsTrue() + g.Assert(count > 0).IsTrue() + fmt.Println("GOT COUNT", count) }) g.It("Should Put a Build", func() { @@ -247,7 +267,7 @@ func TestBuilds(t *testing.T) { } s.CreateBuild(build1, []*model.Proc{}...) s.CreateBuild(build2, []*model.Proc{}...) - builds, err := s.GetBuildList(&model.Repo{ID: 1}) + builds, err := s.GetBuildList(&model.Repo{ID: 1}, 1) g.Assert(err == nil).IsTrue() g.Assert(len(builds)).Equal(2) g.Assert(builds[0].ID).Equal(build2.ID) diff --git a/store/datastore/config.go b/store/datastore/config.go index ca6d6f24af..af976ebb5b 100644 --- a/store/datastore/config.go +++ b/store/datastore/config.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/config_test.go b/store/datastore/config_test.go index cdcceaab30..b98461c650 100644 --- a/store/datastore/config_test.go +++ b/store/datastore/config_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/ddl/migrate.go b/store/datastore/ddl/migrate.go index d59e201437..16283c6645 100644 --- a/store/datastore/ddl/migrate.go +++ b/store/datastore/ddl/migrate.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 ddl import ( diff --git a/store/datastore/ddl/mysql/ddl.go b/store/datastore/ddl/mysql/ddl.go index 42ab9ab9fe..ac3c094912 100644 --- a/store/datastore/ddl/mysql/ddl.go +++ b/store/datastore/ddl/mysql/ddl.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 mysql //go:generate togo ddl -package mysql -dialect mysql diff --git a/store/datastore/ddl/mysql/ddl_gen.go b/store/datastore/ddl/mysql/ddl_gen.go index 0bd0ca69a2..b12efe1263 100644 --- a/store/datastore/ddl/mysql/ddl_gen.go +++ b/store/datastore/ddl/mysql/ddl_gen.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 mysql import ( diff --git a/store/datastore/ddl/postgres/ddl.go b/store/datastore/ddl/postgres/ddl.go index cb1877039c..6d50b23362 100644 --- a/store/datastore/ddl/postgres/ddl.go +++ b/store/datastore/ddl/postgres/ddl.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 postgres //go:generate togo ddl -package postgres -dialect postgres diff --git a/store/datastore/ddl/postgres/ddl_gen.go b/store/datastore/ddl/postgres/ddl_gen.go index 2e999e220e..3915069faf 100644 --- a/store/datastore/ddl/postgres/ddl_gen.go +++ b/store/datastore/ddl/postgres/ddl_gen.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 postgres import ( diff --git a/store/datastore/ddl/postgres/files/013_add_column_repo_visibility.sql b/store/datastore/ddl/postgres/files/013_add_column_repo_visibility.sql index ed795dfc20..03b73f8887 100644 --- a/store/datastore/ddl/postgres/files/013_add_column_repo_visibility.sql +++ b/store/datastore/ddl/postgres/files/013_add_column_repo_visibility.sql @@ -1,6 +1,6 @@ -- name: alter-table-add-repo-visibility -ALTER TABLE repos ADD COLUMN repo_visibility VARCHAR(50) +ALTER TABLE repos ADD COLUMN repo_visibility VARCHAR(50); -- name: update-table-set-repo-visibility @@ -8,4 +8,4 @@ UPDATE repos SET repo_visibility = (CASE WHEN repo_private = false THEN 'public' ELSE 'private' - END) + END); diff --git a/store/datastore/ddl/postgres/files/014_add_column_repo_seq.sql b/store/datastore/ddl/postgres/files/014_add_column_repo_seq.sql index a0be87dda7..2c45f95b6a 100644 --- a/store/datastore/ddl/postgres/files/014_add_column_repo_seq.sql +++ b/store/datastore/ddl/postgres/files/014_add_column_repo_seq.sql @@ -8,9 +8,10 @@ UPDATE repos SET repo_counter = ( SELECT max(build_number) FROM builds WHERE builds.build_repo_id = repos.repo_id -) +); -- name: update-table-set-repo-seq-default UPDATE repos SET repo_counter = 0 WHERE repo_counter IS NULL +; \ No newline at end of file diff --git a/store/datastore/ddl/postgres/files/015_add_column_repo_active.sql b/store/datastore/ddl/postgres/files/015_add_column_repo_active.sql index 4dca2dd1e1..627ffda0c0 100644 --- a/store/datastore/ddl/postgres/files/015_add_column_repo_active.sql +++ b/store/datastore/ddl/postgres/files/015_add_column_repo_active.sql @@ -1,7 +1,7 @@ -- name: alter-table-add-repo-active -ALTER TABLE repos ADD COLUMN repo_active BOOLEAN +ALTER TABLE repos ADD COLUMN repo_active BOOLEAN; -- name: update-table-set-repo-active -UPDATE repos SET repo_active = true +UPDATE repos SET repo_active = true; diff --git a/store/datastore/ddl/postgres/files/016_add_column_user_synced.sql b/store/datastore/ddl/postgres/files/016_add_column_user_synced.sql index 43db914e7a..efe2d9bed9 100644 --- a/store/datastore/ddl/postgres/files/016_add_column_user_synced.sql +++ b/store/datastore/ddl/postgres/files/016_add_column_user_synced.sql @@ -4,4 +4,4 @@ ALTER TABLE users ADD COLUMN user_synced INTEGER; -- name: update-table-set-user-synced -UPDATE users SET user_synced = 0 +UPDATE users SET user_synced = 0; diff --git a/store/datastore/ddl/postgres/files/018_add_column_file_pid.sql b/store/datastore/ddl/postgres/files/018_add_column_file_pid.sql index 0ad11ac788..a8ee163c10 100644 --- a/store/datastore/ddl/postgres/files/018_add_column_file_pid.sql +++ b/store/datastore/ddl/postgres/files/018_add_column_file_pid.sql @@ -1,18 +1,18 @@ -- name: alter-table-add-file-pid -ALTER TABLE files ADD COLUMN file_pid INTEGER +ALTER TABLE files ADD COLUMN file_pid INTEGER; -- name: alter-table-add-file-meta-passed -ALTER TABLE files ADD COLUMN file_meta_passed INTEGER +ALTER TABLE files ADD COLUMN file_meta_passed INTEGER; -- name: alter-table-add-file-meta-failed -ALTER TABLE files ADD COLUMN file_meta_failed INTEGER +ALTER TABLE files ADD COLUMN file_meta_failed INTEGER; -- name: alter-table-add-file-meta-skipped -ALTER TABLE files ADD COLUMN file_meta_skipped INTEGER +ALTER TABLE files ADD COLUMN file_meta_skipped INTEGER; -- name: alter-table-update-file-meta @@ -20,3 +20,4 @@ UPDATE files SET file_meta_passed=0 ,file_meta_failed=0 ,file_meta_skipped=0 +; \ No newline at end of file diff --git a/store/datastore/ddl/sqlite/ddl.go b/store/datastore/ddl/sqlite/ddl.go index 5573bad290..7cddb02eb4 100644 --- a/store/datastore/ddl/sqlite/ddl.go +++ b/store/datastore/ddl/sqlite/ddl.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 sqlite //go:generate togo ddl -package sqlite -dialect sqlite3 diff --git a/store/datastore/ddl/sqlite/ddl_gen.go b/store/datastore/ddl/sqlite/ddl_gen.go index e4e46247bf..3318a93584 100644 --- a/store/datastore/ddl/sqlite/ddl_gen.go +++ b/store/datastore/ddl/sqlite/ddl_gen.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 sqlite import ( diff --git a/store/datastore/files.go b/store/datastore/files.go index a52965ea4b..7657625518 100644 --- a/store/datastore/files.go +++ b/store/datastore/files.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/files_test.go b/store/datastore/files_test.go index 051e78a1db..f51230c740 100644 --- a/store/datastore/files_test.go +++ b/store/datastore/files_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/init.go b/store/datastore/init.go index b006609028..12febc36ff 100644 --- a/store/datastore/init.go +++ b/store/datastore/init.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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. + // +build !cgo package datastore diff --git a/store/datastore/init_cgo.go b/store/datastore/init_cgo.go index 0aa3ef76d2..8a4e208399 100644 --- a/store/datastore/init_cgo.go +++ b/store/datastore/init_cgo.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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. + // +build cgo package datastore diff --git a/store/datastore/logs.go b/store/datastore/logs.go index 841ef7de37..6d1460c9ae 100644 --- a/store/datastore/logs.go +++ b/store/datastore/logs.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/logs_test.go b/store/datastore/logs_test.go index 6641787086..2d227b0d26 100644 --- a/store/datastore/logs_test.go +++ b/store/datastore/logs_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/perms.go b/store/datastore/perms.go index ffa4f77e12..4ad7e49b77 100644 --- a/store/datastore/perms.go +++ b/store/datastore/perms.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/perms_test.go b/store/datastore/perms_test.go index 113b550cbd..030bdd926e 100644 --- a/store/datastore/perms_test.go +++ b/store/datastore/perms_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/procs.go b/store/datastore/procs.go index 7dcce95ecb..d503e1de9a 100644 --- a/store/datastore/procs.go +++ b/store/datastore/procs.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/procs_test.go b/store/datastore/procs_test.go index 2f9849d361..c02dfd295f 100644 --- a/store/datastore/procs_test.go +++ b/store/datastore/procs_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/registry.go b/store/datastore/registry.go index 6e16d36568..fc1d9d19e0 100644 --- a/store/datastore/registry.go +++ b/store/datastore/registry.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/registry_test.go b/store/datastore/registry_test.go index 3df5b611b6..66223599e0 100644 --- a/store/datastore/registry_test.go +++ b/store/datastore/registry_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/repos.go b/store/datastore/repos.go index eda92d9010..e993c1742b 100644 --- a/store/datastore/repos.go +++ b/store/datastore/repos.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/repos_test.go b/store/datastore/repos_test.go index ddd1218a97..f180543bf7 100644 --- a/store/datastore/repos_test.go +++ b/store/datastore/repos_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/secret.go b/store/datastore/secret.go index 33e8c0c7ed..b967974e74 100644 --- a/store/datastore/secret.go +++ b/store/datastore/secret.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/secret_test.go b/store/datastore/secret_test.go index c5b02883fc..8b0b8cae8d 100644 --- a/store/datastore/secret_test.go +++ b/store/datastore/secret_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/sender.go b/store/datastore/sender.go index 7843108631..326cbd4d52 100644 --- a/store/datastore/sender.go +++ b/store/datastore/sender.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/sender_test.go b/store/datastore/sender_test.go index 346ce2c6f8..433797f65a 100644 --- a/store/datastore/sender_test.go +++ b/store/datastore/sender_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/sql/lookup.go b/store/datastore/sql/lookup.go index da3643f91e..e0e3d46aa2 100644 --- a/store/datastore/sql/lookup.go +++ b/store/datastore/sql/lookup.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 sql import ( diff --git a/store/datastore/sql/mysql/sql.go b/store/datastore/sql/mysql/sql.go index 3e7d8abf61..64fba52d48 100644 --- a/store/datastore/sql/mysql/sql.go +++ b/store/datastore/sql/mysql/sql.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 mysql //go:generate togo sql --package=mysql diff --git a/store/datastore/sql/mysql/sql_gen.go b/store/datastore/sql/mysql/sql_gen.go index 313a53eb48..a93ea22cb2 100644 --- a/store/datastore/sql/mysql/sql_gen.go +++ b/store/datastore/sql/mysql/sql_gen.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 mysql // Lookup returns the named statement. diff --git a/store/datastore/sql/postgres/files/counts.sql b/store/datastore/sql/postgres/files/counts.sql index 29948d9322..b9c34cf1ae 100644 --- a/store/datastore/sql/postgres/files/counts.sql +++ b/store/datastore/sql/postgres/files/counts.sql @@ -11,5 +11,4 @@ WHERE repo_active = true -- name: count-builds -SELECT reltuples -FROM pg_class WHERE relname = 'builds' +SELECT currval('builds_build_id_seq'); diff --git a/store/datastore/sql/postgres/sql.go b/store/datastore/sql/postgres/sql.go index 08b7734517..dafdfc0402 100644 --- a/store/datastore/sql/postgres/sql.go +++ b/store/datastore/sql/postgres/sql.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 postgres //go:generate togo sql --package=postgres diff --git a/store/datastore/sql/postgres/sql_gen.go b/store/datastore/sql/postgres/sql_gen.go index 3f0e2dacd5..5cb3576b1f 100644 --- a/store/datastore/sql/postgres/sql_gen.go +++ b/store/datastore/sql/postgres/sql_gen.go @@ -94,8 +94,7 @@ WHERE repo_active = true ` var countBuilds = ` -SELECT reltuples -FROM pg_class WHERE relname = 'builds' +SELECT currval('builds_build_id_seq'); ` var feedLatestBuild = ` diff --git a/store/datastore/sql/sqlite/sql.go b/store/datastore/sql/sqlite/sql.go index 9b8267f68c..d1481e699d 100644 --- a/store/datastore/sql/sqlite/sql.go +++ b/store/datastore/sql/sqlite/sql.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 sqlite //go:generate togo sql --package=sqlite diff --git a/store/datastore/sql/sqlite/sql_gen.go b/store/datastore/sql/sqlite/sql_gen.go index e98d2e36e5..a464217882 100644 --- a/store/datastore/sql/sqlite/sql_gen.go +++ b/store/datastore/sql/sqlite/sql_gen.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 sqlite // Lookup returns the named statement. diff --git a/store/datastore/store.go b/store/datastore/store.go index eb7058dc48..e3e1401a4d 100644 --- a/store/datastore/store.go +++ b/store/datastore/store.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/task.go b/store/datastore/task.go index d82e23800a..e095dc29a3 100644 --- a/store/datastore/task.go +++ b/store/datastore/task.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/task_test.go b/store/datastore/task_test.go index a155076586..118436a5ca 100644 --- a/store/datastore/task_test.go +++ b/store/datastore/task_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/users.go b/store/datastore/users.go index ba432c346d..e37baaee53 100644 --- a/store/datastore/users.go +++ b/store/datastore/users.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/users_test.go b/store/datastore/users_test.go index f37dbce56c..5fd580e6c6 100644 --- a/store/datastore/users_test.go +++ b/store/datastore/users_test.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/datastore/utils.go b/store/datastore/utils.go index dbf0e8b75d..979501cef2 100644 --- a/store/datastore/utils.go +++ b/store/datastore/utils.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 datastore import ( diff --git a/store/store.go b/store/store.go index ccfd635fe6..b93331a694 100644 --- a/store/store.go +++ b/store/store.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 store import ( @@ -67,7 +81,7 @@ type Store interface { GetBuildLastBefore(*model.Repo, string, int64) (*model.Build, error) // GetBuildList gets a list of builds for the repository - GetBuildList(*model.Repo) ([]*model.Build, error) + GetBuildList(*model.Repo, int) ([]*model.Build, error) // GetBuildQueue gets a list of build in queue. GetBuildQueue() ([]*model.Feed, error) @@ -223,8 +237,8 @@ func GetBuildLastBefore(c context.Context, repo *model.Repo, branch string, numb return FromContext(c).GetBuildLastBefore(repo, branch, number) } -func GetBuildList(c context.Context, repo *model.Repo) ([]*model.Build, error) { - return FromContext(c).GetBuildList(repo) +func GetBuildList(c context.Context, repo *model.Repo, page int) ([]*model.Build, error) { + return FromContext(c).GetBuildList(repo, page) } func GetBuildQueue(c context.Context) ([]*model.Feed, error) { diff --git a/vendor/github.com/cncd/pipeline/pipeline/backend/backend.go b/vendor/github.com/cncd/pipeline/pipeline/backend/backend.go index ef8331097d..6d4b7eeffe 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/backend/backend.go +++ b/vendor/github.com/cncd/pipeline/pipeline/backend/backend.go @@ -1,21 +1,24 @@ package backend -import "io" +import ( + "context" + "io" +) // Engine defines a container orchestration backend and is used // to create and manage container resources. type Engine interface { // Setup the pipeline environment. - Setup(*Config) error + Setup(context.Context, *Config) error // Start the pipeline step. - Exec(*Step) error + Exec(context.Context, *Step) error // Kill the pipeline step. - Kill(*Step) error + Kill(context.Context, *Step) error // Wait for the pipeline step to complete and returns // the completion results. - Wait(*Step) (*State, error) + Wait(context.Context, *Step) (*State, error) // Tail the pipeline step logs. - Tail(*Step) (io.ReadCloser, error) + Tail(context.Context, *Step) (io.ReadCloser, error) // Destroy the pipeline environment. - Destroy(*Config) error + Destroy(context.Context, *Config) error } diff --git a/vendor/github.com/cncd/pipeline/pipeline/backend/docker/convert.go b/vendor/github.com/cncd/pipeline/pipeline/backend/docker/convert.go index 0b7b5231df..724ad09534 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/backend/docker/convert.go +++ b/vendor/github.com/cncd/pipeline/pipeline/backend/docker/convert.go @@ -49,6 +49,7 @@ func toHostConfig(proc *backend.Step) *container.HostConfig { }, Privileged: proc.Privileged, ShmSize: proc.ShmSize, + Sysctls: proc.Sysctls, } // if len(proc.VolumesFrom) != 0 { diff --git a/vendor/github.com/cncd/pipeline/pipeline/backend/docker/docker.go b/vendor/github.com/cncd/pipeline/pipeline/backend/docker/docker.go index e7c67d6a04..84c333df16 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/backend/docker/docker.go +++ b/vendor/github.com/cncd/pipeline/pipeline/backend/docker/docker.go @@ -35,7 +35,7 @@ func NewEnv() (backend.Engine, error) { return New(cli), nil } -func (e *engine) Setup(conf *backend.Config) error { +func (e *engine) Setup(_ context.Context, conf *backend.Config) error { for _, vol := range conf.Volumes { _, err := e.client.VolumeCreate(noContext, volume.VolumesCreateBody{ Name: vol.Name, @@ -60,9 +60,7 @@ func (e *engine) Setup(conf *backend.Config) error { return nil } -func (e *engine) Exec(proc *backend.Step) error { - ctx := context.Background() - +func (e *engine) Exec(ctx context.Context, proc *backend.Step) error { config := toConfig(proc) hostConfig := toHostConfig(proc) @@ -126,12 +124,12 @@ func (e *engine) Exec(proc *backend.Step) error { return e.client.ContainerStart(ctx, proc.Name, startOpts) } -func (e *engine) Kill(proc *backend.Step) error { +func (e *engine) Kill(_ context.Context, proc *backend.Step) error { return e.client.ContainerKill(noContext, proc.Name, "9") } -func (e *engine) Wait(proc *backend.Step) (*backend.State, error) { - _, err := e.client.ContainerWait(noContext, proc.Name) +func (e *engine) Wait(ctx context.Context, proc *backend.Step) (*backend.State, error) { + _, err := e.client.ContainerWait(ctx, proc.Name) if err != nil { // todo } @@ -151,8 +149,8 @@ func (e *engine) Wait(proc *backend.Step) (*backend.State, error) { }, nil } -func (e *engine) Tail(proc *backend.Step) (io.ReadCloser, error) { - logs, err := e.client.ContainerLogs(noContext, proc.Name, logsOpts) +func (e *engine) Tail(ctx context.Context, proc *backend.Step) (io.ReadCloser, error) { + logs, err := e.client.ContainerLogs(ctx, proc.Name, logsOpts) if err != nil { return nil, err } @@ -167,7 +165,7 @@ func (e *engine) Tail(proc *backend.Step) (io.ReadCloser, error) { return rc, nil } -func (e *engine) Destroy(conf *backend.Config) error { +func (e *engine) Destroy(_ context.Context, conf *backend.Config) error { for _, stage := range conf.Stages { for _, step := range stage.Steps { e.client.ContainerKill(noContext, step.Name, "9") diff --git a/vendor/github.com/cncd/pipeline/pipeline/backend/types.go b/vendor/github.com/cncd/pipeline/pipeline/backend/types.go index 01d092344a..e9132d41ba 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/backend/types.go +++ b/vendor/github.com/cncd/pipeline/pipeline/backend/types.go @@ -47,6 +47,7 @@ type ( AuthConfig Auth `json:"auth_config,omitempty"` NetworkMode string `json:"network_mode,omitempty"` IpcMode string `json:"ipc_mode,omitempty"` + Sysctls map[string]string `json:"sysctls,omitempty"` } // Auth defines registry authentication credentials. diff --git a/vendor/github.com/cncd/pipeline/pipeline/frontend/metadata.go b/vendor/github.com/cncd/pipeline/pipeline/frontend/metadata.go index 574e6780fc..6c82514bdb 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/frontend/metadata.go +++ b/vendor/github.com/cncd/pipeline/pipeline/frontend/metadata.go @@ -33,6 +33,7 @@ type ( Remote string `json:"remote,omitempty"` Private bool `json:"private,omitempty"` Secrets []Secret `json:"secrets,omitempty"` + Branch string `json:"default_branch,omitempty"` } // Build defines runtime metadata for a build. @@ -181,7 +182,7 @@ func (m *Metadata) EnvironDrone() map[string]string { "DRONE_REPO_OWNER": owner, "DRONE_REPO_NAME": name, "DRONE_REPO_LINK": m.Repo.Link, - "DRONE_REPO_BRANCH": m.Curr.Commit.Branch, + "DRONE_REPO_BRANCH": m.Repo.Branch, "DRONE_REPO_PRIVATE": fmt.Sprintf("%v", m.Repo.Private), "DRONE_REPO_TRUSTED": "false", // TODO should this be added? "DRONE_REMOTE_URL": m.Repo.Remote, diff --git a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go index f815057086..ee39c9bc75 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go +++ b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/compiler/convert.go @@ -166,6 +166,7 @@ func (c *Compiler) createProcess(name string, container *yaml.Container, section MemSwapLimit: memSwapLimit, MemLimit: memLimit, ShmSize: shmSize, + Sysctls: container.Sysctls, CPUQuota: cpuQuota, CPUShares: cpuShares, CPUSet: cpuSet, diff --git a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/constraint.go b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/constraint.go index ad193b286c..a59dabb231 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/constraint.go +++ b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/constraint.go @@ -19,6 +19,7 @@ type ( Event Constraint Branch Constraint Status Constraint + Refspec Constraint Matrix ConstraintMap Local types.BoolTrue } @@ -43,8 +44,10 @@ func (c *Constraints) Match(metadata frontend.Metadata) bool { c.Environment.Match(metadata.Curr.Target) && c.Event.Match(metadata.Curr.Event) && c.Branch.Match(metadata.Curr.Commit.Branch) && + c.Refspec.Match(metadata.Curr.Commit.Refspec) && c.Repo.Match(metadata.Repo.Name) && c.Ref.Match(metadata.Curr.Commit.Ref) && + c.Instance.Match(metadata.Sys.Host) && c.Matrix.Match(metadata.Job.Matrix) } diff --git a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/container.go b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/container.go index ffdebb625f..e5975e8c02 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/container.go +++ b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/container.go @@ -55,6 +55,7 @@ type ( Ulimits libcompose.Ulimits `yaml:"ulimits,omitempty"` Volumes libcompose.Volumes `yaml:"volumes,omitempty"` Secrets Secrets `yaml:"secrets,omitempty"` + Sysctls libcompose.SliceorMap `yaml:"sysctls,omitempty"` Constraints Constraints `yaml:"when,omitempty"` Vargs map[string]interface{} `yaml:",inline"` } diff --git a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/linter/linter.go b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/linter/linter.go index 1facc16d45..a458e7e887 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/linter/linter.go +++ b/vendor/github.com/cncd/pipeline/pipeline/frontend/yaml/linter/linter.go @@ -127,6 +127,9 @@ func (l *Linter) lintTrusted(c *yaml.Container) error { if len(c.IpcMode) != 0 { return fmt.Errorf("Insufficient privileges to use ipc_mode") } + if len(c.Sysctls) != 0 { + return fmt.Errorf("Insufficient privileges to use sysctls") + } if c.Networks.Networks != nil && len(c.Networks.Networks) != 0 { return fmt.Errorf("Insufficient privileges to use networks") } diff --git a/vendor/github.com/cncd/pipeline/pipeline/pipeline.go b/vendor/github.com/cncd/pipeline/pipeline/pipeline.go index be6970f832..047d85bad6 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/pipeline.go +++ b/vendor/github.com/cncd/pipeline/pipeline/pipeline.go @@ -55,11 +55,11 @@ func New(spec *backend.Config, opts ...Option) *Runtime { // Run starts the runtime and waits for it to complete. func (r *Runtime) Run() error { defer func() { - r.engine.Destroy(r.spec) + r.engine.Destroy(r.ctx, r.spec) }() r.started = time.Now().Unix() - if err := r.engine.Setup(r.spec); err != nil { + if err := r.engine.Setup(r.ctx, r.spec); err != nil { return err } @@ -124,12 +124,12 @@ func (r *Runtime) exec(proc *backend.Step) error { } } - if err := r.engine.Exec(proc); err != nil { + if err := r.engine.Exec(r.ctx, proc); err != nil { return err } if r.logger != nil { - rc, err := r.engine.Tail(proc) + rc, err := r.engine.Tail(r.ctx, proc) if err != nil { return err } @@ -144,7 +144,7 @@ func (r *Runtime) exec(proc *backend.Step) error { return nil } - wait, err := r.engine.Wait(proc) + wait, err := r.engine.Wait(r.ctx, proc) if err != nil { return err } diff --git a/vendor/github.com/cncd/pipeline/pipeline/rpc/client_grpc.go b/vendor/github.com/cncd/pipeline/pipeline/rpc/client_grpc.go index 204c4fdd06..9917133210 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/rpc/client_grpc.go +++ b/vendor/github.com/cncd/pipeline/pipeline/rpc/client_grpc.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "time" + "log" "github.com/cncd/pipeline/pipeline/backend" "github.com/cncd/pipeline/pipeline/rpc/proto" @@ -46,6 +47,8 @@ func (c *client) Next(ctx context.Context, f Filter) (*Pipeline, error) { res, err = c.client.Next(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: done(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case @@ -84,6 +87,8 @@ func (c *client) Wait(ctx context.Context, id string) (err error) { _, err = c.client.Wait(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: wait(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case @@ -116,6 +121,8 @@ func (c *client) Init(ctx context.Context, id string, state State) (err error) { _, err = c.client.Init(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: init(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case @@ -148,6 +155,8 @@ func (c *client) Done(ctx context.Context, id string, state State) (err error) { _, err = c.client.Done(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: done(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case @@ -173,6 +182,8 @@ func (c *client) Extend(ctx context.Context, id string) (err error) { _, err = c.client.Extend(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: extend(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case @@ -205,6 +216,8 @@ func (c *client) Update(ctx context.Context, id string, state State) (err error) _, err = c.client.Update(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: update(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case @@ -238,6 +251,8 @@ func (c *client) Upload(ctx context.Context, id string, file *File) (err error) _, err = c.client.Upload(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: upload(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case @@ -268,6 +283,8 @@ func (c *client) Log(ctx context.Context, id string, line *Line) (err error) { _, err = c.client.Log(ctx, req) if err == nil { break + } else { + log.Printf("grpc error: log(): code: %v: %s", grpc.Code(err), err) } switch grpc.Code(err) { case diff --git a/vendor/github.com/cncd/pipeline/pipeline/rpc/client_grpc_health.go b/vendor/github.com/cncd/pipeline/pipeline/rpc/client_grpc_health.go new file mode 100644 index 0000000000..b2d9fc2091 --- /dev/null +++ b/vendor/github.com/cncd/pipeline/pipeline/rpc/client_grpc_health.go @@ -0,0 +1,63 @@ +package rpc + +import ( + "context" + // "encoding/json" + "time" + + // "github.com/cncd/pipeline/pipeline/backend" + "github.com/cncd/pipeline/pipeline/rpc/proto" + + "google.golang.org/grpc" + "google.golang.org/grpc/codes" +) + +// generate protobuffs +// protoc --go_out=plugins=grpc,import_path=proto:. *.proto + +type healthClient struct { + client proto.HealthClient + conn *grpc.ClientConn +} + +// NewGrpcHealthClient returns a new grpc Client. +func NewGrpcHealthClient(conn *grpc.ClientConn) Health { + client := new(healthClient) + client.client = proto.NewHealthClient(conn) + client.conn = conn + return client +} + +func (c *healthClient) Close() error { + return c.conn.Close() +} + +func (c *healthClient) Check(ctx context.Context) (bool, error) { + var res *proto.HealthCheckResponse + var err error + req := new(proto.HealthCheckRequest) + + for { + res, err = c.client.Check(ctx, req) + if err == nil { + if res.GetStatus() == proto.HealthCheckResponse_SERVING { + return true, nil + } + return false, nil + } + switch grpc.Code(err) { + case + codes.Aborted, + codes.DataLoss, + codes.DeadlineExceeded, + codes.Internal, + codes.Unavailable: + // non-fatal errors + default: + return false, err + } + <-time.After(backoff) + } + + return true, nil +} diff --git a/vendor/github.com/cncd/pipeline/pipeline/rpc/health.go b/vendor/github.com/cncd/pipeline/pipeline/rpc/health.go new file mode 100644 index 0000000000..1adc02c1b0 --- /dev/null +++ b/vendor/github.com/cncd/pipeline/pipeline/rpc/health.go @@ -0,0 +1,11 @@ +package rpc + +import ( + "context" +) + +// Health defines a health-check connection. +type Health interface { + // Check returns if server is healthy or not + Check(c context.Context) (bool, error) +} diff --git a/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.pb.go b/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.pb.go index ae214962b3..b4dea7c17e 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.pb.go +++ b/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.pb.go @@ -13,6 +13,8 @@ It has these top-level messages: Line Filter Pipeline + HealthCheckRequest + HealthCheckResponse NextRequest NextReply InitRequest @@ -46,6 +48,32 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto1.ProtoPackageIsVersion2 // please upgrade the proto package +type HealthCheckResponse_ServingStatus int32 + +const ( + HealthCheckResponse_UNKNOWN HealthCheckResponse_ServingStatus = 0 + HealthCheckResponse_SERVING HealthCheckResponse_ServingStatus = 1 + HealthCheckResponse_NOT_SERVING HealthCheckResponse_ServingStatus = 2 +) + +var HealthCheckResponse_ServingStatus_name = map[int32]string{ + 0: "UNKNOWN", + 1: "SERVING", + 2: "NOT_SERVING", +} +var HealthCheckResponse_ServingStatus_value = map[string]int32{ + "UNKNOWN": 0, + "SERVING": 1, + "NOT_SERVING": 2, +} + +func (x HealthCheckResponse_ServingStatus) String() string { + return proto1.EnumName(HealthCheckResponse_ServingStatus_name, int32(x)) +} +func (HealthCheckResponse_ServingStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor0, []int{6, 0} +} + type File struct { Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` Proc string `protobuf:"bytes,2,opt,name=proc" json:"proc,omitempty"` @@ -262,6 +290,38 @@ func (m *Pipeline) GetPayload() []byte { return nil } +type HealthCheckRequest struct { + Service string `protobuf:"bytes,1,opt,name=service" json:"service,omitempty"` +} + +func (m *HealthCheckRequest) Reset() { *m = HealthCheckRequest{} } +func (m *HealthCheckRequest) String() string { return proto1.CompactTextString(m) } +func (*HealthCheckRequest) ProtoMessage() {} +func (*HealthCheckRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } + +func (m *HealthCheckRequest) GetService() string { + if m != nil { + return m.Service + } + return "" +} + +type HealthCheckResponse struct { + Status HealthCheckResponse_ServingStatus `protobuf:"varint,1,opt,name=status,enum=proto.HealthCheckResponse_ServingStatus" json:"status,omitempty"` +} + +func (m *HealthCheckResponse) Reset() { *m = HealthCheckResponse{} } +func (m *HealthCheckResponse) String() string { return proto1.CompactTextString(m) } +func (*HealthCheckResponse) ProtoMessage() {} +func (*HealthCheckResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } + +func (m *HealthCheckResponse) GetStatus() HealthCheckResponse_ServingStatus { + if m != nil { + return m.Status + } + return HealthCheckResponse_UNKNOWN +} + type NextRequest struct { Filter *Filter `protobuf:"bytes,1,opt,name=filter" json:"filter,omitempty"` } @@ -269,7 +329,7 @@ type NextRequest struct { func (m *NextRequest) Reset() { *m = NextRequest{} } func (m *NextRequest) String() string { return proto1.CompactTextString(m) } func (*NextRequest) ProtoMessage() {} -func (*NextRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } +func (*NextRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} } func (m *NextRequest) GetFilter() *Filter { if m != nil { @@ -285,7 +345,7 @@ type NextReply struct { func (m *NextReply) Reset() { *m = NextReply{} } func (m *NextReply) String() string { return proto1.CompactTextString(m) } func (*NextReply) ProtoMessage() {} -func (*NextReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} } +func (*NextReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} } func (m *NextReply) GetPipeline() *Pipeline { if m != nil { @@ -302,7 +362,7 @@ type InitRequest struct { func (m *InitRequest) Reset() { *m = InitRequest{} } func (m *InitRequest) String() string { return proto1.CompactTextString(m) } func (*InitRequest) ProtoMessage() {} -func (*InitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} } +func (*InitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } func (m *InitRequest) GetId() string { if m != nil { @@ -325,7 +385,7 @@ type WaitRequest struct { func (m *WaitRequest) Reset() { *m = WaitRequest{} } func (m *WaitRequest) String() string { return proto1.CompactTextString(m) } func (*WaitRequest) ProtoMessage() {} -func (*WaitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} } +func (*WaitRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} } func (m *WaitRequest) GetId() string { if m != nil { @@ -342,7 +402,7 @@ type DoneRequest struct { func (m *DoneRequest) Reset() { *m = DoneRequest{} } func (m *DoneRequest) String() string { return proto1.CompactTextString(m) } func (*DoneRequest) ProtoMessage() {} -func (*DoneRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} } +func (*DoneRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11} } func (m *DoneRequest) GetId() string { if m != nil { @@ -365,7 +425,7 @@ type ExtendRequest struct { func (m *ExtendRequest) Reset() { *m = ExtendRequest{} } func (m *ExtendRequest) String() string { return proto1.CompactTextString(m) } func (*ExtendRequest) ProtoMessage() {} -func (*ExtendRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} } +func (*ExtendRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{12} } func (m *ExtendRequest) GetId() string { if m != nil { @@ -382,7 +442,7 @@ type UploadRequest struct { func (m *UploadRequest) Reset() { *m = UploadRequest{} } func (m *UploadRequest) String() string { return proto1.CompactTextString(m) } func (*UploadRequest) ProtoMessage() {} -func (*UploadRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11} } +func (*UploadRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{13} } func (m *UploadRequest) GetId() string { if m != nil { @@ -406,7 +466,7 @@ type UpdateRequest struct { func (m *UpdateRequest) Reset() { *m = UpdateRequest{} } func (m *UpdateRequest) String() string { return proto1.CompactTextString(m) } func (*UpdateRequest) ProtoMessage() {} -func (*UpdateRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{12} } +func (*UpdateRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{14} } func (m *UpdateRequest) GetId() string { if m != nil { @@ -430,7 +490,7 @@ type LogRequest struct { func (m *LogRequest) Reset() { *m = LogRequest{} } func (m *LogRequest) String() string { return proto1.CompactTextString(m) } func (*LogRequest) ProtoMessage() {} -func (*LogRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{13} } +func (*LogRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{15} } func (m *LogRequest) GetId() string { if m != nil { @@ -452,7 +512,7 @@ type Empty struct { func (m *Empty) Reset() { *m = Empty{} } func (m *Empty) String() string { return proto1.CompactTextString(m) } func (*Empty) ProtoMessage() {} -func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{14} } +func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{16} } func init() { proto1.RegisterType((*File)(nil), "proto.File") @@ -460,6 +520,8 @@ func init() { proto1.RegisterType((*Line)(nil), "proto.Line") proto1.RegisterType((*Filter)(nil), "proto.Filter") proto1.RegisterType((*Pipeline)(nil), "proto.Pipeline") + proto1.RegisterType((*HealthCheckRequest)(nil), "proto.HealthCheckRequest") + proto1.RegisterType((*HealthCheckResponse)(nil), "proto.HealthCheckResponse") proto1.RegisterType((*NextRequest)(nil), "proto.NextRequest") proto1.RegisterType((*NextReply)(nil), "proto.NextReply") proto1.RegisterType((*InitRequest)(nil), "proto.InitRequest") @@ -470,6 +532,7 @@ func init() { proto1.RegisterType((*UpdateRequest)(nil), "proto.UpdateRequest") proto1.RegisterType((*LogRequest)(nil), "proto.LogRequest") proto1.RegisterType((*Empty)(nil), "proto.Empty") + proto1.RegisterEnum("proto.HealthCheckResponse_ServingStatus", HealthCheckResponse_ServingStatus_name, HealthCheckResponse_ServingStatus_value) } // Reference imports to suppress errors if they are not otherwise used. @@ -775,50 +838,121 @@ var _Drone_serviceDesc = grpc.ServiceDesc{ Metadata: "drone.proto", } +// Client API for Health service + +type HealthClient interface { + Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) +} + +type healthClient struct { + cc *grpc.ClientConn +} + +func NewHealthClient(cc *grpc.ClientConn) HealthClient { + return &healthClient{cc} +} + +func (c *healthClient) Check(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) { + out := new(HealthCheckResponse) + err := grpc.Invoke(ctx, "/proto.Health/Check", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Health service + +type HealthServer interface { + Check(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) +} + +func RegisterHealthServer(s *grpc.Server, srv HealthServer) { + s.RegisterService(&_Health_serviceDesc, srv) +} + +func _Health_Check_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HealthCheckRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HealthServer).Check(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Health/Check", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HealthServer).Check(ctx, req.(*HealthCheckRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Health_serviceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Health", + HandlerType: (*HealthServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Check", + Handler: _Health_Check_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "drone.proto", +} + func init() { proto1.RegisterFile("drone.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 661 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xed, 0x6a, 0xd4, 0x4c, - 0x14, 0x7e, 0xb3, 0xf9, 0xe8, 0xee, 0x49, 0xfb, 0x5a, 0x87, 0x2a, 0x71, 0x45, 0xba, 0x04, 0x84, - 0x55, 0x61, 0xc1, 0x55, 0xb0, 0x0a, 0x82, 0xd2, 0x0f, 0x10, 0xd6, 0x22, 0x23, 0xe2, 0x4f, 0x49, - 0x9b, 0xd3, 0x3a, 0x98, 0xcd, 0xc4, 0x64, 0x2a, 0x1b, 0x2f, 0xc1, 0x6b, 0xf0, 0xea, 0xbc, 0x07, - 0xff, 0xcb, 0x99, 0x99, 0xa4, 0xd9, 0x76, 0x2b, 0x48, 0x7f, 0xed, 0xf9, 0x78, 0x66, 0xce, 0x73, - 0x9e, 0x67, 0xb2, 0x10, 0xa6, 0xa5, 0xcc, 0x71, 0x52, 0x94, 0x52, 0x49, 0xe6, 0xeb, 0x9f, 0xf8, - 0x97, 0x03, 0xde, 0x81, 0xc8, 0x90, 0x31, 0xf0, 0xf2, 0x64, 0x8e, 0x91, 0x33, 0x72, 0xc6, 0x03, - 0xae, 0x63, 0xaa, 0x15, 0xa5, 0x3c, 0x8e, 0x7a, 0xa6, 0x46, 0x31, 0xd5, 0xe6, 0x62, 0x8e, 0x91, - 0x6b, 0x6a, 0x14, 0x53, 0x4d, 0x51, 0xcd, 0x1b, 0x39, 0x63, 0x97, 0xeb, 0x98, 0x6a, 0x95, 0xf8, - 0x8e, 0x91, 0x3f, 0x72, 0xc6, 0x3e, 0xd7, 0x31, 0xd5, 0xd2, 0x44, 0x25, 0x51, 0x30, 0x72, 0xc6, - 0xeb, 0x5c, 0xc7, 0xec, 0x01, 0x78, 0x73, 0x54, 0x49, 0xb4, 0x36, 0x72, 0xc7, 0xe1, 0xf4, 0x96, - 0x61, 0x37, 0x21, 0x4a, 0x93, 0xb7, 0xa8, 0x92, 0xfd, 0x5c, 0x95, 0x35, 0xd7, 0x90, 0xe1, 0x33, - 0x18, 0xb4, 0x25, 0xb6, 0x09, 0xee, 0x17, 0xac, 0x2d, 0x5d, 0x0a, 0xd9, 0x16, 0xf8, 0xdf, 0x92, - 0xec, 0x0c, 0x2d, 0x5d, 0x93, 0xbc, 0xe8, 0xed, 0x38, 0xf1, 0x4f, 0x07, 0xfc, 0xf7, 0x2a, 0x51, - 0xab, 0xb7, 0xbc, 0x0d, 0x01, 0x2e, 0x84, 0xc2, 0x54, 0x1f, 0xec, 0x73, 0x9b, 0xb1, 0xbb, 0x30, - 0xa0, 0xe8, 0xd3, 0xb1, 0x4c, 0xcd, 0xba, 0x3e, 0xef, 0x53, 0x61, 0x57, 0xa6, 0xc8, 0x22, 0x58, - 0xab, 0x54, 0x52, 0xd2, 0x29, 0xb3, 0x75, 0x93, 0xb2, 0x21, 0xf4, 0x4f, 0x44, 0x2e, 0xaa, 0xcf, - 0x98, 0xea, 0xe5, 0x5d, 0xde, 0xe6, 0x44, 0x11, 0xcb, 0x52, 0x96, 0x5a, 0x81, 0x01, 0x37, 0x49, - 0xcc, 0xc1, 0x9b, 0x89, 0xfc, 0x5c, 0x6e, 0x67, 0x59, 0x6e, 0x2d, 0x6d, 0xaf, 0x23, 0xed, 0x26, - 0xb8, 0x85, 0xac, 0x2c, 0x25, 0x0a, 0xa9, 0x22, 0xcf, 0x94, 0x66, 0x32, 0xe0, 0x14, 0xc6, 0x3f, - 0x1c, 0x08, 0x0e, 0x44, 0xa6, 0xb0, 0x64, 0x8f, 0x21, 0xc8, 0x92, 0x23, 0xcc, 0xaa, 0xc8, 0xd1, - 0x1a, 0xdf, 0x39, 0xd7, 0x58, 0x61, 0x39, 0x99, 0xe9, 0x9e, 0xd1, 0xd9, 0x02, 0x69, 0x2a, 0x2e, - 0x8a, 0xb2, 0x31, 0x9e, 0xe2, 0xe1, 0x73, 0x08, 0x3b, 0xd0, 0x7f, 0xd2, 0xff, 0x10, 0xfa, 0xef, - 0x44, 0x81, 0x19, 0x2d, 0xf9, 0x3f, 0xf4, 0x44, 0x6a, 0x8f, 0xf5, 0x44, 0x4a, 0x42, 0xd2, 0x52, - 0x44, 0xdf, 0xec, 0xd8, 0xa4, 0xd4, 0x29, 0x92, 0x3a, 0x93, 0x49, 0xaa, 0x57, 0x5d, 0xe7, 0x4d, - 0x1a, 0x3f, 0x85, 0xf0, 0x10, 0x17, 0x8a, 0xe3, 0xd7, 0x33, 0xac, 0x14, 0xbb, 0x0f, 0xc1, 0x89, - 0xde, 0x45, 0x5f, 0x1b, 0x4e, 0x37, 0x96, 0x16, 0xe4, 0xb6, 0x19, 0xef, 0xc0, 0xc0, 0x9c, 0x2a, - 0xb2, 0x9a, 0x3d, 0x82, 0x7e, 0x61, 0x29, 0xd9, 0x53, 0x37, 0xec, 0xa9, 0x86, 0x29, 0x6f, 0x01, - 0xf1, 0x6b, 0x08, 0xdf, 0xe4, 0xa2, 0x9d, 0x77, 0x71, 0x85, 0x18, 0xfc, 0x8a, 0x5e, 0x97, 0x5e, - 0x20, 0x9c, 0xae, 0xdb, 0x8b, 0xf4, 0x8b, 0xe3, 0xa6, 0x15, 0xdf, 0x83, 0xf0, 0x63, 0x72, 0xe5, - 0x15, 0x34, 0x61, 0x4f, 0xe6, 0x78, 0x9d, 0x09, 0xdb, 0xb0, 0xb1, 0xbf, 0x50, 0x98, 0xa7, 0x57, - 0xcd, 0x78, 0x05, 0x1b, 0x1f, 0x0a, 0xd2, 0xef, 0xaa, 0x29, 0xdb, 0xe0, 0x9d, 0x88, 0xac, 0x19, - 0x12, 0x76, 0x3e, 0x45, 0xae, 0x1b, 0xf1, 0x2e, 0xdd, 0x90, 0xd2, 0xcc, 0x6b, 0xf0, 0x7c, 0x09, - 0x30, 0x93, 0xa7, 0x7f, 0xe1, 0xa0, 0x3d, 0x59, 0xe6, 0x40, 0x9f, 0x07, 0xd7, 0x8d, 0x78, 0x0d, - 0xfc, 0xfd, 0x79, 0xa1, 0xea, 0xe9, 0xef, 0x1e, 0xf8, 0x7b, 0xf4, 0x87, 0xc6, 0x26, 0xe0, 0x91, - 0xb1, 0x8c, 0x59, 0x74, 0xe7, 0x6d, 0x0c, 0x37, 0x97, 0x6a, 0x45, 0x56, 0xc7, 0xff, 0xb1, 0x87, - 0xe0, 0x91, 0x9d, 0x2d, 0xbe, 0xe3, 0xed, 0xb0, 0xa1, 0xac, 0x67, 0x18, 0x2c, 0xf9, 0xd6, 0x62, - 0x3b, 0x26, 0xae, 0xc2, 0x92, 0x89, 0x2d, 0xb6, 0xe3, 0xe8, 0x25, 0xec, 0x04, 0x02, 0xe3, 0x16, - 0xdb, 0x6a, 0x3a, 0x5d, 0xf3, 0x56, 0xe1, 0x8d, 0xf4, 0x2d, 0x7e, 0xc9, 0x89, 0xd5, 0x78, 0x32, - 0xbb, 0x83, 0xef, 0x78, 0x7f, 0x09, 0x3f, 0x06, 0x77, 0x26, 0x4f, 0xd9, 0xcd, 0x46, 0xf0, 0xd6, - 0xa1, 0x8b, 0xc8, 0xa3, 0x40, 0xa7, 0x4f, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0xe9, 0x21, 0xb6, - 0xce, 0x4e, 0x06, 0x00, 0x00, + // 780 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x5f, 0x4f, 0xd3, 0x50, + 0x14, 0xa7, 0x5b, 0xdb, 0x6d, 0xa7, 0x0c, 0xe6, 0x15, 0x4d, 0x99, 0x31, 0x2c, 0x4d, 0x4c, 0xa6, + 0x26, 0x4d, 0x9c, 0x26, 0x22, 0x89, 0x06, 0x03, 0x43, 0x88, 0x73, 0x98, 0x3b, 0x91, 0x47, 0x52, + 0xd6, 0x0b, 0x34, 0x74, 0x6d, 0x6d, 0xef, 0xc8, 0xe6, 0x47, 0xf0, 0xd5, 0x57, 0x3f, 0x9d, 0xdf, + 0xc1, 0x77, 0x73, 0xee, 0x6d, 0x4b, 0x07, 0x9b, 0x89, 0xe1, 0xa9, 0xe7, 0xcf, 0xef, 0xdc, 0x73, + 0xce, 0xef, 0xd7, 0x7b, 0xc1, 0x70, 0xe3, 0x30, 0x60, 0x76, 0x14, 0x87, 0x3c, 0x24, 0x9a, 0xf8, + 0x58, 0xbf, 0x15, 0x50, 0xf7, 0x3c, 0x9f, 0x11, 0x02, 0x6a, 0xe0, 0x8c, 0x98, 0xa9, 0xb4, 0x94, + 0x76, 0x8d, 0x0a, 0x1b, 0x63, 0x51, 0x1c, 0x0e, 0xcd, 0x92, 0x8c, 0xa1, 0x8d, 0xb1, 0x91, 0x37, + 0x62, 0x66, 0x59, 0xc6, 0xd0, 0xc6, 0x18, 0xc7, 0x98, 0xda, 0x52, 0xda, 0x65, 0x2a, 0x6c, 0x8c, + 0x25, 0xde, 0x77, 0x66, 0x6a, 0x2d, 0xa5, 0xad, 0x51, 0x61, 0x63, 0xcc, 0x75, 0xb8, 0x63, 0xea, + 0x2d, 0xa5, 0xbd, 0x4c, 0x85, 0x4d, 0x9e, 0x82, 0x3a, 0x62, 0xdc, 0x31, 0x2b, 0xad, 0x72, 0xdb, + 0xe8, 0x3c, 0x90, 0xd3, 0xd9, 0x38, 0x92, 0xfd, 0x89, 0x71, 0xa7, 0x1b, 0xf0, 0x78, 0x4a, 0x05, + 0xa4, 0xf9, 0x1a, 0x6a, 0x79, 0x88, 0x34, 0xa0, 0x7c, 0xc9, 0xa6, 0xe9, 0xb8, 0x68, 0x92, 0x35, + 0xd0, 0xae, 0x1c, 0x7f, 0xcc, 0xd2, 0x71, 0xa5, 0xb3, 0x55, 0xda, 0x54, 0xac, 0x5f, 0x0a, 0x68, + 0x03, 0xee, 0xf0, 0xf9, 0x5b, 0x3e, 0x04, 0x9d, 0x4d, 0x3c, 0xce, 0x5c, 0x51, 0x58, 0xa5, 0xa9, + 0x47, 0x1e, 0x41, 0x0d, 0xad, 0x93, 0x61, 0xe8, 0xca, 0x75, 0x35, 0x5a, 0xc5, 0xc0, 0x4e, 0xe8, + 0x32, 0x62, 0x42, 0x25, 0xe1, 0x4e, 0x8c, 0x55, 0x72, 0xeb, 0xcc, 0x25, 0x4d, 0xa8, 0x9e, 0x79, + 0x81, 0x97, 0x5c, 0x30, 0x57, 0x2c, 0x5f, 0xa6, 0xb9, 0x8f, 0x23, 0xb2, 0x38, 0x0e, 0x63, 0xc1, + 0x40, 0x8d, 0x4a, 0xc7, 0xa2, 0xa0, 0xf6, 0xbc, 0xe0, 0x9a, 0x6e, 0x65, 0x96, 0x6e, 0x41, 0x6d, + 0xa9, 0x40, 0x6d, 0x03, 0xca, 0x51, 0x98, 0xa4, 0x23, 0xa1, 0x89, 0x91, 0x70, 0xcc, 0xc5, 0x24, + 0x35, 0x8a, 0xa6, 0xf5, 0x43, 0x01, 0x7d, 0xcf, 0xf3, 0x39, 0x8b, 0xc9, 0x0b, 0xd0, 0x7d, 0xe7, + 0x94, 0xf9, 0x89, 0xa9, 0x08, 0x8e, 0xd7, 0xaf, 0x39, 0xe6, 0x2c, 0xb6, 0x7b, 0x22, 0x27, 0x79, + 0x4e, 0x81, 0xd8, 0x95, 0x4d, 0xa2, 0x38, 0x13, 0x1e, 0xed, 0xe6, 0x1b, 0x30, 0x0a, 0xd0, 0xff, + 0xe2, 0xbf, 0x0f, 0xd5, 0xcf, 0x5e, 0xc4, 0x7c, 0x5c, 0x72, 0x05, 0x4a, 0x9e, 0x9b, 0x96, 0x95, + 0x3c, 0x17, 0x89, 0xc4, 0xa5, 0x70, 0x7c, 0xb9, 0x63, 0xe6, 0x62, 0x26, 0x72, 0xa6, 0x7e, 0xe8, + 0xb8, 0x62, 0xd5, 0x65, 0x9a, 0xb9, 0x96, 0x0d, 0x64, 0x9f, 0x39, 0x3e, 0xbf, 0xd8, 0xb9, 0x60, + 0xc3, 0x4b, 0xca, 0xbe, 0x8d, 0x59, 0x22, 0xf0, 0x09, 0x8b, 0xaf, 0xbc, 0x61, 0x26, 0x6f, 0xe6, + 0x5a, 0x3f, 0x15, 0xb8, 0x3f, 0x53, 0x90, 0x44, 0x61, 0x90, 0x30, 0xb2, 0x0d, 0x7a, 0xc2, 0x1d, + 0x3e, 0x4e, 0x44, 0xc1, 0x4a, 0xa7, 0x9d, 0x32, 0x33, 0x07, 0x6b, 0x0f, 0xf0, 0xac, 0xe0, 0x7c, + 0x20, 0xf0, 0x34, 0xad, 0xb3, 0xb6, 0xa0, 0x3e, 0x93, 0x20, 0x06, 0x54, 0x8e, 0xfa, 0x1f, 0xfb, + 0x87, 0xc7, 0xfd, 0xc6, 0x12, 0x3a, 0x83, 0x2e, 0xfd, 0x7a, 0xd0, 0xff, 0xd0, 0x50, 0xc8, 0x2a, + 0x18, 0xfd, 0xc3, 0x2f, 0x27, 0x59, 0xa0, 0x64, 0xbd, 0x02, 0xa3, 0xcf, 0x26, 0x3c, 0x1b, 0xff, + 0x09, 0xe8, 0x67, 0x42, 0x11, 0x31, 0x8c, 0xd1, 0xa9, 0xcf, 0xc8, 0x44, 0xd3, 0xa4, 0xb5, 0x09, + 0x35, 0x59, 0x15, 0xf9, 0x53, 0xf2, 0x1c, 0xaa, 0x51, 0x4a, 0x6c, 0x5a, 0xb5, 0x9a, 0x56, 0x65, + 0x7c, 0xd3, 0x1c, 0x60, 0xbd, 0x07, 0xe3, 0x20, 0xf0, 0xf2, 0x7e, 0x37, 0x85, 0xb0, 0x40, 0xc3, + 0xa5, 0xa4, 0x7c, 0x46, 0x67, 0x39, 0x3d, 0x48, 0xdc, 0x1b, 0x2a, 0x53, 0xd6, 0x63, 0x30, 0x8e, + 0x9d, 0x85, 0x47, 0x60, 0x87, 0xdd, 0x30, 0x60, 0x77, 0xe9, 0xb0, 0x01, 0xf5, 0xee, 0x84, 0xb3, + 0xc0, 0x5d, 0xd4, 0x63, 0x1b, 0xea, 0x47, 0x11, 0xfe, 0x05, 0x8b, 0xba, 0x6c, 0x80, 0x7a, 0xe6, + 0xf9, 0x59, 0x13, 0xa3, 0xf0, 0xa0, 0x50, 0x91, 0xb0, 0x76, 0xf0, 0x04, 0x17, 0x7b, 0xde, 0x61, + 0xce, 0xb7, 0x00, 0xbd, 0xf0, 0xfc, 0x1f, 0x33, 0x08, 0x4d, 0x66, 0x67, 0xc0, 0x4b, 0x4e, 0x45, + 0xc2, 0xaa, 0x80, 0xd6, 0x1d, 0x45, 0x7c, 0xda, 0xf9, 0x53, 0x02, 0x6d, 0x17, 0x9f, 0x65, 0x62, + 0x83, 0x8a, 0xc2, 0x12, 0x92, 0xa2, 0x0b, 0xff, 0x46, 0xb3, 0x31, 0x13, 0x8b, 0xfc, 0xa9, 0xb5, + 0x44, 0x9e, 0x81, 0x8a, 0x72, 0xe6, 0xf8, 0x82, 0xb6, 0xcd, 0x6c, 0x64, 0xd1, 0x43, 0x62, 0x51, + 0xb7, 0x1c, 0x5b, 0x10, 0x71, 0x1e, 0x16, 0x45, 0xcc, 0xb1, 0x05, 0x45, 0x6f, 0x61, 0x6d, 0xd0, + 0xa5, 0x5a, 0x64, 0x2d, 0xcb, 0x14, 0xc5, 0x9b, 0x87, 0x97, 0xd4, 0xe7, 0xf8, 0x19, 0x25, 0xe6, + 0xe3, 0x51, 0xec, 0x02, 0xbe, 0xa0, 0xfd, 0x2d, 0x7c, 0x1b, 0xca, 0xbd, 0xf0, 0x9c, 0xdc, 0xcb, + 0x08, 0xcf, 0x15, 0xba, 0x89, 0xec, 0xec, 0x83, 0x2e, 0x6f, 0x39, 0x79, 0x07, 0x9a, 0xb8, 0xe9, + 0x64, 0x7d, 0xde, 0xed, 0x97, 0xd5, 0xcd, 0xc5, 0x0f, 0xc3, 0xa9, 0x2e, 0x52, 0x2f, 0xff, 0x06, + 0x00, 0x00, 0xff, 0xff, 0x59, 0x78, 0xda, 0x5d, 0x5e, 0x07, 0x00, 0x00, } diff --git a/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.proto b/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.proto index 49ec122e66..97345e291e 100644 --- a/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.proto +++ b/vendor/github.com/cncd/pipeline/pipeline/rpc/proto/drone.proto @@ -39,6 +39,19 @@ message Pipeline { bytes payload = 3; } +message HealthCheckRequest { + string service = 1; +} + +message HealthCheckResponse { + enum ServingStatus { + UNKNOWN = 0; + SERVING = 1; + NOT_SERVING = 2; + } + ServingStatus status = 1; +} + service Drone { rpc Next (NextRequest) returns (NextReply) {} rpc Init (InitRequest) returns (Empty) {} @@ -50,6 +63,10 @@ service Drone { rpc Log (LogRequest) returns (Empty) {} } +service Health { + rpc Check(HealthCheckRequest) returns (HealthCheckResponse); +} + // // next // diff --git a/vendor/golang.org/x/crypto/acme/acme.go b/vendor/golang.org/x/crypto/acme/acme.go index 4e409be6d2..fa9c4b39e2 100644 --- a/vendor/golang.org/x/crypto/acme/acme.go +++ b/vendor/golang.org/x/crypto/acme/acme.go @@ -51,38 +51,6 @@ const ( maxNonces = 100 ) -// CertOption is an optional argument type for Client methods which manipulate -// certificate data. -type CertOption interface { - privateCertOpt() -} - -// WithKey creates an option holding a private/public key pair. -// The private part signs a certificate, and the public part represents the signee. -func WithKey(key crypto.Signer) CertOption { - return &certOptKey{key} -} - -type certOptKey struct { - key crypto.Signer -} - -func (*certOptKey) privateCertOpt() {} - -// WithTemplate creates an option for specifying a certificate template. -// See x509.CreateCertificate for template usage details. -// -// In TLSSNIxChallengeCert methods, the template is also used as parent, -// resulting in a self-signed certificate. -// The DNSNames field of t is always overwritten for tls-sni challenge certs. -func WithTemplate(t *x509.Certificate) CertOption { - return (*certOptTemplate)(t) -} - -type certOptTemplate x509.Certificate - -func (*certOptTemplate) privateCertOpt() {} - // Client is an ACME client. // The only required field is Key. An example of creating a client with a new key // is as follows: @@ -174,7 +142,7 @@ func (c *Client) Discover(ctx context.Context) (Directory, error) { // // In the case where CA server does not provide the issued certificate in the response, // CreateCert will poll certURL using c.FetchCert, which will result in additional round-trips. -// In such scenario the caller can cancel the polling with ctx. +// In such a scenario, the caller can cancel the polling with ctx. // // CreateCert returns an error if the CA's response or chain was unreasonably large. // Callers are encouraged to parse the returned value to ensure the certificate is valid and has the expected features. @@ -289,7 +257,7 @@ func (c *Client) RevokeCert(ctx context.Context, key crypto.Signer, cert []byte, func AcceptTOS(tosURL string) bool { return true } // Register creates a new account registration by following the "new-reg" flow. -// It returns registered account. The a argument is not modified. +// It returns the registered account. The account is not modified. // // The registration may require the caller to agree to the CA's Terms of Service (TOS). // If so, and the account has not indicated the acceptance of the terms (see Account for details), @@ -1027,6 +995,7 @@ func keyAuth(pub crypto.PublicKey, token string) (string, error) { // tlsChallengeCert creates a temporary certificate for TLS-SNI challenges // with the given SANs and auto-generated public/private key pair. +// The Subject Common Name is set to the first SAN to aid debugging. // To create a cert with a custom key pair, specify WithKey option. func tlsChallengeCert(san []string, opt []CertOption) (tls.Certificate, error) { var ( @@ -1065,6 +1034,9 @@ func tlsChallengeCert(san []string, opt []CertOption) (tls.Certificate, error) { } } tmpl.DNSNames = san + if len(san) > 0 { + tmpl.Subject.CommonName = san[0] + } der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, key.Public(), key) if err != nil { diff --git a/vendor/golang.org/x/crypto/acme/autocert/autocert.go b/vendor/golang.org/x/crypto/acme/autocert/autocert.go index a478eff54a..453e72291f 100644 --- a/vendor/golang.org/x/crypto/acme/autocert/autocert.go +++ b/vendor/golang.org/x/crypto/acme/autocert/autocert.go @@ -24,7 +24,9 @@ import ( "fmt" "io" mathrand "math/rand" + "net" "net/http" + "path" "strconv" "strings" "sync" @@ -80,11 +82,14 @@ func defaultHostPolicy(context.Context, string) error { } // Manager is a stateful certificate manager built on top of acme.Client. -// It obtains and refreshes certificates automatically, -// as well as providing them to a TLS server via tls.Config. +// It obtains and refreshes certificates automatically using "tls-sni-01", +// "tls-sni-02" and "http-01" challenge types, as well as providing them +// to a TLS server via tls.Config. // -// To preserve issued certificates and improve overall performance, -// use a cache implementation of Cache. For instance, DirCache. +// You must specify a cache implementation, such as DirCache, +// to reuse obtained certificates across program restarts. +// Otherwise your server is very likely to exceed the certificate +// issuer's request rate limits. type Manager struct { // Prompt specifies a callback function to conditionally accept a CA's Terms of Service (TOS). // The registration may require the caller to agree to the CA's TOS. @@ -148,15 +153,26 @@ type Manager struct { stateMu sync.Mutex state map[string]*certState // keyed by domain name - // tokenCert is keyed by token domain name, which matches server name - // of ClientHello. Keys always have ".acme.invalid" suffix. - tokenCertMu sync.RWMutex - tokenCert map[string]*tls.Certificate - // renewal tracks the set of domains currently running renewal timers. // It is keyed by domain name. renewalMu sync.Mutex renewal map[string]*domainRenewal + + // tokensMu guards the rest of the fields: tryHTTP01, certTokens and httpTokens. + tokensMu sync.RWMutex + // tryHTTP01 indicates whether the Manager should try "http-01" challenge type + // during the authorization flow. + tryHTTP01 bool + // httpTokens contains response body values for http-01 challenges + // and is keyed by the URL path at which a challenge response is expected + // to be provisioned. + // The entries are stored for the duration of the authorization flow. + httpTokens map[string][]byte + // certTokens contains temporary certificates for tls-sni challenges + // and is keyed by token domain name, which matches server name of ClientHello. + // Keys always have ".acme.invalid" suffix. + // The entries are stored for the duration of the authorization flow. + certTokens map[string]*tls.Certificate } // GetCertificate implements the tls.Config.GetCertificate hook. @@ -183,14 +199,16 @@ func (m *Manager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, return nil, errors.New("acme/autocert: server name contains invalid character") } + // In the worst-case scenario, the timeout needs to account for caching, host policy, + // domain ownership verification and certificate issuance. ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() // check whether this is a token cert requested for TLS-SNI challenge if strings.HasSuffix(name, ".acme.invalid") { - m.tokenCertMu.RLock() - defer m.tokenCertMu.RUnlock() - if cert := m.tokenCert[name]; cert != nil { + m.tokensMu.RLock() + defer m.tokensMu.RUnlock() + if cert := m.certTokens[name]; cert != nil { return cert, nil } if cert, err := m.cacheGet(ctx, name); err == nil { @@ -222,6 +240,68 @@ func (m *Manager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, return cert, nil } +// HTTPHandler configures the Manager to provision ACME "http-01" challenge responses. +// It returns an http.Handler that responds to the challenges and must be +// running on port 80. If it receives a request that is not an ACME challenge, +// it delegates the request to the optional fallback handler. +// +// If fallback is nil, the returned handler redirects all GET and HEAD requests +// to the default TLS port 443 with 302 Found status code, preserving the original +// request path and query. It responds with 400 Bad Request to all other HTTP methods. +// The fallback is not protected by the optional HostPolicy. +// +// Because the fallback handler is run with unencrypted port 80 requests, +// the fallback should not serve TLS-only requests. +// +// If HTTPHandler is never called, the Manager will only use TLS SNI +// challenges for domain verification. +func (m *Manager) HTTPHandler(fallback http.Handler) http.Handler { + m.tokensMu.Lock() + defer m.tokensMu.Unlock() + m.tryHTTP01 = true + + if fallback == nil { + fallback = http.HandlerFunc(handleHTTPRedirect) + } + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !strings.HasPrefix(r.URL.Path, "/.well-known/acme-challenge/") { + fallback.ServeHTTP(w, r) + return + } + // A reasonable context timeout for cache and host policy only, + // because we don't wait for a new certificate issuance here. + ctx, cancel := context.WithTimeout(r.Context(), time.Minute) + defer cancel() + if err := m.hostPolicy()(ctx, r.Host); err != nil { + http.Error(w, err.Error(), http.StatusForbidden) + return + } + data, err := m.httpToken(ctx, r.URL.Path) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + w.Write(data) + }) +} + +func handleHTTPRedirect(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" && r.Method != "HEAD" { + http.Error(w, "Use HTTPS", http.StatusBadRequest) + return + } + target := "https://" + stripPort(r.Host) + r.URL.RequestURI() + http.Redirect(w, r, target, http.StatusFound) +} + +func stripPort(hostport string) string { + host, _, err := net.SplitHostPort(hostport) + if err != nil { + return hostport + } + return net.JoinHostPort(host, "443") +} + // cert returns an existing certificate either from m.state or cache. // If a certificate is found in cache but not in m.state, the latter will be filled // with the cached value. @@ -369,7 +449,7 @@ func (m *Manager) createCert(ctx context.Context, domain string) (*tls.Certifica // We are the first; state is locked. // Unblock the readers when domain ownership is verified - // and the we got the cert or the process failed. + // and we got the cert or the process failed. defer state.Unlock() state.locked = false @@ -437,16 +517,17 @@ func (m *Manager) certState(domain string) (*certState, error) { return state, nil } -// authorizedCert starts domain ownership verification process and requests a new cert upon success. +// authorizedCert starts the domain ownership verification process and requests a new cert upon success. // The key argument is the certificate private key. func (m *Manager) authorizedCert(ctx context.Context, key crypto.Signer, domain string) (der [][]byte, leaf *x509.Certificate, err error) { - if err := m.verify(ctx, domain); err != nil { - return nil, nil, err - } client, err := m.acmeClient(ctx) if err != nil { return nil, nil, err } + + if err := m.verify(ctx, client, domain); err != nil { + return nil, nil, err + } csr, err := certRequest(key, domain) if err != nil { return nil, nil, err @@ -462,98 +543,171 @@ func (m *Manager) authorizedCert(ctx context.Context, key crypto.Signer, domain return der, leaf, nil } -// verify starts a new identifier (domain) authorization flow. -// It prepares a challenge response and then blocks until the authorization -// is marked as "completed" by the CA (either succeeded or failed). -// -// verify returns nil iff the verification was successful. -func (m *Manager) verify(ctx context.Context, domain string) error { - client, err := m.acmeClient(ctx) - if err != nil { - return err - } - - // start domain authorization and get the challenge - authz, err := client.Authorize(ctx, domain) - if err != nil { - return err - } - // maybe don't need to at all - if authz.Status == acme.StatusValid { - return nil - } +// verify runs the identifier (domain) authorization flow +// using each applicable ACME challenge type. +func (m *Manager) verify(ctx context.Context, client *acme.Client, domain string) error { + // The list of challenge types we'll try to fulfill + // in this specific order. + challengeTypes := []string{"tls-sni-02", "tls-sni-01"} + m.tokensMu.RLock() + if m.tryHTTP01 { + challengeTypes = append(challengeTypes, "http-01") + } + m.tokensMu.RUnlock() + + var nextTyp int // challengeType index of the next challenge type to try + for { + // Start domain authorization and get the challenge. + authz, err := client.Authorize(ctx, domain) + if err != nil { + return err + } + // No point in accepting challenges if the authorization status + // is in a final state. + switch authz.Status { + case acme.StatusValid: + return nil // already authorized + case acme.StatusInvalid: + return fmt.Errorf("acme/autocert: invalid authorization %q", authz.URI) + } - // pick a challenge: prefer tls-sni-02 over tls-sni-01 - // TODO: consider authz.Combinations - var chal *acme.Challenge - for _, c := range authz.Challenges { - if c.Type == "tls-sni-02" { - chal = c - break + // Pick the next preferred challenge. + var chal *acme.Challenge + for chal == nil && nextTyp < len(challengeTypes) { + chal = pickChallenge(challengeTypes[nextTyp], authz.Challenges) + nextTyp++ } - if c.Type == "tls-sni-01" { - chal = c + if chal == nil { + return fmt.Errorf("acme/autocert: unable to authorize %q; tried %q", domain, challengeTypes) + } + cleanup, err := m.fulfill(ctx, client, chal) + if err != nil { + continue + } + defer cleanup() + if _, err := client.Accept(ctx, chal); err != nil { + continue + } + + // A challenge is fulfilled and accepted: wait for the CA to validate. + if _, err := client.WaitAuthorization(ctx, authz.URI); err == nil { + return nil } } - if chal == nil { - return errors.New("acme/autocert: no supported challenge type found") - } +} - // create a token cert for the challenge response - var ( - cert tls.Certificate - name string - ) +// fulfill provisions a response to the challenge chal. +// The cleanup is non-nil only if provisioning succeeded. +func (m *Manager) fulfill(ctx context.Context, client *acme.Client, chal *acme.Challenge) (cleanup func(), err error) { switch chal.Type { case "tls-sni-01": - cert, name, err = client.TLSSNI01ChallengeCert(chal.Token) + cert, name, err := client.TLSSNI01ChallengeCert(chal.Token) + if err != nil { + return nil, err + } + m.putCertToken(ctx, name, &cert) + return func() { go m.deleteCertToken(name) }, nil case "tls-sni-02": - cert, name, err = client.TLSSNI02ChallengeCert(chal.Token) - default: - err = fmt.Errorf("acme/autocert: unknown challenge type %q", chal.Type) - } - if err != nil { - return err + cert, name, err := client.TLSSNI02ChallengeCert(chal.Token) + if err != nil { + return nil, err + } + m.putCertToken(ctx, name, &cert) + return func() { go m.deleteCertToken(name) }, nil + case "http-01": + resp, err := client.HTTP01ChallengeResponse(chal.Token) + if err != nil { + return nil, err + } + p := client.HTTP01ChallengePath(chal.Token) + m.putHTTPToken(ctx, p, resp) + return func() { go m.deleteHTTPToken(p) }, nil } - m.putTokenCert(ctx, name, &cert) - defer func() { - // verification has ended at this point - // don't need token cert anymore - go m.deleteTokenCert(name) - }() + return nil, fmt.Errorf("acme/autocert: unknown challenge type %q", chal.Type) +} - // ready to fulfill the challenge - if _, err := client.Accept(ctx, chal); err != nil { - return err +func pickChallenge(typ string, chal []*acme.Challenge) *acme.Challenge { + for _, c := range chal { + if c.Type == typ { + return c + } } - // wait for the CA to validate - _, err = client.WaitAuthorization(ctx, authz.URI) - return err + return nil } -// putTokenCert stores the cert under the named key in both m.tokenCert map +// putCertToken stores the cert under the named key in both m.certTokens map // and m.Cache. -func (m *Manager) putTokenCert(ctx context.Context, name string, cert *tls.Certificate) { - m.tokenCertMu.Lock() - defer m.tokenCertMu.Unlock() - if m.tokenCert == nil { - m.tokenCert = make(map[string]*tls.Certificate) +func (m *Manager) putCertToken(ctx context.Context, name string, cert *tls.Certificate) { + m.tokensMu.Lock() + defer m.tokensMu.Unlock() + if m.certTokens == nil { + m.certTokens = make(map[string]*tls.Certificate) } - m.tokenCert[name] = cert + m.certTokens[name] = cert m.cachePut(ctx, name, cert) } -// deleteTokenCert removes the token certificate for the specified domain name -// from both m.tokenCert map and m.Cache. -func (m *Manager) deleteTokenCert(name string) { - m.tokenCertMu.Lock() - defer m.tokenCertMu.Unlock() - delete(m.tokenCert, name) +// deleteCertToken removes the token certificate for the specified domain name +// from both m.certTokens map and m.Cache. +func (m *Manager) deleteCertToken(name string) { + m.tokensMu.Lock() + defer m.tokensMu.Unlock() + delete(m.certTokens, name) if m.Cache != nil { m.Cache.Delete(context.Background(), name) } } +// httpToken retrieves an existing http-01 token value from an in-memory map +// or the optional cache. +func (m *Manager) httpToken(ctx context.Context, tokenPath string) ([]byte, error) { + m.tokensMu.RLock() + defer m.tokensMu.RUnlock() + if v, ok := m.httpTokens[tokenPath]; ok { + return v, nil + } + if m.Cache == nil { + return nil, fmt.Errorf("acme/autocert: no token at %q", tokenPath) + } + return m.Cache.Get(ctx, httpTokenCacheKey(tokenPath)) +} + +// putHTTPToken stores an http-01 token value using tokenPath as key +// in both in-memory map and the optional Cache. +// +// It ignores any error returned from Cache.Put. +func (m *Manager) putHTTPToken(ctx context.Context, tokenPath, val string) { + m.tokensMu.Lock() + defer m.tokensMu.Unlock() + if m.httpTokens == nil { + m.httpTokens = make(map[string][]byte) + } + b := []byte(val) + m.httpTokens[tokenPath] = b + if m.Cache != nil { + m.Cache.Put(ctx, httpTokenCacheKey(tokenPath), b) + } +} + +// deleteHTTPToken removes an http-01 token value from both in-memory map +// and the optional Cache, ignoring any error returned from the latter. +// +// If m.Cache is non-nil, it blocks until Cache.Delete returns without a timeout. +func (m *Manager) deleteHTTPToken(tokenPath string) { + m.tokensMu.Lock() + defer m.tokensMu.Unlock() + delete(m.httpTokens, tokenPath) + if m.Cache != nil { + m.Cache.Delete(context.Background(), httpTokenCacheKey(tokenPath)) + } +} + +// httpTokenCacheKey returns a key at which an http-01 token value may be stored +// in the Manager's optional Cache. +func httpTokenCacheKey(tokenPath string) string { + return "http-01-" + path.Base(tokenPath) +} + // renew starts a cert renewal timer loop, one per domain. // // The loop is scheduled in two cases: diff --git a/vendor/golang.org/x/crypto/acme/types.go b/vendor/golang.org/x/crypto/acme/types.go index ab4de0b880..3e199749ec 100644 --- a/vendor/golang.org/x/crypto/acme/types.go +++ b/vendor/golang.org/x/crypto/acme/types.go @@ -5,6 +5,8 @@ package acme import ( + "crypto" + "crypto/x509" "errors" "fmt" "net/http" @@ -293,3 +295,35 @@ func (e *wireError) error(h http.Header) *Error { Header: h, } } + +// CertOption is an optional argument type for the TLSSNIxChallengeCert methods for +// customizing a temporary certificate for TLS-SNI challenges. +type CertOption interface { + privateCertOpt() +} + +// WithKey creates an option holding a private/public key pair. +// The private part signs a certificate, and the public part represents the signee. +func WithKey(key crypto.Signer) CertOption { + return &certOptKey{key} +} + +type certOptKey struct { + key crypto.Signer +} + +func (*certOptKey) privateCertOpt() {} + +// WithTemplate creates an option for specifying a certificate template. +// See x509.CreateCertificate for template usage details. +// +// In TLSSNIxChallengeCert methods, the template is also used as parent, +// resulting in a self-signed certificate. +// The DNSNames field of t is always overwritten for tls-sni challenge certs. +func WithTemplate(t *x509.Certificate) CertOption { + return (*certOptTemplate)(t) +} + +type certOptTemplate x509.Certificate + +func (*certOptTemplate) privateCertOpt() {} diff --git a/vendor/vendor.json b/vendor/vendor.json index 3cf7bd4c55..e45986fa17 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -193,82 +193,82 @@ "revisionTime": "2017-03-05T07:05:34Z" }, { - "checksumSHA1": "W3AuK8ocqHwlUajGmQLFvnRhTZE=", + "checksumSHA1": "ZHIN9ZvSnpB6xJZrlRPiuSU5I+Y=", "path": "github.com/cncd/pipeline/pipeline", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "gc+efbEPGdecp6I2ezd6J3+UL3o=", + "checksumSHA1": "fVN8cdG7KyWMge1UL3UzC0IZ8T4=", "path": "github.com/cncd/pipeline/pipeline/backend", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "IIuOItGMhYP6kLtlZWYBO+liSx4=", + "checksumSHA1": "W8YLHobCsauDN8mHNGv0kdDsNzM=", "path": "github.com/cncd/pipeline/pipeline/backend/docker", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "2A3+CnkMfvvO4oRkjQKqi44no0g=", + "checksumSHA1": "HWV2BBLXS4gY5eLJeNIg7Z6nAOA=", "path": "github.com/cncd/pipeline/pipeline/frontend", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "VZEf4sUe0jVi3TPXE+gfjpKtXFA=", + "checksumSHA1": "ncGH2MfHDtM7/dNzj2i+lnXFnf4=", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "Bso8L5AC/YA4k+YVfIg+m2bMLmU=", + "checksumSHA1": "cdjOSSSS5Gzx7gRLNvObQvNJWYg=", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/compiler", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "tExCYtVZoTnfEkEQL7r/megor8I=", + "checksumSHA1": "Sj2VYU+asWToYriIqcinav5MJZo=", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/linter", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { "checksumSHA1": "kx2sPUIMozPC/g6E4w48h3FfH3k=", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/matrix", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { "checksumSHA1": "L7Q5qJmPITNmvFEEaj5MPwCWFRk=", "path": "github.com/cncd/pipeline/pipeline/frontend/yaml/types", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { "checksumSHA1": "2/3f3oNmxXy5kcrRLCFa24Oc9O4=", "path": "github.com/cncd/pipeline/pipeline/interrupt", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { "checksumSHA1": "uOjTfke7Qxosrivgz/nVTHeIP5g=", "path": "github.com/cncd/pipeline/pipeline/multipart", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "pyaqbQRdFkOGTE0mSNou27ikvfs=", + "checksumSHA1": "mfWlnRAr5B4+RL13W3s0BQVBofM=", "path": "github.com/cncd/pipeline/pipeline/rpc", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { - "checksumSHA1": "huYd+DhpBP/0kHMAC0mPZAZBmnw=", + "checksumSHA1": "N+3wNQ8hc/6yrh3FxbaxkEVwrkY=", "path": "github.com/cncd/pipeline/pipeline/rpc/proto", - "revision": "b7427ae1fb86bb04e2997e5f3a1eec75c4b056ef", - "revisionTime": "2017-09-14T17:45:32Z" + "revision": "20fb2f4efd792fc8dafc53aec766c2edcfdf0bb0", + "revisionTime": "2018-04-01T18:32:51Z" }, { "checksumSHA1": "7Qj1DK0ceAXkYztW0l3+L6sn+V8=", @@ -1007,16 +1007,16 @@ "revisionTime": "2016-11-19T21:37:11Z" }, { - "checksumSHA1": "Ag672Laei0E45NrvTO4LV9B3Jfc=", + "checksumSHA1": "CSMVjFF7FnylAUUKW1e/4r+VFXA=", "path": "golang.org/x/crypto/acme", - "revision": "c7af5bf2638a1164f2eb5467c39c6cffbd13a02e", - "revisionTime": "2017-04-25T18:31:00Z" + "revision": "13931e22f9e72ea58bb73048bc752b48c6d4d4ac", + "revisionTime": "2018-01-11T11:10:38Z" }, { - "checksumSHA1": "TrKJW+flz7JulXU3sqnBJjGzgQc=", + "checksumSHA1": "lBWiVnI+9tnYWuXnUiWljDy9dnc=", "path": "golang.org/x/crypto/acme/autocert", - "revision": "c7af5bf2638a1164f2eb5467c39c6cffbd13a02e", - "revisionTime": "2017-04-25T18:31:00Z" + "revision": "13931e22f9e72ea58bb73048bc752b48c6d4d4ac", + "revisionTime": "2018-01-11T11:10:38Z" }, { "checksumSHA1": "MlEHIE/60sB86Lmf0MPTIXHzKzE=", diff --git a/version/version.go b/version/version.go index d5a2ef11b3..f30bd06aec 100644 --- a/version/version.go +++ b/version/version.go @@ -1,3 +1,17 @@ +// Copyright 2018 Drone.IO Inc. +// +// 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 version import "github.com/coreos/go-semver/semver" @@ -8,7 +22,7 @@ var ( // VersionMinor is for functionality in a backwards-compatible manner. VersionMinor int64 = 8 // VersionPatch is for backwards-compatible bug fixes. - VersionPatch int64 = 2 + VersionPatch int64 = 6 // VersionPre indicates prerelease. VersionPre string // VersionDev indicates development branch. Releases will be empty string.