mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-18 12:22:10 +03:00
digocean api
This commit is contained in:
parent
519c1627f8
commit
a6da4e0855
128
main/app/do/core.hook
Normal file
128
main/app/do/core.hook
Normal file
@ -0,0 +1,128 @@
|
||||
:: digital ocean fleet management
|
||||
::
|
||||
::::
|
||||
::
|
||||
/? 310
|
||||
::
|
||||
::
|
||||
:::: sivtyv-barnel
|
||||
::
|
||||
::id=@ud name=@t memory=@ud vcpu=@ud disk=@ud locked=@f created=@t status=@t backup-ids=json snapshot-ids=json features=json region=json image=json size=json size-slug=@t networks=json kernel=json next-backup-window=@t])
|
||||
|
||||
!:
|
||||
|%
|
||||
++ droplet ,~
|
||||
++ axle ,[ke=keys toke=tokens drops=(list droplet)]
|
||||
++ keys ,[authc=(unit ,@t) client-secret=(unit ,@t)]
|
||||
++ tokens ,[access=@t refresh=@t]
|
||||
++ droplet (unit ,@)
|
||||
++ move ,[bone (mold note gift)]
|
||||
++ note
|
||||
$: %e
|
||||
%them
|
||||
(unit hiss)
|
||||
==
|
||||
++ gift
|
||||
$% [%nice ~]
|
||||
[%rush %json json]
|
||||
==
|
||||
++ sign
|
||||
$: %e
|
||||
$% [%thou p=httr]
|
||||
== ==
|
||||
|
||||
|
||||
--
|
||||
!:
|
||||
|_ [hid=hide vat=axle]
|
||||
++ auth-queries
|
||||
:~ '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
|
||||
req-type=$?(%get %post) headers=math
|
||||
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
|
||||
[req-type headers ~] :: post
|
||||
:^ ost %pass pour-path
|
||||
:+ %e %them
|
||||
`(unit hiss)`[~ request]
|
||||
++ prep ,_`. :: wipe state when app code is changed
|
||||
::
|
||||
++ peer
|
||||
|= [ost=bone you=ship pax=path]
|
||||
^- [(list move) _+>.$]
|
||||
:_ +>.$
|
||||
[ost %give %rush %json ~]~
|
||||
::
|
||||
++ 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) _+>.$]
|
||||
~& 'pokeclientsecret'
|
||||
=. client-secret.ke.vat
|
||||
[~ secret]
|
||||
~& client-secret.ke.vat
|
||||
:_ +>.$
|
||||
:_ [ost %give %nice ~]~
|
||||
%^ httpreq ost /auth
|
||||
:^ ~[%digitalocean %cloud] `path`/v1/oauth/token
|
||||
%post
|
||||
:- ~ `quay`['client_secret'^(need client-secret.ke.vat) auth-queries]
|
||||
::
|
||||
++ pour
|
||||
|= [ost=bone pour-path=path resp=sign]
|
||||
^- [(list move) _+>.$]
|
||||
?+ -.pour-path !!
|
||||
%auth
|
||||
=+ body=(rash q:(need r.p.+.resp) apex:poja)
|
||||
=+ [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 ~]
|
||||
[(list-droplets ost)]~
|
||||
::
|
||||
%list
|
||||
:_ +>.$
|
||||
=+ parsed=(rash q:(need r.p.+.resp) apex:poja)
|
||||
=+ dar=((ot droplets/(ar some) ~):jo parsed)
|
||||
~& [dar/dar]
|
||||
[ost %give %nice ~]~
|
||||
==
|
||||
++ list-droplets
|
||||
|= os=bone
|
||||
=+ ^= lis :*
|
||||
os /list
|
||||
~[%digitalocean %api] /v2/droplets
|
||||
%get
|
||||
(mo ['Content-Type' 'application/json' ~] ['Authorization' (cat 3 'Bearer ' access.toke.vat) ~] ~)
|
||||
~
|
||||
==
|
||||
(httpreq lis)
|
||||
--
|
29
main/pub/do/fab/hymn.hook
Normal file
29
main/pub/do/fab/hymn.hook
Normal file
@ -0,0 +1,29 @@
|
||||
::
|
||||
::::
|
||||
::
|
||||
/? 310
|
||||
/= gas /$ fuel
|
||||
::
|
||||
::::
|
||||
::
|
||||
!:
|
||||
^- manx
|
||||
|
||||
=+ authcode=(~(get by qix.gas) %'code')
|
||||
;html
|
||||
;head
|
||||
;script@"/~/at/main/lib/urb.js";
|
||||
;script: urb.appl = 'do'
|
||||
;script@"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js";
|
||||
;script@"https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js";
|
||||
::;link/"/main/pub/do/src/main.css"(rel "stylesheet");
|
||||
;title: DO Instance Tracker
|
||||
==
|
||||
;body
|
||||
;* ?~ authcode ~
|
||||
:_ ~
|
||||
;script: authcode='{(trip u.authcode)}'; console.log(authcode)
|
||||
;div#container;
|
||||
;script@"/main/pub/do/src/main.js";
|
||||
==
|
||||
==
|
0
main/pub/do/src/main.css
Normal file
0
main/pub/do/src/main.css
Normal file
46
main/pub/do/src/main.js
Normal file
46
main/pub/do/src/main.js
Normal file
@ -0,0 +1,46 @@
|
||||
recl = React.createClass
|
||||
div = React.DOM.div
|
||||
a = React.DOM.a
|
||||
b = React.DOM.button
|
||||
input = React.DOM.input
|
||||
|
||||
Page = recl({
|
||||
handleClick: function(){
|
||||
if(window.authcode.length !== ''){
|
||||
urb.send({
|
||||
appl: "do",
|
||||
data: window.authcode,
|
||||
mark: "oauth2-code"})
|
||||
} else { console.log("nocode") }
|
||||
},
|
||||
|
||||
sendSecret: function(){
|
||||
if($('#appsecret').val()) {
|
||||
urb.send({appl: "do",
|
||||
data: $('#appsecret').val(),
|
||||
mark: "client-secret"
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
render: function(){
|
||||
href = "https://cloud.digitalocean.com/v1/oauth/authorize?client_id=d8f46b95af38c1ab3d78ad34c2157a6959c23eb0eb5d8e393f650f08e6a75c6f&redirect_uri=http%3A%2F%2Flocalhost%3A8443%2Fmain%2Fpub%2Fdo%2Ffab&response_type=code&redirect_uri=http://localhost:8443/main/pub/do/fab&scope=read+write"
|
||||
return (div({}, [
|
||||
div({},
|
||||
a({href:href},[
|
||||
"get authcode",
|
||||
b({onClick:this.handleClick}, "Send Authcode")
|
||||
])
|
||||
),
|
||||
div({}, [
|
||||
input({id:"appsecret"},
|
||||
b({onClick:this.sendSecret}, "Send Secret"))
|
||||
])
|
||||
])
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
mounted = React.render(Page({}), $("#container")[0])
|
||||
urb.bind("/", function(err,d) {
|
||||
return})
|
Loading…
Reference in New Issue
Block a user