@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) • 6.48 kB
JavaScript
import{a as O}from"./chunk-GK2T2SMO.js";import{c as I}from"./chunk-TOO3FEYQ.js";import{a as S}from"./chunk-XUEIITMC.js";import{b as G,c as j}from"./chunk-NTF5XIGH.js";import{d as E}from"./chunk-2SO4BVIT.js";import{a as T}from"./chunk-2BNLISUN.js";import{a as R}from"./chunk-7A4HO4AV.js";import{Aa as g,Ba as d,F as C,I as p,Ja as k,K as w,L as P,La as h,Na as f,R as l,Xa as _,Za as $,_ as u,ga as A,qb as b,sb as F,ta as D,tb as c,ua as M,za as m}from"./chunk-FYA6QUPZ.js";import{a as N}from"./chunk-WFIHWVQO.js";var V=class r{api=p(T);colors=l(new Map);inFlight=!1;lastFetched=0;ensure(){this.inFlight||Date.now()-this.lastFetched<5e3||(this.inFlight=!0,this.api.listAccounts().subscribe({next:t=>{let n=new Map;for(let e of t)for(let i of e.roles)i.color&&n.set(`${e.accountNumber}#${i.roleName}`,i.color);this.colors.set(n),this.inFlight=!1,this.lastFetched=Date.now()},error:()=>{this.inFlight=!1,this.lastFetched=Date.now()}}))}colorOf(t,n){return this.colors().get(`${t}#${n}`)??null}static \u0275fac=function(n){return new(n||r)};static \u0275prov=C({token:r,factory:r.\u0275fac,providedIn:"root"})};function L(r,t){if(r&1){let n=k();g(0,"app-grant-dialog",6),h("granted",function(i){w(n);let s=f();return P(s.grant(i.ids,i.durationHours))})("closed",function(){w(n);let i=f();return P(i.granting.set(!1))}),d()}if(r&2){let n=f();m("intro",n.intro())("options",n.options())("withDuration",n.principal().kind==="user")("busy",n.busy())}}var x="|",y=(r,t,n)=>[r,t,n].join(x),B=class r{api=p(S);store=p(I);principal=c.required();holder=c.required();assignments=c.required();capabilities=c([]);groupNames=c({});changed=F();granting=l(!1);busy=l(!1);catalog=l([]);constructor(){this.api.catalog().subscribe({next:t=>this.catalog.set(t.plugins),error:()=>this.catalog.set([])})}intro=b(()=>this.principal().kind==="group"?`${this.holder()} \u2014 every member gets this while they are in the group, long-term.`:`${this.holder()} \u2014 takes effect on their next request to the plugin.`);rows=b(()=>{let t=this.assignments().map(e=>this.row(e.pluginId,e.accountNumber,e.permission,e.available,e.reason,e)),n=new Set(t.map(e=>e.id));for(let e of this.capabilities())n.has(y(e.pluginId,e.accountNumber,e.permission))||this.groupsOf(e.pluginId,e.accountNumber,e.permission).length&&t.push(this.row(e.pluginId,e.accountNumber,e.permission,e.available,e.reason));return t});row(t,n,e,i,s,a){let o=this.catalog().find(q=>q.id===t),v=[{text:e,tone:"gray"}];return i||v.push({text:"dormant",tone:"amber",title:this.dormantReason(s)}),v.push(...this.whyBadges(a,this.groupsOf(t,n,e))),N({id:y(t,n,e),title:o?.displayName??t,subtitle:n,chipColor:O(n),pillClass:"role-chip",badges:v},a?{action:{label:"Revoke"}}:{})}groupsOf(t,n,e){let i=this.groupNames(),s=this.capabilities().find(o=>o.pluginId===t&&o.accountNumber===n&&o.permission===e);return[...new Set(s?.sources.flatMap(o=>o.groups)??[])].map(o=>i[o]??o).sort()}whyBadges(t,n){let e=n.map(i=>({text:`via ${i}`,tone:"gray",title:`Granted through the group ${i}`}));if(t){let i=this.principal().kind==="user"?"direct \xB7 ":"";e.unshift(t.expired?{text:`${i}expired`,tone:"amber",title:"Direct grant, expired \u2014 revoke to tidy it away"}:t.expiresAt?{text:`${i}expires ${E(t.expiresAt)}`,tone:"amber",title:"Direct grant, temporary"}:{text:`${i}long-term`,tone:"gray",title:"Direct grant, long-term"})}return e}options=b(()=>{let t=new Set(this.assignments().map(e=>y(e.pluginId,e.accountNumber,e.permission))),n=[];for(let e of this.catalog())if(e.status==="active"){for(let i of e.accounts)if(i.available)for(let s of e.permissions){let a=y(e.id,i.accountNumber,s.id);t.has(a)||n.push({id:a,label:`${e.displayName} \xB7 ${s.label}`,sublabel:s.implies.length?`includes ${s.implies.join(", ")}`:void 0,group:i.displayName?`${i.displayName} \xB7 ${i.accountNumber}`:i.accountNumber})}}return n});grant(t,n){this.busy.set(!0),this.granting.set(!1);let e=t.length;for(let i of t){let[s,a,o]=i.split(x);this.api.assign(s,a,this.principal(),o,n).subscribe({next:()=>this.done(--e),error:()=>this.done(--e)})}t.length||this.busy.set(!1)}revoke(t){let[n,e,i]=t.split(x);this.busy.set(!0),this.api.revoke(n,e,this.principal(),i).subscribe({next:()=>this.done(0),error:()=>this.done(0)})}done(t){t>0||(this.busy.set(!1),this.changed.emit(),this.store.refresh())}dormantReason(t){switch(t){case"plugin-disabled":return"The plugin is turned off in this deployment.";case"plugin-removed":return"The plugin was removed; the row is kept so its history stays readable.";case"plugin-unsupported":return"The plugin was built for a different version of the portal.";case"plugin-unknown":return"No such plugin is installed.";case"permission-undeclared":return"The plugin no longer offers this permission.";case"account-unbound":return"The plugin is no longer bound to this account.";case"account-unregistered":return"This account is not registered in the portal.";default:return"This assignment cannot authorize anything right now."}}static \u0275fac=function(n){return new(n||r)};static \u0275cmp=A({type:r,selectors:[["app-plugin-access-panel"]],inputs:{principal:[1,"principal"],holder:[1,"holder"],assignments:[1,"assignments"],capabilities:[1,"capabilities"],groupNames:[1,"groupNames"]},outputs:{changed:"changed"},decls:8,vars:4,consts:[[1,"mt-5","rounded-lg","border","border-border","px-5","pb-5","pt-2.5"],[1,"-ml-1.5","px-1.5","text-xs","font-medium","text-muted-foreground"],[1,"-mt-1","mb-2","flex","justify-end"],["variant","secondary","size","sm",3,"click","disabled"],["empty","No plugin access.",3,"action","rows"],["title","Grant plugin access","placeholder","Filter by plugin, account or permission","emptyText","Every available binding is already held.",3,"intro","options","withDuration","busy"],["title","Grant plugin access","placeholder","Filter by plugin, account or permission","emptyText","Every available binding is already held.",3,"granted","closed","intro","options","withDuration","busy"]],template:function(n,e){n&1&&(g(0,"fieldset",0)(1,"legend",1),_(2),d(),g(3,"div",2)(4,"app-button",3),h("click",function(){return e.granting.set(!0)}),_(5," \uFF0B Grant plugin access "),d()(),g(6,"app-access-list",4),h("action",function(s){return e.revoke(s)}),d()(),D(7,L,1,4,"app-grant-dialog",5)),n&2&&(u(2),$(" Plugins \xB7 ",e.assignments().length," "),u(2),m("disabled",!e.options().length),u(2),m("rows",e.rows()),u(),M(e.granting()?7:-1))},dependencies:[G,R,j],encapsulation:2,changeDetection:0})};export{V as a,B as b};