UNPKG

@fntio/infra-client

Version:

Self-hosted AWS access portal: credential vending, target-account trust, and grant-driven private networking as CDK stacks and constructs.

2 lines (1 loc) • 18 kB
import{a as K,c as Se,d as we,e as Ee,f as V,g as De,h as Me,i as Ne,j as Fe,k as Pe}from"./chunk-252EGHSF.js";import{a as Te}from"./chunk-KRQ75YR4.js";import{a as te}from"./chunk-64ITJKG6.js";import{a as X}from"./chunk-LEEL6MDA.js";import{b as Ce}from"./chunk-HUXCPIDO.js";import{a as xe}from"./chunk-XPF5YBGU.js";import{v as J}from"./chunk-Z2HQA5DO.js";import{a as P}from"./chunk-2DD7CZB4.js";import{a as Y}from"./chunk-J7PZFXOE.js";import{a as R}from"./chunk-WM5A6BAU.js";import{a as ve,d as he,e as be}from"./chunk-JNANYFF2.js";import{a as ee}from"./chunk-YMC4QOLO.js";import{b as ke,d as ye}from"./chunk-6NTXC6VK.js";import{a as ge}from"./chunk-6HVGPPAG.js";import{a as _e}from"./chunk-IVXFG5AJ.js";import{d as fe}from"./chunk-2SO4BVIT.js";import{a as oe,b as ie,e as re,g as ae,i as le,j as se,k as pe,l as ce,m as me,n as de,o as ue,p as D}from"./chunk-T5HLFYHP.js";import{a as U,c as G}from"./chunk-KCJ5HNXP.js";import{a as ne}from"./chunk-3SC2PPSK.js";import{a as E}from"./chunk-B67EMZ2H.js";import{b as Z}from"./chunk-MID2IYAR.js";import"./chunk-6GDWMGWO.js";import{a as w}from"./chunk-7A4HO4AV.js";import"./chunk-ZRDXKVPG.js";import{Aa as r,Ba as i,Ca as b,I as y,Ja as k,K as x,L as C,La as d,Na as p,R as u,Ra as H,Sa as q,Xa as s,Ya as _,_ as a,_a as L,ga as T,ka as z,nb as Q,pb as B,qb as S,rb as O,sb as M,ta as f,tb as F,ua as g,ub as W,wa as N,xa as v,ya as h,za as m}from"./chunk-FYA6QUPZ.js";import{a as $,b as j}from"./chunk-WFIHWVQO.js";var $e=(n,t)=>t.scope,Le=(n,t)=>t.accountNumber,Be=(n,t)=>t.role;function Oe(n,t){if(n&1){let e=k();r(0,"label",7)(1,"input",17),d("change",function(){let l=x(e).$implicit,c=p();return C(c.toggleScope(l.scope))}),i(),r(2,"span",18)(3,"span",19),s(4),i(),r(5,"span",20),s(6),i()()()}if(n&2){let e=t.$implicit,o=p();a(),m("checked",o.scopes().has(e.scope)),a(3),_(e.label),a(2),_(o.describe(e))}}function Ke(n,t){if(n&1&&(r(0,"option",10),s(1),i()),n&2){let e=t.$implicit,o=p();m("ngValue",e),a(),_(o.daysLabel(e))}}function je(n,t){if(n&1){let e=k();r(0,"app-field",11)(1,"input",21),d("ngModelChange",function(l){x(e);let c=p();return C(c.customDays.set(l))}),i()()}if(n&2){let e=p();m("hint","1 to "+e.maxDays()),a(),m("max",e.maxDays())("ngModel",e.customDays())}}function ze(n,t){if(n&1&&(r(0,"div",25)(1,"app-banner",12),s(2),i()()),n&2){let e=p(3);a(2),_(e.accountsError())}}function He(n,t){n&1&&b(0,"app-skeleton",26)}function qe(n,t){n&1&&(r(0,"p",27),s(1,"You don't hold any roles right now."),i())}function Qe(n,t){if(n&1){let e=k();r(0,"label",7)(1,"input",17),d("change",function(){let l=x(e).$implicit,c=p().$implicit,Ae=p(4);return C(Ae.toggleRole(c.accountNumber,l.role))}),i(),r(2,"span",30),s(3),i()()}if(n&2){let e=t.$implicit,o=p().$implicit,l=p(4);a(),m("checked",l.pickedRoles().has(o.accountNumber+"#"+e.role)),a(2),_(e.displayName||e.role)}}function We(n,t){if(n&1&&(r(0,"p",29),s(1),i(),v(2,Qe,4,2,"label",7,Be)),n&2){let e=t.$implicit;a(),_(e.name||e.accountNumber),a(),h(e.roles)}}function Ue(n,t){if(n&1&&(r(0,"div",28),v(1,We,4,1,null,null,Le),i()),n&2){let e=p(3);a(),h(e.accounts())}}function Ye(n,t){if(n&1&&f(0,ze,3,1,"div",25)(1,He,1,0,"app-skeleton",26)(2,qe,2,0,"p",27)(3,Ue,3,0,"div",28),n&2){let e=p(2);g(e.accountsError()?0:e.accounts()===null?1:e.accounts().length===0?2:3)}}function Ge(n,t){if(n&1){let e=k();r(0,"div")(1,"label",22)(2,"input",17),d("change",function(){x(e);let l=p();return C(l.limitRoles.set(!l.limitRoles()))}),i(),r(3,"span",23),s(4,"Limit to these roles"),i()(),r(5,"p",24),s(6," Without a limit the token can use every role you hold when it is used. "),i(),f(7,Ye,4,1),i()}if(n&2){let e=p();a(2),m("checked",e.limitRoles()),a(5),g(e.limitRoles()?7:-1)}}function Je(n,t){if(n&1&&(r(0,"app-banner",12),s(1),i()),n&2){let e=p();a(),_(e.serverError())}}function Xe(n,t){if(n&1&&(r(0,"span",14),s(1),i()),n&2){let e=p();a(),_(e.problem())}}var I=class n{api=y(P);accountsApi=y(Y);auth=y(J);maxDays=F.required();created=M();cancelled=M();SCOPES=K;daysLabel=Ne;describe=t=>Se(t,this.auth.isAdmin());name=u("");description=u("");scopes=u(new Set);expiryChoice=u(30);customDays=u(null);limitRoles=u(!1);pickedRoles=u(new Set);accounts=u(null);accountsError=u("");busy=u(!1);attempted=u(!1);serverError=u("");expiryOptions=S(()=>De(this.maxDays()));showRoles=S(()=>V([...this.scopes()]));expiresInDays=S(()=>{let t=this.expiryChoice();return t==="custom"?Number(this.customDays()??NaN):t});selectedRoles=S(()=>(this.accounts()??[]).flatMap(t=>t.roles.filter(e=>this.pickedRoles().has(t.accountNumber+"#"+e.role)).map(e=>({accountNumber:t.accountNumber,roleName:e.role}))));problem=S(()=>{let t=Fe({name:this.name(),description:this.description(),scopes:[...this.scopes()],expiresInDays:this.expiresInDays()},this.maxDays());return t||(this.showRoles()&&this.limitRoles()&&this.selectedRoles().length===0?"Pick at least one role, or turn off the limit.":null)});constructor(){O(()=>{let t=Me(this.maxDays());B(()=>this.expiryChoice.set(t))}),O(()=>{this.showRoles()&&this.limitRoles()&&B(()=>this.loadAccounts())})}loadAccounts(){this.accounts()===null&&(this.accountsError.set(""),this.accountsApi.listAccounts().subscribe({next:t=>this.accounts.set(t.filter(e=>e.roles.length>0)),error:t=>this.accountsError.set(D(t,"Could not load your roles."))}))}toggleScope(t){this.scopes.update(e=>{let o=new Set(e);return o.has(t)?o.delete(t):o.add(t),o})}toggleRole(t,e){let o=Pe({accountNumber:t,roleName:e});this.pickedRoles.update(l=>{let c=new Set(l);return c.has(o)?c.delete(o):c.add(o),c})}submit(){if(this.attempted.set(!0),this.problem())return;let t=this.description().trim(),e=this.showRoles()&&this.limitRoles();this.busy.set(!0),this.serverError.set(""),this.api.create($(j($({name:this.name().trim()},t?{description:t}:{}),{scopes:K.map(o=>o.scope).filter(o=>this.scopes().has(o)),expiresInDays:this.expiresInDays()}),e?{roles:this.selectedRoles()}:{})).subscribe({next:o=>{this.busy.set(!1),this.created.emit(o)},error:o=>{this.busy.set(!1),this.serverError.set(D(o,"Could not create the token."))}})}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=T({type:n,selectors:[["app-token-create-form"]],inputs:{maxDays:[1,"maxDays"]},outputs:{created:"created",cancelled:"cancelled"},decls:26,vars:10,consts:[[1,"space-y-5"],["label","Name","hint","what uses it, e.g. the script or job"],["maxlength","60","autocomplete","off","placeholder","nightly-backup",1,"ui-input",3,"ngModelChange","ngModel"],["label","Description","hint","optional"],["rows","2","maxlength","200",1,"ui-input",3,"ngModelChange","ngModel"],[1,"mb-1.5","text-sm","font-medium","text-surface-foreground"],[1,"rounded-lg","border","border-border"],[1,"ui-check-row","text-sm"],["label","Expires after",3,"hint"],[1,"ui-input",3,"ngModelChange","ngModel"],[3,"ngValue"],["label","Days",3,"hint"],["tone","danger"],[1,"mt-5","flex","items-center","justify-end","gap-3"],[1,"mr-auto","text-xs","text-danger"],["variant","outline","size","lg",3,"click"],["size","lg",3,"click","loading"],["type","checkbox",1,"ui-checkbox",3,"change","checked"],[1,"min-w-0","flex-1"],[1,"block","font-medium","text-surface-foreground"],[1,"block","text-xs","text-muted-foreground"],["type","number","min","1","step","1",1,"ui-input",3,"ngModelChange","max","ngModel"],[1,"flex","cursor-pointer","items-center","gap-2.5","text-sm"],[1,"font-medium","text-surface-foreground"],[1,"mt-1","text-xs","text-muted-foreground"],[1,"mt-2"],["sizeClass","h-16 w-full",1,"mt-2","block"],[1,"mt-2","text-xs","text-muted-foreground"],[1,"mt-2","max-h-64","overflow-y-auto","rounded-lg","border","border-border"],[1,"ui-microlabel","px-3","pb-1","pt-2","text-muted-foreground"],[1,"min-w-0","flex-1","truncate","text-surface-foreground"]],template:function(e,o){e&1&&(r(0,"div",0)(1,"app-field",1)(2,"input",2),d("ngModelChange",function(c){return o.name.set(c)}),i()(),r(3,"app-field",3)(4,"textarea",4),d("ngModelChange",function(c){return o.description.set(c)}),i()(),r(5,"div")(6,"p",5),s(7,"Scopes"),i(),r(8,"div",6),v(9,Oe,7,3,"label",7,$e),i()(),r(11,"app-field",8)(12,"select",9),d("ngModelChange",function(c){return o.expiryChoice.set(c)}),v(13,Ke,2,2,"option",10,N),r(15,"option",10),s(16,"Custom\u2026"),i()()(),f(17,je,2,3,"app-field",11),f(18,Ge,8,2,"div"),f(19,Je,2,1,"app-banner",12),i(),r(20,"div",13),f(21,Xe,2,1,"span",14),r(22,"app-button",15),d("click",function(){return o.cancelled.emit()}),s(23,"Cancel"),i(),r(24,"app-button",16),d("click",function(){return o.submit()}),s(25,"Create token"),i()()),e&2&&(a(2),m("ngModel",o.name()),a(2),m("ngModel",o.description()),a(5),h(o.SCOPES),a(2),m("hint","at most "+o.daysLabel(o.maxDays())+" on this portal"),a(),m("ngModel",o.expiryChoice()),a(),h(o.expiryOptions()),a(2),m("ngValue","custom"),a(2),g(o.expiryChoice()==="custom"?17:-1),a(),g(o.showRoles()?18:-1),a(),g(o.serverError()?19:-1),a(2),g(o.attempted()&&o.problem()?21:-1),a(3),m("loading",o.busy()))},dependencies:[ue,se,pe,oe,ae,le,ie,de,me,ce,re,E,w,_e,R],encapsulation:2})};var A=class n{created=F.required();closed=M();static \u0275fac=function(e){return new(e||n)};static \u0275cmp=T({type:n,selectors:[["app-token-secret"]],inputs:{created:[1,"created"]},outputs:{closed:"closed"},decls:17,vars:2,consts:[["tone","warning"],[1,"mt-4","grid","gap-y-1","text-sm"],[1,"text-xs","font-medium","text-muted-foreground"],[1,"flex","items-center","justify-between","gap-2","rounded-md","bg-muted","px-3","py-2"],["data-testid","token-secret",1,"min-w-0","break-all","font-mono","text-xs"],["variant","icon","label","Copy token",3,"text"],[1,"mt-4","text-xs","text-muted-foreground"],[1,"font-mono"],[1,"mt-5","flex","justify-end"],["size","lg",3,"click"]],template:function(e,o){e&1&&(r(0,"app-banner",0),s(1," Copy the token now \u2014 you won't see it again. If it's lost, revoke it and create a new one. "),i(),r(2,"dl",1)(3,"dt",2),s(4,"Token"),i(),r(5,"dd",3)(6,"code",4),s(7),i(),b(8,"app-copy-button",5),i()(),r(9,"p",6),s(10," Send it as "),r(11,"code",7),s(12,"Authorization: Bearer \u2026"),i(),s(13," on API calls. It acts as you, limited to its scopes, so keep it in a secret store \u2014 never in code or logs. "),i(),r(14,"div",8)(15,"app-button",9),d("click",function(){return o.closed.emit()}),s(16,"Done"),i()()),e&2&&(a(7),_(o.created().secret),a(),m("text",o.created().secret))},dependencies:[E,w,te],encapsulation:2})};var Ze=["panelTpl"],et=(n,t)=>t.tokenId,tt=(n,t)=>t.accountNumber+"#"+t.roleName;function nt(n,t){if(n&1&&(r(0,"app-banner",4),s(1),i()),n&2){let e=p();a(),_(e.error())}}function ot(n,t){n&1&&(r(0,"div",5),b(1,"app-skeleton",9)(2,"app-skeleton",9),i())}function it(n,t){n&1&&(r(0,"app-empty-state",6)(1,"span",10),s(2,"Create token"),i(),s(3," issues a secret a script, CI job, command-line tool or remote development machine uses to act as you \u2014 only within the scopes you pick, and only until it expires. "),i())}function rt(n,t){if(n&1&&(r(0,"span",17),s(1),i()),n&2){let e=p().$implicit;a(),_(e.description)}}function at(n,t){if(n&1&&(r(0,"app-chip"),s(1),i()),n&2){let e=t.$implicit,o=p(3);a(),_(o.scopeLabel(e))}}function lt(n,t){if(n&1&&(r(0,"app-badge",29),s(1),i()),n&2){let e=t.$implicit,o=p(4);a(),L("",e.roleName," \xB7 ",o.names.label(e.accountNumber))}}function st(n,t){if(n&1&&(r(0,"div",21),v(1,lt,2,2,"app-badge",29,tt),i()),n&2){let e=p().$implicit;a(),h(e.roles)}}function pt(n,t){n&1&&(r(0,"p",22),s(1,"All your roles"),i())}function ct(n,t){n&1&&(r(0,"app-badge",25),s(1,"expired"),i())}function mt(n,t){if(n&1&&(r(0,"app-badge",26),s(1),i()),n&2){let e=p().$implicit,o=p(2);a(),_(o.until(e.expiresAt))}}function dt(n,t){if(n&1){let e=k();r(0,"div",14)(1,"div",15)(2,"span",16),s(3),i(),f(4,rt,2,1,"span",17),r(5,"span",18),s(6),i()(),r(7,"div",19)(8,"div",20),v(9,at,2,1,"app-chip",null,N),i(),f(11,st,3,0,"div",21)(12,pt,2,0,"p",22),i(),r(13,"div",23)(14,"span",24),s(15),i(),f(16,ct,2,0,"app-badge",25)(17,mt,2,1,"app-badge",26),i(),r(18,"div",27)(19,"app-button",28),d("click",function(){let l=x(e).$implicit,c=p(2);return C(c.confirmingRevoke.set(l))}),s(20,"Revoke"),i()()()}if(n&2){let e,o=t.$implicit,l=p(2);a(3),_(o.name),a(),g(o.description?4:-1),a(2),L(" Created ",l.date(o.createdAt)," \xB7 last used ",l.ago(o.lastUsedAt)," "),a(3),h(o.scopes),a(2),g(o.roles!=null&&o.roles.length?11:l.rolesApply(o.scopes)?12:-1),a(4),_(l.date(o.expiresAt)),a(),g((e=l.expiryState(o))==="expired"?16:e==="soon"?17:-1)}}function ut(n,t){if(n&1&&(r(0,"div",7)(1,"div",11)(2,"div",12),s(3,"Name"),i(),r(4,"div",12),s(5,"Scopes"),i(),r(6,"div",12),s(7,"Expires"),i(),b(8,"div"),i(),r(9,"div",13),v(10,dt,21,7,"div",14,et),i()()),n&2){let e=p();a(10),h(e.tokens())}}function _t(n,t){if(n&1){let e=k();r(0,"app-token-secret",33),d("closed",function(){x(e);let l=p(3);return C(l.closePanel())}),i()}n&2&&m("created",t)}function xt(n,t){if(n&1&&f(0,_t,1,1,"app-token-secret",32),n&2){let e,o=p(2);g((e=o.lastCreated())?0:-1,e)}}function Ct(n,t){if(n&1){let e=k();r(0,"app-token-create-form",34),d("created",function(l){x(e);let c=p(2);return C(c.onCreated(l))})("cancelled",function(){x(e);let l=p(2);return C(l.closePanel())}),i()}if(n&2){let e=p(2);m("maxDays",e.maxDays)}}function ft(n,t){if(n&1){let e=k();r(0,"app-panel",30),d("closed",function(){x(e);let l=p();return C(l.closePanel())}),f(1,xt,1,1)(2,Ct,1,1,"app-token-create-form",31),i()}if(n&2){let e,o=p();m("title",o.panelKind()==="secret"?((e=o.lastCreated())==null||e.token==null?null:e.token.name)??"Token":"New access token")("contentKey",o.panelKind()),a(),g(o.panelKind()==="secret"?1:2)}}function gt(n,t){if(n&1){let e=k();r(0,"app-dialog",35),d("closed",function(){x(e);let l=p();return C(l.confirmingRevoke.set(null))}),r(1,"p",36),s(2," The token stops working at once. Anything still using it will start failing. This can't be undone. "),i(),r(3,"div",37)(4,"app-button",38),d("click",function(){x(e);let l=p();return C(l.confirmingRevoke.set(null))}),s(5,"Cancel"),i(),r(6,"app-button",39),d("click",function(){let l=x(e),c=p();return C(c.revoke(l))}),s(7,"Revoke token"),i()()()}if(n&2){let e=p();m("title","Revoke "+t.name+"?"),a(6),m("loading",e.revoking())}}var Ie=class n{api=y(P);toast=y(G);names=y(xe);maxDays=X(y(U))?.maxLifetimeDays??1;tokens=u(null);error=u("");panelKind=u(null);lastCreated=u(null);confirmingRevoke=u(null);revoking=u(!1);panelTpl=W("panelTpl");scopeLabel=Ee;rolesApply=V;constructor(){this.names.ensure(),ke(this.panelKind,this.panelTpl,()=>this.closePanel()),this.load()}load(){this.api.list().subscribe({next:t=>{this.error.set(""),this.tokens.set(t)},error:t=>this.error.set(D(t,"Could not load your access tokens."))})}openCreate(){this.lastCreated.set(null),this.panelKind.set("create")}onCreated(t){this.lastCreated.set(t),this.panelKind.set("secret"),this.load()}closePanel(){this.panelKind.set(null),this.lastCreated.set(null)}revoke(t){this.revoking.set(!0),this.api.revoke(t.tokenId).subscribe({next:()=>{this.revoking.set(!1),this.confirmingRevoke.set(null),this.toast.success(`Revoked ${t.name}`),this.tokens.update(e=>(e??[]).filter(o=>o.tokenId!==t.tokenId))},error:e=>{this.revoking.set(!1),this.toast.error(D(e,"Could not revoke the token."))}})}expiryState(t){return we(t)}date(t){return Ce(t)}until(t){return fe(t)}ago(t){return Te(t)}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=T({type:n,selectors:[["app-tokens-page"]],viewQuery:function(e,o){e&1&&H(o.panelTpl,Ze,5),e&2&&q()},hostAttrs:[1,"flex","min-h-0","flex-1","flex-col"],decls:12,vars:4,consts:[["panelTpl",""],["pageHeader","","title","Access tokens","subtitle","Let scripts, CI jobs and command-line tools act as you, limited to the scopes you pick.","subtitleInfo","A token stops working when you revoke it, when it expires, or when your account is disabled.",3,"showHeaderSearch"],["headerActions","","size","lg",3,"click"],["name","plus",1,"h-4","w-4",3,"strokeWidth"],["tone","danger"],[1,"space-y-2"],["title","No access tokens yet"],[1,"overflow-x-auto"],[3,"title"],["sizeClass","h-16 w-full"],[1,"font-medium"],[1,"grid","min-w-[560px]","grid-cols-[minmax(0,1.2fr)_minmax(0,1fr)_8.5rem_6.5rem]"],[1,"px-4","py-2.5","ui-microlabel","text-text-secondary"],[1,"min-w-[560px]","overflow-hidden","rounded-lg","border","border-border","bg-card-bg"],["data-testid","token-row",1,"grid","grid-cols-[minmax(0,1.2fr)_minmax(0,1fr)_8.5rem_6.5rem]","items-start","border-t","border-border","text-sm","first:border-t-0"],[1,"min-w-0","px-4","py-3"],[1,"block","break-words","font-medium","tracking-[0.015em]","text-surface-foreground"],[1,"mt-0.5","block","break-words","text-xs","text-muted-foreground"],[1,"mt-1","block","text-xs","tabular-nums","text-muted-foreground"],[1,"px-4","py-3"],[1,"flex","flex-wrap","gap-1.5"],[1,"mt-1.5","flex","flex-wrap","gap-1.5"],[1,"mt-1.5","text-xs","text-muted-foreground"],[1,"whitespace-nowrap","px-4","py-3","text-xs","tabular-nums","text-muted-foreground"],[1,"block"],["tone","red",1,"mt-1","inline-block"],["tone","amber",1,"mt-1","inline-block"],[1,"flex","justify-end","px-4","py-2.5"],["variant","outline","size","sm",3,"click"],["tone","gray"],["size","lg",3,"closed","title","contentKey"],[3,"maxDays"],[3,"created"],[3,"closed","created"],[3,"created","cancelled","maxDays"],[3,"closed","title"],[1,"text-sm","text-muted-foreground"],[1,"mt-4","flex","justify-end","gap-2"],["variant","outline",3,"click"],["variant","danger",3,"click","loading"]],template:function(e,o){if(e&1){let l=k();r(0,"app-page")(1,"app-page-header",1)(2,"app-button",2),d("click",function(){return x(l),C(o.openCreate())}),b(3,"app-icon",3),s(4," Create token "),i()(),f(5,nt,2,1,"app-banner",4)(6,ot,3,0,"div",5)(7,it,4,0,"app-empty-state",6)(8,ut,12,0,"div",7),i(),z(9,ft,3,3,"ng-template",null,0,Q),f(11,gt,8,2,"app-dialog",8)}if(e&2){let l;a(),m("showHeaderSearch",!1),a(2),m("strokeWidth",2),a(2),g(o.error()?5:o.tokens()===null?6:o.tokens().length===0?7:8),a(6),g((l=o.confirmingRevoke())?11:-1,l)}},dependencies:[ee,E,w,be,ne,ge,Z,he,ve,ye,R,I,A],encapsulation:2})};export{Ie as TokensPageComponent};