Skip to content

Commit

Permalink
Initial checkin of the CC APIs
Browse files Browse the repository at this point in the history
Change-Id: I7509a50707588b324e608e3ccd2b3e991b0ea746
  • Loading branch information
Patrick Bozeman committed Jun 1, 2012
1 parent 0f22cc0 commit 69e6cce
Show file tree
Hide file tree
Showing 40 changed files with 2,121 additions and 6 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ gem "sequel"
gem "sinatra"
gem "sinatra-contrib"
gem "yajl-ruby"
gem "vcap-concurrency"
gem "vcap_common"
gem "vcap_logging"

Expand Down
6 changes: 2 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GEM
ruby-graphviz (1.0.5)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
sequel (3.34.1)
sequel (3.35.0)
simplecov (0.6.2)
multi_json (~> 1.3)
simplecov-html (~> 0.5.3)
Expand All @@ -67,14 +67,13 @@ GEM
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
vcap-concurrency (0.0.1)
vcap_common (1.0.10)
eventmachine (~> 0.12.11.cloudfoundry.3)
nats (~> 0.4.22.beta.8)
posix-spawn (~> 0.3.6)
thin (~> 1.3.1)
yajl-ruby (~> 0.8.3)
vcap_logging (1.0.0)
vcap_logging (1.0.1)
rake
yajl-ruby (0.8.3)

Expand All @@ -95,7 +94,6 @@ DEPENDENCIES
sinatra
sinatra-contrib
sqlite3
vcap-concurrency
vcap_common
vcap_logging
yajl-ruby
318 changes: 318 additions & 0 deletions docs/ilia_tour
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
Hi. Lets take a tour of working with the cc locally and do a few basic
operations.

Heads up.. the CC doesn't match the API doc yet. This tour will guide you
around the pitfalls.

Run the CC

First, let's get your cloud controller running. To do so, in another window
run:

bin/cloud_controller -d -m

-d puts the cc into developer mode. -m will cause it to run migrations.

You don't really have to go into dev mode, but you do need to run -m at
least once.


Test the CC

Your cc should be up and running on port 8080 now, so test it out.
with:

curl -v http://localhost:8080/

You should get a 404 back and a custom error body. We should probably be
nicer about returning something for /, but for now, meh.

That error body is the standard sort of error that you will expect to see for
other types of errors.

Bootstrap an Admin

Ok.. let's get your admin user created. We really need an external
bootstrap tool to insert an initial admin into the db, but for now, you can
do the following

curl -v http://localhost:8080/bootstrap

You should get back an HTTP 201 and a blob of json. Since the bootstrap call
is not a real CC api call, it is not in the standard format with a metadata
and entity section.

Let's see a server error:

If you run the same command again:

curl -v http://localhost:8080/bootstrap

You will get back a 500 and a custom server error response body. This is
because the bootstrap route bypasses the API. Had you gone through the API
you would have gotten a real error message. Still, you didn't get a blob of
html on an unhandled error like in the original cc.

Note the window you are running the cc in. You should see a big stack trace.
If you get any weird server errors, go check for those sort of backtraces and
send them to me.

Let's create an org:

Ok, this will be a load of fun!

curl -X POST -H "Content-Type: application/json" \
-d '{"name":"my cool org"}' \
http://localhost:8080/v2/organizations

Oh, you got an auth error. Silly you.


Let's create an org with "correct" auth/authz

Ok, this will be even more fun. Fun like a horror movie. (UAA integration
is coming. We used to have our own signed token, but didn't bother checking
it in because the UAA is the true new hotness.)

curl -X POST -H "Content-Type: application/json" \
-H "Authorization: iliag@vmware.com" \
-d '{"name":"my cool org"}' \
http://localhost:8080/v2/organizations

Now this time you should get something back like:

{
"metadata": {
"id": 1,
"url": "/v2/organizations/1",
"created_at": "2012-05-14 12:49:31 -0700",
"updated_at": null
},
"entity": {
"name": "my cool org",
"users_url":
"/v2/users?q=organization_id:1",
"app_spaces_url":
"/v2/app_spaces?q=organization_id:1"
}
}

Yay.

Note the Location header in the response. You should be able to do
a GET on that.


Let's double check our org:

curl -H "Authorization: iliag@vmware.com" \
http://localhost:8080/v2/organizations/1

{
"metadata": {
"id": 1,
"url": "/v2/organizations/1",
"created_at": "2012-05-14 12:49:31 -0700",
"updated_at": null
},
"entity": {
"name": "my cool org",
"users_url":
"/v2/users?q=organization_id:1",
"app_spaces_url":
"/v2/app_spaces?q=organization_id:1"
}
}

Double yay.


Let's rename the org:

curl -v -X PUT -H "Content-Type: application/json" \
-H "Authorization: iliag@vmware.com" \
-d '{"name":"ilia likes orgs"}' \
http://localhost:8080/v2/organizations/1

{
"metadata": {
"id": 1,
"url": "/v2/organizations/1",
"created_at": "2012-05-14 12:49:31 -0700",
"updated_at": "2012-05-14 12:55:01 -0700"
},
"entity": {
"name": "ilia likes orgs",
"users_url":
"/v2/users?q=organization_id:1",
"app_spaces_url":
"/v2/app_spaces?q=organization_id:1"
}
}


Let's go create a user:

curl -v -X POST -H "Content-Type: application/json" \
-H "Authorization: iliag@vmware.com" \
-d '{"id":"1234-4567-89AB-CDEF"}' \
http://localhost:8080/v2/users

{
"metadata": {
"id": "1234-4567-89AB-CDEF",
"url": "/v2/users/1234-4567-89AB-CDEF",
"created_at": "2012-05-14 12:57:08 -0700",
"updated_at": null
},
"entity": {
"id": "1234-4567-89AB-CDEF",
"admin": false,
"active": false,
"organizations_url":
"/v2/organizations?q=user_id:1234-4567-89AB-CDEF",
"app_spaces_url":
"/v2/app_spaces?q=user_id:1234-4567-89AB-CDEF"
}
}

So now we should have 2 users, (the boot strap user, plus the one above)
let's see: (NOTE: The bootstrap user is currently using an email address
since that is what was provided in the last drop, but for now,
all uaa_ids are basically arbitrary text strings as far as the CC is concerned)

curl -v -H "Authorization: iliag@vmware.com" http://localhost:8080/v2/users

{
"total_results": 2,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"id": "iliag@vmware.com",
"url": "/v2/users/iliag@vmware.com",
"created_at": "2012-05-14 12:47:03 -0700",
"updated_at": null
},
"entity": {
"id": "iliag@vmware.com",
"admin": true,
"active": true,
"organizations_url": "/v2/organizations?q=user_id:iliag@vmware.com",
"app_spaces_url": "/v2/app_spaces?q=user_id:iliag@vmware.com"
}
},
{
"metadata": {
"id": "1234-4567-89AB-CDEF",
"url": "/v2/users/1234-4567-89AB-CDEF",
"created_at": "2012-05-14 12:57:08 -0700",
"updated_at": null
},
"entity": {
"id": "1234-4567-89AB-CDEF",
"admin": false,
"active": false,
"organizations_url": "/v2/organizations?q=user_id:1234-4567-89AB-CDEF",
"app_spaces_url": "/v2/app_spaces?q=user_id:1234-4567-89AB-CDEF"
}
}
]
}

Yep

Check the orgs the same way:

curl -v -H "Authorization: iliag@vmware.com" \
http://localhost:8080/v2/organizations

{
"total_results": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"id": 1,
"url": "/v2/organizations/1",
"created_at": "2012-05-14 12:49:31 -0700",
"updated_at": "2012-05-14 12:55:01 -0700"
},
"entity": {
"name": "ilia likes orgs",
"users_url": "/v2/users?q=organization_id:1",
"app_spaces_url": "/v2/app_spaces?q=organization_id:1"
}
}
]
}


Those url associations work. Let's check the one for
the 1234-... user.

curl -v -H "Authorization: iliag@vmware.com" \
http://localhost:8080/v2/organizations?q=user_id:1234-4567-89AB-CDEF

{
"total_results": 0,
"prev_url": null,
"next_url": null,
"resources": [

]
}

Which is correct because we haven't added the user to an org yet.


Now let's add that 1234-... user to an org:

curl -v -X PUT -H "Content-Type: application/json" \
-H "Authorization: iliag@vmware.com" \
-d '{"user_ids":["1234-4567-89AB-CDEF"]}' \
http://localhost:8080/v2/organizations/1

{
"metadata": {
"id": 1,
"url": "/v2/organizations/1",
"created_at": "2012-05-14 12:49:31 -0700",
"updated_at": "2012-05-14 13:09:59 -0700"
},
"entity": {
"name": "ilia likes orgs",
"users_url": "/v2/users?q=organization_id:1",
"app_spaces_url": "/v2/app_spaces?q=organization_id:1"
}
}

Now if we fetch the url association for that user again:

curl -v -H "Authorization: iliag@vmware.com" \
http://localhost:8080/v2/organizations?q=user_id:1234-4567-89AB-CDEF

{
"total_results": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"id": 1,
"url": "/v2/organizations/1",
"created_at": "2012-05-14 12:49:31 -0700",
"updated_at": "2012-05-14 13:09:59 -0700"
},
"entity": {
"name": "ilia likes orgs",
"users_url": "/v2/users?q=organization_id:1",
"app_spaces_url": "/v2/app_spaces?q=organization_id:1"
}
}
]
}

Yep.. he shows up in org 1 as expected.
Loading

0 comments on commit 69e6cce

Please sign in to comment.