Skip to content

Commit

Permalink
Merge branch 'master' of github.com:leg100/ots
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Jun 21, 2021
2 parents 61eb795 + 2c78591 commit e963727
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.pem
# sqlite db
*.db
# bins
/_build
# terraform
/.terraformignore
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ These steps will get you started with running everything on your local system. Y

![demo](https://user-images.githubusercontent.com/75728/122572684-e21ffc80-d045-11eb-91a7-927d18eb7e62.gif)

1. Download and extract a [release](https://github.com/leg100/ots/releases).
1. Download a [release](https://github.com/leg100/ots/releases). The zip file contains two binaries: a daemon and a client, `otsd` and `ots`. Extract them to a directory in your `PATH`, e.g. `/usr/local/bin`.
1. Generate SSL cert and key. For example, to generate a self-signed cert and key for localhost:

```bash
Expand All @@ -31,21 +31,21 @@ These steps will get you started with running everything on your local system. Y
1. Run the OTS daemon:

```bash
./otsd --ssl --cert-file=cert.crt --key-file=key.pem
otsd --ssl --cert-file=cert.crt --key-file=key.pem
```

The daemon runs in the foreground and can be left to run.

1. In another terminal create an organization:

```bash
./ots organizations new mycorp [email protected]
ots organizations new mycorp [email protected]
```

1. Login to your OTS server (this merely adds some dummy credentials to `~/.terraform.d/credentials.tfrc.json`):

```bash
./ots login
ots login
```

1. Configure the terraform backend and define a resource:
Expand Down
10 changes: 8 additions & 2 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
// Query schema decoder, caches structs, and safe for sharing
var decoder = schema.NewDecoder()

// The HTTP/S server
type Server struct {
server *http.Server
router *mux.Router
Expand All @@ -41,6 +42,7 @@ type Server struct {
StateVersionService ots.StateVersionService
}

// NewServer is the contructor for Server
func NewServer() *Server {
s := &Server{
server: &http.Server{},
Expand All @@ -52,6 +54,7 @@ func NewServer() *Server {
return s
}

// NewRouter constructs a negroni-wrapped HTTP router
func NewRouter(server *Server) *negroni.Negroni {
router := mux.NewRouter()

Expand All @@ -69,13 +72,15 @@ func NewRouter(server *Server) *negroni.Negroni {
w.WriteHeader(http.StatusNoContent)
})

// Organization routes
sub.HandleFunc("/organizations", server.ListOrganizations).Methods("GET")
sub.HandleFunc("/organizations", server.CreateOrganization).Methods("POST")
sub.HandleFunc("/organizations/{name}", server.GetOrganization).Methods("GET")
sub.HandleFunc("/organizations/{name}", server.UpdateOrganization).Methods("PATCH")
sub.HandleFunc("/organizations/{name}", server.DeleteOrganization).Methods("DELETE")
sub.HandleFunc("/organizations/{name}/entitlement-set", server.GetEntitlements).Methods("GET")

// Workspace routes
sub.HandleFunc("/organizations/{org}/workspaces", server.ListWorkspaces).Methods("GET")
sub.HandleFunc("/organizations/{org}/workspaces/{name}", server.GetWorkspace).Methods("GET")
sub.HandleFunc("/organizations/{org}/workspaces", server.CreateWorkspace).Methods("POST")
Expand All @@ -87,14 +92,15 @@ func NewRouter(server *Server) *negroni.Negroni {
sub.HandleFunc("/workspaces/{id}/actions/lock", server.LockWorkspace).Methods("POST")
sub.HandleFunc("/workspaces/{id}/actions/unlock", server.UnlockWorkspace).Methods("POST")

// StateVersion routes
sub.HandleFunc("/workspaces/{workspace_id}/state-versions", server.CreateStateVersion).Methods("POST")
sub.HandleFunc("/workspaces/{workspace_id}/current-state-version", server.CurrentStateVersion).Methods("GET")
sub.HandleFunc("/state-versions/{id}", server.GetStateVersion).Methods("GET")
sub.HandleFunc("/state-versions", server.ListStateVersions).Methods("GET")

// Add default set of negroni middleware to routes: (i) Logging (ii)
// Recovery (iii) Static File serving (we don't use this one...)
n := negroni.Classic()
// Or use a middleware with the Use() function
//n.Use() router goes last
n.UseHandler(router)

return n
Expand Down

0 comments on commit e963727

Please sign in to comment.