1
0
mirror of https://github.com/ilyakooo0/urbit.git synced 2024-12-22 14:21:34 +03:00
urbit/main/app/do/core.hook

328 lines
8.9 KiB
Plaintext
Raw Normal View History

2015-04-25 21:23:34 +03:00
:: digital ocean fleet management
::
::::
::
/? 310
::
::
:::: sivtyv-barnel
::
!:
|%
2015-04-30 00:02:54 +03:00
++ droplet
2015-05-01 06:22:05 +03:00
$: id=@ud name=@t memory=@ud vcpus=@ud disk=@ud locked=?
2015-04-30 00:02:54 +03:00
created=@t status=@t backup-ids=(list ,@t) snapshot-ids=(list ,@t)
2015-04-30 23:55:10 +03:00
features=(list ,@t) region=regi image=img
size=syze size-slug=@t networks=ntwrks kernel=kern
2015-04-30 05:24:24 +03:00
next-backup-window=json
2015-04-30 00:02:54 +03:00
==
2015-04-30 23:55:10 +03:00
++ regi ,[name=@t slug=@t sizes=(list ,@t)]
2015-04-30 05:24:24 +03:00
++ kern ,[id=@ud name=@t version=@t]
2015-04-30 00:02:54 +03:00
++ img
$: id=@ud name=@t distribution=@t slug=@t public=? regions=(list ,@t)
created-at=@t type=@t min-disk-size=@ud
==
2015-04-30 05:24:24 +03:00
++ ntwrks ,[v4=(list v) v6=(list v)]
2015-04-30 00:02:54 +03:00
++ v ,[ip-address=@t netmask=@t gateway=@t type=@t]
2015-04-30 23:55:10 +03:00
++ syze
$: memory=@ud price-monthly=@t price-hourly=@t disk=@ud vcpus=@ud
slug=@t transfer=@t available=? regions=(list ,@t)
2015-04-30 05:24:24 +03:00
==
2015-04-30 23:55:10 +03:00
++ reqbody
$:
name=@t region=@t size=@t image=@t ssh=(list cord)
backups=(unit ,?) ipv6=(unit ,?) private-networking=(unit ,?) user-data=(unit ,@t)
==
++ axle ,[ke=keys toke=tokens drops=(list droplet)]
2015-04-25 21:23:34 +03:00
++ keys ,[authc=(unit ,@t) client-secret=(unit ,@t)]
++ tokens ,[access=@t refresh=@t]
++ move ,[bone (mold note gift)]
++ note
$: %e
%them
(unit hiss)
==
++ gift
$% [%nice ~]
[%rush %json json]
==
++ sign
$: %e
$% [%thou p=httr]
== ==
2015-04-30 00:02:54 +03:00
--
2015-04-30 23:55:10 +03:00
!:
2015-04-30 00:02:54 +03:00
|%
2015-04-30 05:24:24 +03:00
++ parse-img
2015-04-30 00:02:54 +03:00
=> jo
2015-04-30 05:24:24 +03:00
%- ot
:~ id/ni name/so distribution/so slug/so public/bo
regions/(ar so) 'created_at'^so type/so 'min_disk_size'^ni
2015-04-30 00:02:54 +03:00
==
++ parse-ntwrks
=> jo
%- ot
2015-04-30 05:24:24 +03:00
:+ v4/(ar (ot 'ip_address'^so netmask/so gateway/so type/so ~))
v6/(ar (ot 'ip_address'^so netmask/so gateway/so type/so ~))
2015-04-30 00:02:54 +03:00
~
2015-04-30 05:24:24 +03:00
++ parse-size
=> jo
%- ot
2015-04-30 23:55:10 +03:00
:~ memory/ni 'price_monthly'^no 'price_hourly'^no disk/ni
vcpus/ni slug/so transfer/no available/bo regions/(ar so)
2015-04-30 05:24:24 +03:00
==
2015-04-30 23:55:10 +03:00
++ parse-region
=> jo
(ot name/so slug/so sizes/(ar so) ~)
2015-04-30 05:24:24 +03:00
++ create-body
2015-04-30 23:55:10 +03:00
|= $: name=@t region=@t size=@t image=@t ssh-keys=(list cord)
backups=(unit ,?) ipv6=(unit ,?) private-networking=(unit ,?) user-data=(unit ,@t)
2015-04-30 05:24:24 +03:00
==
%- jobe
:~ name/s/name region/s/region size/s/size image/s/image
2015-04-30 23:55:10 +03:00
'ssh_keys'^a/(turn ssh-keys |=(cord s/+<)) backups/?~(backups ~ b/u.backups) ipv6/?~(ipv6 ~ b/u.ipv6)
'user_data'^?~(user-data ~ s/u.user-data) 'private_networking'^?~(private-networking ~ b/u.private-networking)
2015-04-30 05:24:24 +03:00
==
2015-05-01 06:22:05 +03:00
++ state-to-json
|= a=(list droplet)
:- %a
%+ turn a
|= droplet
^- json
%- jobe
:~ id/`json`(jone id)
name/`json`s/name
vcpus/`json`(jone vcpus)
disk/`json`(jone disk)
locked/b/locked
created/s/created
status/s/status
backup-ids/a/(turn backup-ids |=(el=cord s/el))
snapshot-ids/a/(turn snapshot-ids |=(el=cord s/el))
features/a/(turn features |=(el=cord s/el))
=+ ^= reg
:~ name/s/name.region slug/s/slug.region
sizes/a/(turn sizes.region |=(el=cord s/el))
==
region/(jobe reg)
=+ ^= im
:~ id/(jone id.image) name/s/name.image distribution/s/distribution.image
slug/s/slug.image public/b/public.image
regions/a/(turn regions.image |=(el=cord s/el))
created-at/s/created-at.image type/s/type.image
min-disk-size/(jone min-disk-size.image)
==
image/(jobe im)
=+ ^= sz
:~ memory/(jone memory.size) price-monthly/s/price-monthly.size
price-hourly/s/price-hourly.size disk/(jone disk.size) vcpus/(jone vcpus.size)
slug/s/slug.size transfer/s/transfer.size available/b/available.size
regions/a/(turn regions.size |=(el=cord s/el))
==
size/(jobe sz)
size-slug/s/size-slug
=+ ^= nt
=+ ^= vobj
|= v
%- jobe :~
ip-address/s/ip-address netmask/s/netmask
gateway/s/gateway type/s/type
==
:~ v4/[%a (turn v4.networks vobj)]
v6/[%a (turn v4.networks vobj)]
==
networks/(jobe nt)
kernel/s/'kernel'
next-backup-window/s/'valid'
==
2015-04-25 21:23:34 +03:00
--
!:
|_ [hid=hide vat=axle]
2015-04-30 00:02:54 +03:00
::
2015-04-30 05:24:24 +03:00
++ auth-queries
2015-04-25 21:23:34 +03:00
:~ 'grant_type'^'authorization_code'
'code'^(need authc.ke.vat)
:- 'client_id'
'd8f46b95af38c1ab3d78ad34c2157a6959c23eb0eb5d8e393f650f08e6a75c6f'
'redirect_uri'^'http://localhost:8443/main/pub/do/fab'
==
++ httpreq
|= $: ost=bone pour-path=wire
domain=(list cord) end-point=path
2015-04-30 05:24:24 +03:00
req-type=$?(%get [%post json]) headers=math
2015-04-25 21:23:34 +03:00
queries=quay
==
^- move
=+ ^- parsed-url=purl
:+ ^= host-port :: ++hart
:+ security=%.y
port=~
host=[%.y [path=[%com domain]]]
endpoint=[extensions=~ point=end-point] :: ++pork,
q-strings=queries :: ++quay
=+ ^- request=hiss :: cast to hiss
:- parsed-url
2015-04-30 05:24:24 +03:00
?@ req-type
[%get headers ~]
[%post headers ~ (tact (pojo +.req-type))]
2015-04-25 21:23:34 +03:00
:^ ost %pass pour-path
:+ %e %them
`(unit hiss)`[~ request]
2015-05-01 06:22:05 +03:00
::++ prep ,_`. :: wipe state when app code is changed
2015-04-25 21:23:34 +03:00
::
++ peer
|= [ost=bone you=ship pax=path]
^- [(list move) _+>.$]
:_ +>.$
2015-05-01 06:22:05 +03:00
[ost %give %rush %json (state-to-json drops.vat)]~
2015-04-25 21:23:34 +03:00
::
++ poke-oauth2-code
|= [ost=bone you=ship code=cord]
^- [(list move) _+>.$]
=. authc.ke.vat
[~ code]
=+ ath=(need authc.ke.vat)
:_ +>.$
[ost %give %nice ~]~
::
++ poke-client-secret
|= [ost=bone you=ship secret=cord]
^- [(list move) _+>.$]
=. client-secret.ke.vat
[~ secret]
~& client-secret.ke.vat
:_ +>.$
:_ [ost %give %nice ~]~
%^ httpreq ost /auth
:^ ~[%digitalocean %cloud] `path`/v1/oauth/token
2015-04-30 05:24:24 +03:00
[%post ~]
2015-04-25 21:23:34 +03:00
:- ~ `quay`['client_secret'^(need client-secret.ke.vat) auth-queries]
::
2015-04-30 00:02:54 +03:00
++ receive-auth
2015-04-25 21:23:34 +03:00
|= [ost=bone pour-path=path resp=sign]
2015-04-30 00:02:54 +03:00
=+ body=(rash q:(need r.p.+.resp) apex:poja)
~& body
=+ [ac re]=(need ((ot 'access_token'^so 'refresh_token'^so ~):jo body))
=: access.toke.vat ac
refresh.toke.vat re
==
~& toke.vat
:_ +>.$
[ost %give %nice ~]~
::
++ poke-json
|= [ost=bone you=ship act=json]
2015-04-30 05:24:24 +03:00
=+ do=(need ((ot action/so ~):jo act))
2015-04-30 00:02:54 +03:00
?+ do !!
%list
2015-05-01 06:22:05 +03:00
:_ +>.$
:+ [(list-droplets ost)]
[ost %give %nice ~]
~
2015-04-30 05:24:24 +03:00
%create
2015-05-01 06:22:05 +03:00
:_ +>.$
=+ ^- deets=reqbody
%- need
%. act
=> jo
%- ot
:~ name/so region/so size/so image/so ssh/(ar so) backups/(mu bo)
'ipv6'^(mu bo) 'priv_networking'^(mu bo) 'user_data'^(mu so)
==
:+ [(create-droplet ost deets)]
[ost %give %nice ~]
~
%reboot
=+ id=(need ((ot id/ni ~):jo act))
~& id
:+ (reboot-droplet ost id)
[%ost %give %nice ~]
~
2015-04-25 21:23:34 +03:00
==
2015-04-30 00:02:54 +03:00
::
2015-05-01 06:22:05 +03:00
++ reboot-droplet
|= [ost=bone id=@ud]
=+ ^= reboot
:~ ost /reboot
~[%digitalocean %api] /v2/droplets/(scot %ud id)/actions
:- %post
(jobe type/s/'reboot' ~)
(mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.toke.vat) ~] ~)
==
(httpreq reboot)
::
2015-04-25 21:23:34 +03:00
++ list-droplets
|= os=bone
2015-05-01 06:22:05 +03:00
=+ ^= lis
:~ os /list
2015-04-25 21:23:34 +03:00
~[%digitalocean %api] /v2/droplets
%get
(mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.toke.vat) ~] ~)
==
(httpreq lis)
2015-04-30 00:02:54 +03:00
::
2015-04-30 05:24:24 +03:00
++ receive-list
|= [ost=bone pour-path=path resp=sign]
=+ parsed=(rash q:(need r.p.+.resp) apex:poja)
=+ dar=(need ((ot droplets/(ar some) ~):jo parsed))
2015-04-30 23:55:10 +03:00
=+ ^- dropz=(list droplet)
2015-04-30 05:24:24 +03:00
~| bad-json/-.dar
2015-04-30 23:55:10 +03:00
%+ turn dar
|= drp=json
2015-04-30 05:24:24 +03:00
%- need
2015-04-30 23:55:10 +03:00
%. drp =+ jo
2015-04-30 05:24:24 +03:00
%- ot
:~ id/ni name/so
memory/ni vcpus/ni disk/ni
locked/bo 'created_at'^so status/so
'backup_ids'^(ar so) 'snapshot_ids'^(ar so) features/(ar so)
2015-04-30 23:55:10 +03:00
region/parse-region image/parse-img size/parse-size
2015-04-30 05:24:24 +03:00
'size_slug'^so networks/parse-ntwrks kernel/(ot id/ni name/so version/so ~)
'next_backup_window'^some
==
2015-04-30 23:55:10 +03:00
=. drops.vat
dropz
~& drops/drops.vat
2015-04-30 05:24:24 +03:00
:_ +>.$
[ost %give %nice ~]~
::
++ create-droplet
2015-04-30 23:55:10 +03:00
|= [os=bone reqbody]
2015-04-30 05:24:24 +03:00
~& 'reached'
=+ ^= create :*
os /create
~[%digitalocean %api] /v2/droplets
:- %post
2015-04-30 23:55:10 +03:00
%- create-body
:* name region size image ssh backups
ipv6 private-networking user-data
==
2015-04-30 05:24:24 +03:00
%^ mo ['Content-Type' 'application/json' ~]
['Authorization' (cat 3 'Bearer ' access.toke.vat) ~] ~
~
==
(httpreq create)
::
2015-04-30 00:02:54 +03:00
++ pour
|= [ost=bone pour-path=path resp=sign]
^- [(list move) _+>.$]
?+ -.pour-path !!
%auth
(receive-auth ost pour-path resp)
::
%list
(receive-list ost pour-path resp)
2015-04-30 23:55:10 +03:00
::
2015-04-30 05:24:24 +03:00
%create
~& created/resp
:_ +>.$
[ost %give %nice ~]~
2015-05-01 06:22:05 +03:00
::
%reboot
~& resp
:_ +>.$
[ost %give %nice ~]~
2015-04-30 00:02:54 +03:00
==
2015-04-25 21:23:34 +03:00
--