├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── bin └── atlantis └── src └── atlantis ├── common ├── atlantis.go ├── atlantis_test.go ├── random.go ├── rpc.go └── task.go ├── crypto ├── crypto.go └── crypto_test.go └── types └── types.go /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | src/atlantis/crypto/key.go 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Ooyala Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ## Copyright 2014 Ooyala, Inc. All rights reserved. 2 | ## 3 | ## This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | ## except in compliance with the License. You may obtain a copy of the License at 5 | ## http://www.apache.org/licenses/LICENSE-2.0 6 | ## 7 | ## Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | ## distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | ## See the License for the specific language governing permissions and limitations under the License. 10 | 11 | PROJECT_ROOT := $(shell pwd) 12 | PROJECT_NAME := $(shell pwd | sed 's/.*\///g') 13 | VENDOR_PATH := $(PROJECT_ROOT)/vendor 14 | GOPATH := $(PROJECT_ROOT):$(VENDOR_PATH) 15 | 16 | all: test fmt 17 | 18 | fmt: 19 | @find . -name \*.go -exec gofmt -l -w {} \; 20 | 21 | clean: 22 | @rm -rf bin pkg $(PROJECT_ROOT)/src/atlantis/crypto/key.go 23 | 24 | copy-key: 25 | @cp $(ATLANTIS_SECRET_DIR)/atlantis_key.go $(PROJECT_ROOT)/src/atlantis/crypto/key.go 26 | 27 | install-deps: 28 | @echo "Installing Dependencies..." 29 | @rm -rf $(VENDOR_PATH) 30 | @mkdir -p $(VENDOR_PATH) || exit 2 31 | @GOPATH=$(VENDOR_PATH) go get launchpad.net/gocheck 32 | @echo "Dependencies Installed." 33 | 34 | test: clean copy-key 35 | @GOPATH=$(GOPATH) go test atlantis/common -gocheck.vv=true -test.v=true 36 | @GOPATH=$(GOPATH) go test atlantis/crypto -gocheck.vv=true -test.v=true 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Atlantis 2 | ======== 3 | 4 | Atlantis is an Open Source PaaS for HTTP applications built on Docker and written in Go. It makes it easy to build and deploy applications in a safe, repeatable fashion, and flexibly route requests to the appropriate containers. 5 | 6 | We're using Atlantis heavily at Ooyala for new applications; while it still has some rough edges around getting it up and running, the experience of using it for deploying applications is fairly smooth. 7 | 8 | For an introduction or more information on how to use Atlantis, see [A User's Guide to Getting Started With Atlantis](http://ooyala.github.io/atlantis/user-getting-started.html). For more technical details on the project, continue reading here. 9 | 10 | 11 | This Repository 12 | --------------- 13 | 14 | This repository is shared across all components; it contains shared datatypes and utility functions. It is included as a submodule in the other components to make these available without code duplication. (At the time we started Atlantis, Go package managers were generally fairly immature; it might make sense to switch to one of those, but for the moment, submodules work.) 15 | 16 | 17 | Architecture 18 | ------------ 19 | 20 | Atlantis consists of multiple components, each with their own repository: 21 | 22 | \[insert Cad's image here\] 23 | 24 | Each component is briefly discussed below, and detailed in more information in its project repository. 25 | 26 | - The [manager](https://github.com/ooyala/atlantis-manager), as its name suggests, manages the whole system. It is the primary interaction point with Atlantis: it coallates information from the various sources and provides APIs to interact with them. In the near future, some of this functionality will be moved into the components, but the manager will still be the center of a full Atlantis cluster. 27 | 28 | - The [supervisors](https://github.com/ooyala/atlantis-supervisor) run the deployed applications in Docker containers. They also handle network security; we use iptables to provide a level of isolation similar to EC2 security groups. If a container doesn't request permissions to a known service, that service is blocked from within that container. 29 | 30 | - The [routers](https://github.com/ooyala/atlantis-router) handle routing of HTTP requests based on flexible rules read out of Zookeeper. 31 | 32 | - The [builder](https://github.com/ooyala/atlantis-builder) builds containers from known templates based on a simple configuration file, and pushes the images to the registry for deployment to the supervisors. 33 | 34 | - The [registry](https://github.com/ooyala/go-docker-registry/) is a Go reimplentation of (most of) the [original Docker registry](https://github.com/docker/docker-registry). We had some issues with the Python implementation that resulted in us building our own. This will likely be deprecated in favor of the [Registry 2.0](https://github.com/docker/distribution) once it's fully stable. 35 | 36 | In addition, we depend on the following pre-existing services: 37 | 38 | - [Zookeeper](https://zookeeper.apache.org/) is used to store configuration data and ensure that updates propagate immediately. 39 | 40 | - [Jenkins](https://jenkins-ci.org/) is used to manage building Docker containers for the applications. We also have a minimal standalone build server for testing, but it doesn't provide niceties like logging or auditing. 41 | 42 | - [LDAP](http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol) is optionally used to manage ownership of applications. Teams of multiple users can be assigned applications, and only users in that team will be able to affect those applications. Teams can be managed through the Atlantis manager or with any other LDAP interface. 43 | 44 | 45 | Aquarium 46 | -------- 47 | Since running all of these pieces in development can be a pain, we've developed [aquarium](https://github.com/ooyala/atlantis-aquarium), a script to make it easy to run Atlantis within a Vagrant instance. Following the directions in its Readme, you should be able to get a full Atlantis cluster up for development in minutes (though downloading the various images and dependences can take some time depending on your connection speed.) 48 | 49 | 50 | Regions and zones 51 | ----------------- 52 | 53 | One of Ooyala's core engineering principles is avoiding a single point of failure by using [multiple regions in EC2](http://engineering.ooyala.com/blog/staying-when-amazon-web-services-isn%E2%80%99t). Atlantis supports this model by running multiple independent clusters in different region. Each has its copy of every component except for the builder; the builder is only in one region, to ensure consistency, and the actual images are pushed to S3, so are available from all regions. 54 | 55 | For finer-grained redundancy, Atlantis also supports [availability zones](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html). The manager knows what zones are available to it, and each supervisor is configured with its zone. When an application is deployed, it is deployed among all availability zones; this ensures that an issue limited to a single availability zone issue will not take out an application. 56 | 57 | Routers should similarly be split among availability zones to ensure uptime. 58 | -------------------------------------------------------------------------------- /bin/atlantis: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # check if subcommand exists in path 4 | hash atlantis-${1} >/dev/null 2>&1 5 | if [ $? -eq 0 ]; then 6 | # if it exists, use subcommand and chop first arg 7 | atlantis-${1} ${@:2} 8 | else 9 | # else default to manager 10 | atlantis-manager $@ 11 | fi 12 | -------------------------------------------------------------------------------- /src/atlantis/common/atlantis.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package common 13 | 14 | // ---------------------------------------------------------------------------------------------------------- 15 | // Atlantis Common Types 16 | // ---------------------------------------------------------------------------------------------------------- 17 | 18 | const ( 19 | StatusOk = "OK" 20 | StatusMaintenance = "MAINTENANCE" 21 | StatusError = "ERROR" 22 | StatusDegraded = "DEGRADED" 23 | StatusUnknown = "UNKNOWN" 24 | StatusDone = "DONE" 25 | StatusInit = "INIT" 26 | StatusFull = "FULL" // Supervisor Health Check status when no more containers are available 27 | ManifestFile = "manifest.toml" 28 | DefaultLDAPPort = uint16(636) 29 | DefaultRegion = "dev" 30 | DefaultZone = "dev" 31 | ) 32 | 33 | // ------------ Version ----------- 34 | // used to check manager or supervisor version 35 | type VersionArg struct { 36 | } 37 | 38 | type VersionReply struct { 39 | RPCVersion string 40 | APIVersion string 41 | } 42 | 43 | // ------------ Async ----------- 44 | // used to for async requests 45 | type AsyncReply struct { 46 | ID string 47 | } 48 | 49 | // ---------------------------------------------------------------------------------------------------------- 50 | // Utility Functions 51 | // ---------------------------------------------------------------------------------------------------------- 52 | 53 | func DiffSlices(s1, s2 []string) (onlyInS1, onlyInS2 []string) { 54 | onlyInS1 = []string{} 55 | onlyInS2 = []string{} 56 | if s1 == nil && s2 == nil { 57 | return 58 | } else if s1 == nil { 59 | return onlyInS1, s2 60 | } else if s2 == nil { 61 | return s1, onlyInS2 62 | } 63 | counts := map[string]int{} 64 | for _, s1str := range s1 { 65 | counts[s1str]++ 66 | } 67 | for _, s2str := range s2 { 68 | if count, present := counts[s2str]; !present || count == 0 { 69 | onlyInS2 = append(onlyInS2, s2str) 70 | } else { 71 | counts[s2str]-- 72 | } 73 | } 74 | for s1str, count := range counts { 75 | for i := count; i > 0; i-- { 76 | onlyInS1 = append(onlyInS1, s1str) 77 | } 78 | } 79 | return 80 | } 81 | -------------------------------------------------------------------------------- /src/atlantis/common/atlantis_test.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package common 13 | 14 | import ( 15 | "launchpad.net/gocheck" 16 | "testing" 17 | ) 18 | 19 | func TestAtlantis(t *testing.T) { gocheck.TestingT(t) } 20 | 21 | type AtlantisSuite struct{} 22 | 23 | var _ = gocheck.Suite(&AtlantisSuite{}) 24 | 25 | func (s *AtlantisSuite) TestDiffSlices(c *gocheck.C) { 26 | var s1, s2, onlyInS1, onlyInS2 []string 27 | s1 = nil 28 | s2 = nil 29 | onlyInS1, onlyInS2 = DiffSlices(s1, s2) 30 | c.Check(onlyInS1, gocheck.DeepEquals, []string{}) 31 | c.Check(onlyInS2, gocheck.DeepEquals, []string{}) 32 | s1 = []string{} 33 | onlyInS1, onlyInS2 = DiffSlices(s1, s2) 34 | c.Check(onlyInS1, gocheck.DeepEquals, []string{}) 35 | c.Check(onlyInS2, gocheck.DeepEquals, []string{}) 36 | s2 = []string{} 37 | onlyInS1, onlyInS2 = DiffSlices(s1, s2) 38 | c.Check(onlyInS1, gocheck.DeepEquals, []string{}) 39 | c.Check(onlyInS2, gocheck.DeepEquals, []string{}) 40 | s1 = []string{"a", "b"} 41 | s2 = []string{} 42 | onlyInS1, onlyInS2 = DiffSlices(s1, s2) 43 | c.Check(onlyInS1, gocheck.DeepEquals, []string{"a", "b"}) 44 | c.Check(onlyInS2, gocheck.DeepEquals, []string{}) 45 | s1 = []string{"a", "b"} 46 | s2 = []string{"b", "c"} 47 | onlyInS1, onlyInS2 = DiffSlices(s1, s2) 48 | c.Check(onlyInS1, gocheck.DeepEquals, []string{"a"}) 49 | c.Check(onlyInS2, gocheck.DeepEquals, []string{"c"}) 50 | s1 = []string{"a", "b", "b", "b"} 51 | s2 = []string{"b", "c"} 52 | onlyInS1, onlyInS2 = DiffSlices(s1, s2) 53 | c.Check(onlyInS1, gocheck.DeepEquals, []string{"a", "b", "b"}) 54 | c.Check(onlyInS2, gocheck.DeepEquals, []string{"c"}) 55 | } 56 | -------------------------------------------------------------------------------- /src/atlantis/common/random.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package common 13 | 14 | import ( 15 | "crypto/rand" 16 | "io" 17 | ) 18 | 19 | var randomChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") 20 | 21 | // NOTE[jigish]: yes, i know this has modulo bias. i don't care. we don't need a truly random string, just 22 | // one that won't collide often. 23 | func CreateRandomID(size int) string { 24 | randomBytes := make([]byte, size) 25 | randomCharsLen := byte(len(randomChars)) 26 | // ignore error here because manas said so. randomBytes is static so if there was an error here we'd be 27 | // completely screwed anyways. 28 | io.ReadFull(rand.Reader, randomBytes) 29 | for i, b := range randomBytes { 30 | randomBytes[i] = randomChars[b%randomCharsLen] 31 | } 32 | return string(randomBytes) 33 | } 34 | -------------------------------------------------------------------------------- /src/atlantis/common/rpc.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package common 13 | 14 | import ( 15 | "crypto/tls" 16 | "errors" 17 | "fmt" 18 | "net/rpc" 19 | "strings" 20 | "time" 21 | ) 22 | 23 | // Returns false if the two major versions mismatch 24 | func CompatibleVersions(v1, v2 string) bool { 25 | major1 := strings.SplitN(v1, ".", 2) 26 | major2 := strings.SplitN(v2, ".", 2) 27 | return major1[0] == major2[0] 28 | } 29 | 30 | type RPCServerOpts interface { 31 | RPCHostAndPort() string 32 | } 33 | 34 | type BasicRPCServerOpts string 35 | 36 | func (o BasicRPCServerOpts) RPCHostAndPort() string { 37 | return string(o) 38 | } 39 | 40 | type RPCClient struct { 41 | BaseName string 42 | RPCVersion string 43 | Opts []RPCServerOpts 44 | UseTLS bool 45 | VersionError error 46 | VersionOk bool 47 | } 48 | 49 | type ClientResult struct { 50 | client *rpc.Client 51 | err error 52 | } 53 | 54 | func NewRPCClient(hostAndPort, baseName, rpcVersion string, useTLS bool) *RPCClient { 55 | return NewRPCClientWithConfig(BasicRPCServerOpts(hostAndPort), baseName, rpcVersion, useTLS) 56 | } 57 | 58 | func NewRPCClientWithConfig(config RPCServerOpts, baseName, rpcVersion string, useTLS bool) *RPCClient { 59 | configs := []RPCServerOpts{config} 60 | return &RPCClient{baseName, rpcVersion, configs, useTLS, nil, false} 61 | } 62 | 63 | func NewMultiRPCClientWithConfig(configs []RPCServerOpts, baseName, rpcVersion string, useTLS bool) *RPCClient { 64 | return &RPCClient{baseName, rpcVersion, configs, useTLS, nil, false} 65 | } 66 | 67 | func (r *RPCClient) newClient(region int) (*rpc.Client, error) { 68 | if r.UseTLS { 69 | return r.newTLSClient(region) 70 | } 71 | return rpc.DialHTTP("tcp", r.Opts[region].RPCHostAndPort()) 72 | } 73 | 74 | func (r *RPCClient) newClientOnChannel(region int) chan *ClientResult { 75 | c := make(chan *ClientResult) 76 | go func() { 77 | if r.UseTLS { 78 | client, err := r.newTLSClient(region) 79 | c <- &ClientResult{client: client, err: err} 80 | } else { 81 | client, err := rpc.DialHTTP("tcp", r.Opts[region].RPCHostAndPort()) 82 | c <- &ClientResult{client: client, err: err} 83 | } 84 | }() 85 | return c 86 | } 87 | 88 | func (r *RPCClient) tlsConfig() (*tls.Config, error) { 89 | var err error 90 | config := &tls.Config{} 91 | config.InsecureSkipVerify = true 92 | return config, err 93 | } 94 | 95 | func (r *RPCClient) newTLSClient(region int) (*rpc.Client, error) { 96 | config, err := r.tlsConfig() 97 | if err != nil { 98 | panic(err) 99 | } 100 | conn, err := tls.Dial("tcp", r.Opts[region].RPCHostAndPort(), config) 101 | if err != nil { 102 | panic(err) 103 | } 104 | c := rpc.NewClient(conn) 105 | return c, err 106 | } 107 | 108 | func (r *RPCClient) checkVersion(region int) error { 109 | if r.VersionOk { 110 | return nil 111 | } 112 | arg := VersionArg{} 113 | var reply VersionReply 114 | err := r.doRequest("Version", arg, region, &reply) 115 | if err != nil { 116 | r.VersionError = err 117 | r.VersionOk = false 118 | return err 119 | } 120 | if !CompatibleVersions(reply.RPCVersion, r.RPCVersion) { 121 | err := errors.New("Version Mismatch. Server: " + reply.RPCVersion + ", Client: " + r.RPCVersion) 122 | r.VersionError = err 123 | r.VersionOk = false 124 | return err 125 | } 126 | r.VersionOk = true 127 | return nil 128 | } 129 | 130 | func (r *RPCClient) checkVersionWithTimeout(region int, timeout int) error { 131 | if r.VersionOk { 132 | return nil 133 | } 134 | arg := VersionArg{} 135 | var reply VersionReply 136 | err := r.doRequestWithTimeout("Version", arg, region, &reply, timeout) 137 | if err != nil { 138 | r.VersionError = err 139 | r.VersionOk = false 140 | return err 141 | } 142 | if !CompatibleVersions(reply.RPCVersion, r.RPCVersion) { 143 | err := errors.New("Version Mismatch. Server: " + reply.RPCVersion + ", Client: " + r.RPCVersion) 144 | r.VersionError = err 145 | r.VersionOk = false 146 | return err 147 | } 148 | r.VersionOk = true 149 | return nil 150 | } 151 | 152 | func (r *RPCClient) doRequest(name string, arg interface{}, region int, reply interface{}) error { 153 | client, err := r.newClient(region) 154 | if err != nil { 155 | return err 156 | } 157 | defer client.Close() 158 | return client.Call(r.BaseName+"."+name, arg, reply) 159 | } 160 | 161 | func (r *RPCClient) doRequestWithTimeout(name string, arg interface{}, region int, reply interface{}, timeout int) error { 162 | clientChan := r.newClientOnChannel(region) 163 | callChan := make(chan *rpc.Call, 1) 164 | for { 165 | select { 166 | case c := <-clientChan: 167 | if c.err != nil { 168 | return c.err 169 | } 170 | defer c.client.Close() 171 | c.client.Go(r.BaseName+"."+name, arg, reply, callChan) 172 | case c := <-callChan: 173 | return c.Error 174 | case <-time.After(time.Duration(timeout) * time.Second): 175 | return errors.New(fmt.Sprintf("Client timed out - no response within %d seconds.", timeout)) 176 | } 177 | } 178 | } 179 | 180 | func (r *RPCClient) Call(name string, arg interface{}, reply interface{}) error { 181 | return r.CallMulti(name, arg, 0, reply) 182 | } 183 | 184 | func (r *RPCClient) CallMulti(name string, arg interface{}, region int, reply interface{}) error { 185 | if err := r.checkVersion(region); err != nil { 186 | return err 187 | } 188 | return r.doRequest(name, arg, region, reply) 189 | } 190 | 191 | func (r *RPCClient) CallWithTimeout(name string, arg interface{}, reply interface{}, timeout int) error { 192 | return r.CallMultiWithTimeout(name, arg, 0, reply, timeout) 193 | } 194 | 195 | func (r *RPCClient) CallMultiWithTimeout(name string, arg interface{}, region int, reply interface{}, timeout int) error { 196 | if err := r.checkVersionWithTimeout(region, timeout); err != nil { 197 | return err 198 | } 199 | return r.doRequestWithTimeout(name, arg, region, reply, timeout) 200 | } 201 | -------------------------------------------------------------------------------- /src/atlantis/common/task.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package common 13 | 14 | import ( 15 | "errors" 16 | "fmt" 17 | "log" 18 | "os" 19 | "sync" 20 | "time" 21 | ) 22 | 23 | const taskIDSize = 20 24 | 25 | var ( 26 | Tracker = &TaskTracker{tasks: map[string]*Task{}} 27 | TaskStatusUnknown = &TaskStatus{Status: StatusUnknown} 28 | ) 29 | 30 | func MaintenanceChecker(file string, interval time.Duration) { 31 | go Tracker.MaintenanceChecker(file, interval) 32 | } 33 | 34 | func NewTask(name string, executor TaskExecutor) *Task { 35 | task := &Task{Tracker: Tracker, Executor: executor} 36 | task.Status = StatusInit 37 | task.StatusTime = time.Now() 38 | task.Name = name 39 | task.Description = executor.Description() 40 | task.Request = executor.Request() 41 | return task 42 | } 43 | 44 | type TaskTracker struct { 45 | sync.RWMutex 46 | ResultDuration time.Duration 47 | Maintenance bool 48 | tasks map[string]*Task 49 | } 50 | 51 | type Task struct { 52 | sync.RWMutex 53 | TaskStatus 54 | Err error 55 | Tracker *TaskTracker 56 | ID string 57 | Executor TaskExecutor 58 | Request interface{} 59 | Result interface{} 60 | } 61 | 62 | type TaskExecutor interface { 63 | Request() interface{} 64 | Result() interface{} 65 | Description() string 66 | Execute(t *Task) error 67 | Authorize() error 68 | } 69 | 70 | type TaskMaintenanceExecutor interface { 71 | AllowDuringMaintenance() bool 72 | } 73 | 74 | func createTaskID() string { 75 | return CreateRandomID(taskIDSize) 76 | } 77 | 78 | func (t *TaskTracker) ListIDs(types []string) []string { 79 | typesMap := make(map[string]bool, len(types)) 80 | for _, typ := range types { 81 | typesMap[typ] = true 82 | } 83 | ids := []string{} 84 | t.Lock() 85 | for id, task := range t.tasks { 86 | if typesMap[task.Name] { 87 | ids = append(ids, id) 88 | } 89 | } 90 | t.Unlock() 91 | return ids 92 | } 93 | 94 | func (t *TaskTracker) SetMaintenance(on bool) { 95 | t.Lock() 96 | t.Maintenance = on 97 | t.Unlock() 98 | } 99 | 100 | func (t *TaskTracker) UnderMaintenance() bool { 101 | t.RLock() 102 | maint := t.Maintenance 103 | t.RUnlock() 104 | return maint 105 | } 106 | 107 | func (t *TaskTracker) MaintenanceChecker(file string, interval time.Duration) { 108 | for { 109 | if _, err := os.Stat(file); err == nil { 110 | // maintenance file exists 111 | if !t.UnderMaintenance() { 112 | log.Println("Begin Maintenance") 113 | t.SetMaintenance(true) 114 | } 115 | } else { 116 | // maintenance file doesn't exist or there is an error looking for it 117 | if t.UnderMaintenance() { 118 | log.Println("End Maintenance") 119 | t.SetMaintenance(false) 120 | } 121 | } 122 | time.Sleep(interval) 123 | } 124 | } 125 | 126 | func (t *TaskTracker) Idle(checkTask *Task) bool { 127 | idle := true 128 | t.RLock() 129 | for _, task := range t.tasks { 130 | if task != checkTask && !task.Done { 131 | idle = false 132 | break 133 | } 134 | } 135 | t.RUnlock() 136 | return idle 137 | } 138 | 139 | func (t *TaskTracker) ReserveTaskID(task *Task) string { 140 | t.Lock() 141 | requestID := createTaskID() 142 | for _, present := t.tasks[requestID]; present; _, present = t.tasks[requestID] { 143 | requestID = createTaskID() 144 | } 145 | t.tasks[requestID] = task // reserve request id 146 | t.Unlock() 147 | task.Lock() 148 | task.ID = requestID 149 | task.Unlock() 150 | return requestID 151 | } 152 | 153 | func (t *TaskTracker) ReleaseTaskID(id string) { 154 | t.Lock() 155 | delete(t.tasks, id) 156 | t.Unlock() 157 | } 158 | 159 | func (t *TaskTracker) Status(id string) (*TaskStatus, error) { 160 | t.RLock() 161 | task := t.tasks[id] 162 | t.RUnlock() 163 | if task != nil { 164 | task.RLock() 165 | status := task.CopyTaskStatus() 166 | err := task.Err 167 | task.RUnlock() 168 | return status, err 169 | } 170 | return TaskStatusUnknown, errors.New("Unknown Task Status") 171 | } 172 | 173 | func (t *TaskTracker) Result(id string) interface{} { 174 | t.RLock() 175 | task := t.tasks[id] 176 | t.RUnlock() 177 | if task != nil { 178 | task.RLock() 179 | result := task.Result 180 | task.RUnlock() 181 | return result 182 | } 183 | return nil 184 | } 185 | 186 | func (t *Task) Authorize() error { 187 | return t.Executor.Authorize() 188 | } 189 | 190 | func (t *Task) Run() error { 191 | if t.Tracker.UnderMaintenance() { 192 | executor, ok := t.Executor.(TaskMaintenanceExecutor) 193 | if !ok || !executor.AllowDuringMaintenance() { 194 | return t.End(errors.New("Under Maintenance"), false) 195 | } 196 | } 197 | t.Tracker.ReserveTaskID(t) 198 | t.Log("Begin %s", t.Description) 199 | t.Lock() 200 | t.StartTime = time.Now() 201 | t.Unlock() 202 | err := t.Executor.Authorize() 203 | if err != nil { 204 | return t.End(err, false) 205 | } 206 | return t.End(t.Executor.Execute(t), false) 207 | } 208 | 209 | func (t *Task) RunAsync(r *AsyncReply) error { 210 | if t.Tracker.UnderMaintenance() { 211 | executor, ok := t.Executor.(TaskMaintenanceExecutor) 212 | if !ok || !executor.AllowDuringMaintenance() { 213 | return t.End(errors.New("Under Maintenance"), false) 214 | } 215 | } 216 | t.Tracker.ReserveTaskID(t) 217 | t.RLock() 218 | r.ID = t.ID 219 | t.RUnlock() 220 | go func() error { 221 | t.Log("Begin %s", t.Description) 222 | t.Lock() 223 | t.StartTime = time.Now() 224 | t.Unlock() 225 | err := t.Executor.Authorize() 226 | if err != nil { 227 | return t.End(err, true) 228 | } 229 | t.End(t.Executor.Execute(t), true) 230 | return nil 231 | }() 232 | return nil 233 | } 234 | 235 | func (t *Task) End(err error, async bool) error { 236 | logString := fmt.Sprintf("End %s", t.Description) 237 | t.Lock() 238 | t.Result = t.Executor.Result() 239 | t.EndTime = time.Now() 240 | t.StatusTime = t.EndTime 241 | if err == nil { 242 | t.Status = StatusDone 243 | t.Done = true 244 | } else { 245 | t.Status = StatusError 246 | t.Err = err 247 | t.Done = true 248 | logString += fmt.Sprintf(" - Error: %s", err.Error()) 249 | } 250 | t.Unlock() 251 | t.Log(logString) 252 | if async { 253 | time.AfterFunc(t.Tracker.ResultDuration, func() { 254 | // keep result around for 30 min in case someone wants to check on it 255 | t.Tracker.ReleaseTaskID(t.ID) 256 | }) 257 | } else { 258 | t.Tracker.ReleaseTaskID(t.ID) 259 | } 260 | return err 261 | } 262 | 263 | func (t *Task) Log(format string, args ...interface{}) { 264 | t.RLock() 265 | log.Printf("[RPC]["+t.Name+"]["+t.ID+"] "+format, args...) 266 | t.RUnlock() 267 | } 268 | 269 | func (t *Task) LogStatus(format string, args ...interface{}) { 270 | t.Log(format, args...) 271 | t.Lock() 272 | t.StatusTime = time.Now() 273 | t.Status = fmt.Sprintf(format, args...) 274 | t.Unlock() 275 | } 276 | 277 | func (t *Task) AddWarning(warn string) { 278 | t.Lock() 279 | if t.Warnings == nil { 280 | t.Warnings = []string{warn} 281 | } else { 282 | t.Warnings = append(t.Warnings, warn) 283 | } 284 | t.Unlock() 285 | t.Log("WARNING: %s", warn) 286 | } 287 | 288 | type TaskStatus struct { 289 | Name string 290 | Description string 291 | Status string 292 | Warnings []string 293 | Done bool 294 | StartTime time.Time 295 | StatusTime time.Time 296 | EndTime time.Time 297 | } 298 | 299 | func (t *TaskStatus) Map() map[string]interface{} { 300 | return map[string]interface{}{ 301 | "Name": t.Name, 302 | "Description": t.Description, 303 | "Status": t.Status, 304 | "Warnings": t.Warnings, 305 | "Done": t.Done, 306 | "StartTime": t.StartTime, 307 | "StatusTime": t.StatusTime, 308 | "EndTime": t.EndTime, 309 | } 310 | } 311 | 312 | func (t *TaskStatus) String() string { 313 | return fmt.Sprintf(`%s 314 | Description : %s 315 | Status : %s 316 | Warnings : %v 317 | Done : %t 318 | StartTime : %s 319 | StatusTime : %s 320 | EndTime : %s`, t.Name, t.Description, t.Status, t.Warnings, t.Done, t.StartTime, t.StatusTime, 321 | t.EndTime) 322 | } 323 | 324 | func (t *TaskStatus) CopyTaskStatus() *TaskStatus { 325 | return &TaskStatus{t.Name, t.Description, t.Status, t.Warnings, t.Done, t.StartTime, t.StatusTime, 326 | t.EndTime} 327 | } 328 | -------------------------------------------------------------------------------- /src/atlantis/crypto/crypto.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package crypto 13 | 14 | import ( 15 | "crypto/aes" 16 | "crypto/cipher" 17 | "encoding/base64" 18 | ) 19 | 20 | var block cipher.Block 21 | 22 | func Init() error { 23 | var err error 24 | block, err = aes.NewCipher(AES_KEY) 25 | return err 26 | } 27 | 28 | func pad(data []byte) []byte { 29 | var size int 30 | if extra := len(data) % block.BlockSize(); extra > 0 { 31 | size = len(data) - extra + block.BlockSize() 32 | } else { 33 | size = len(data) 34 | } 35 | padded := make([]byte, size, size) 36 | for i, b := range data { 37 | padded[i] = b 38 | } 39 | return padded 40 | } 41 | 42 | func unpad(data []byte) []byte { 43 | unpadded := []byte{} 44 | for _, b := range data { 45 | if b == 0 { // assume that there are no 0 bytes inbetween the data 46 | return unpadded 47 | } 48 | unpadded = append(unpadded, b) 49 | } 50 | return unpadded 51 | } 52 | 53 | func chomp(data []byte) []byte { 54 | var size int 55 | if extra := len(data) % block.BlockSize(); extra > 0 { 56 | size = len(data) - extra 57 | } else { 58 | size = len(data) 59 | } 60 | chomped := make([]byte, size, size) 61 | for i, _ := range chomped { 62 | chomped[i] = data[i] 63 | } 64 | return chomped 65 | } 66 | 67 | func clone(data []byte) []byte { 68 | theClone := make([]byte, len(data)) 69 | for i, b := range data { 70 | theClone[i] = b 71 | } 72 | return theClone 73 | } 74 | 75 | func Encrypt(decrypted []byte) []byte { 76 | encrypter := cipher.NewCBCEncrypter(block, AES_IV) // encrypter 77 | toEncrypt := pad(decrypted) // clone and pad decrypted so we can mutate it 78 | encrypted := toEncrypt // maintain pointer to backing array because we're encrypting in place 79 | for len(toEncrypt) > 0 { // encrypt block by block 80 | encryptedPart := toEncrypt[0:block.BlockSize()] // fetch the block 81 | toEncrypt = toEncrypt[block.BlockSize():] // cut the block off toEncrypt 82 | encrypter.CryptBlocks(encryptedPart, encryptedPart) // encrypt the block 83 | } 84 | // B64 encode the shits 85 | b64ed := make([]byte, base64.StdEncoding.EncodedLen(len(encrypted))) 86 | base64.StdEncoding.Encode(b64ed, encrypted) 87 | return b64ed 88 | } 89 | 90 | func Decrypt(b64ed []byte) []byte { 91 | decrypter := cipher.NewCBCDecrypter(block, AES_IV) 92 | // B64 decode the shits 93 | toDecrypt := make([]byte, base64.StdEncoding.DecodedLen(len(b64ed))) 94 | base64.StdEncoding.Decode(toDecrypt, b64ed) 95 | toDecrypt = chomp(toDecrypt) // chomp extra bytes because base64 is stupid 96 | decrypted := toDecrypt 97 | for len(toDecrypt) > 0 { // decrypt block by block 98 | decryptedPart := toDecrypt[0:block.BlockSize()] 99 | toDecrypt = toDecrypt[block.BlockSize():] // cut the block off toDecrypt 100 | decrypter.CryptBlocks(decryptedPart, decryptedPart) // decrypt the block 101 | } 102 | return unpad(decrypted) // unpad and we're done 103 | } 104 | 105 | func EncryptString(decrypted string) string { 106 | return string(Encrypt([]byte(decrypted))) 107 | } 108 | 109 | func DecryptString(b64ed string) string { 110 | return string(Decrypt([]byte(b64ed))) 111 | } 112 | -------------------------------------------------------------------------------- /src/atlantis/crypto/crypto_test.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package crypto 13 | 14 | import ( 15 | "launchpad.net/gocheck" 16 | "testing" 17 | ) 18 | 19 | func TestCrypto(t *testing.T) { gocheck.TestingT(t) } 20 | 21 | type CryptoSuite struct{} 22 | 23 | var _ = gocheck.Suite(&CryptoSuite{}) 24 | 25 | func (s *CryptoSuite) TestBytes(c *gocheck.C) { 26 | c.Check(Init(), gocheck.IsNil) 27 | test := "a" // simple test 28 | c.Check(string(Decrypt(Encrypt([]byte(test)))), gocheck.Equals, test) 29 | test = "abcdabcdabcdabcd" // 16 byte test (block size) 30 | c.Check(string(Decrypt(Encrypt([]byte(test)))), gocheck.Equals, test) 31 | test = "abcdabcdabcdabcda" // 17 byte test (block size + 1) 32 | c.Check(string(Decrypt(Encrypt([]byte(test)))), gocheck.Equals, test) 33 | test = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./" // random character test 34 | c.Check(string(Decrypt(Encrypt([]byte(test)))), gocheck.Equals, test) 35 | test = "~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?" // more random characters 36 | c.Check(string(Decrypt(Encrypt([]byte(test)))), gocheck.Equals, test) 37 | // test long string 38 | test = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 39 | c.Check(string(Decrypt(Encrypt([]byte(test)))), gocheck.Equals, test) 40 | } 41 | 42 | func (s *CryptoSuite) TestString(c *gocheck.C) { 43 | c.Check(Init(), gocheck.IsNil) 44 | test := "a" // simple test 45 | c.Check(DecryptString(EncryptString(test)), gocheck.Equals, test) 46 | test = "abcdabcdabcdabcd" // 16 byte test (block size) 47 | c.Check(DecryptString(EncryptString(test)), gocheck.Equals, test) 48 | test = "abcdabcdabcdabcda" // 17 byte test (block size + 1) 49 | c.Check(DecryptString(EncryptString(test)), gocheck.Equals, test) 50 | test = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./" // random character test 51 | c.Check(DecryptString(EncryptString(test)), gocheck.Equals, test) 52 | test = "~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?" // more random characters 53 | c.Check(DecryptString(EncryptString(test)), gocheck.Equals, test) 54 | // test long string 55 | test = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 56 | c.Check(DecryptString(EncryptString(test)), gocheck.Equals, test) 57 | } 58 | -------------------------------------------------------------------------------- /src/atlantis/types/types.go: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Ooyala, Inc. All rights reserved. 2 | * 3 | * This file is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of the License at 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is 8 | * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * See the License for the specific language governing permissions and limitations under the License. 10 | */ 11 | 12 | package types 13 | 14 | import ( 15 | "encoding/json" 16 | "os" 17 | ) 18 | 19 | const ( 20 | ContainerConfigDir = "/etc/atlantis/config" 21 | ContainerConfigFile = "/etc/atlantis/config/config.json" 22 | ) 23 | 24 | type ContainerConfig struct { 25 | ID string `json:"id"` 26 | Host string `json:"host"` 27 | Env string `json:"env"` 28 | } 29 | 30 | type AppConfig struct { 31 | HTTPPort uint16 `json:"http_port"` 32 | SecondaryPorts []uint16 `json:"secondary_ports"` 33 | Container *ContainerConfig `json:"container"` 34 | Dependencies map[string]map[string]interface{} `json:"dependencies"` 35 | } 36 | 37 | func LoadAppConfig() (*AppConfig, error) { 38 | f, err := os.Open(ContainerConfigFile) 39 | if err != nil { 40 | return nil, err 41 | } 42 | cfg := AppConfig{} 43 | dec := json.NewDecoder(f) 44 | return &cfg, dec.Decode(&cfg) 45 | } 46 | 47 | func (a *AppConfig) Save(fname string) error { 48 | f, err := os.Create(fname) 49 | if err != nil { 50 | return err 51 | } 52 | enc := json.NewEncoder(f) 53 | return enc.Encode(a) 54 | } 55 | --------------------------------------------------------------------------------