CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
IamPolicyVisualizer-D_8gW7AF.js6 linesDownload Raw Back to assets
1import{r as l,j as e}from"./react-CIdJ77ke.js";import{e as I}from"./googleApiService-B4BzT3uR.js";import{aa as A,l as O,u as M,aG as $,S as z}from"./index-CX7Qxd1D.js";import"./@braintree-DzxiOROe.js";import"./react-dom-R9L8nDNe.js";import"./scheduler-CoSDG3-6.js";import"./@google-CcUHq7Ay.js";import"./idb-Dob3nYDb.js";import"./marked-BrGMJkBT.js";import"./mermaid-KwKZWwy0.js";import"./dayjs-CeEF-NGT.js";import"./d3-transition-CiCB8KJE.js";import"./d3-timer-DdKHrDhs.js";import"./d3-dispatch-kxCwF96_.js";import"./d3-interpolate-CtIaNujU.js";import"./d3-color-amxIadob.js";import"./d3-selection-C52G7wmG.js";import"./d3-ease-DRPgKoYJ.js";import"./d3-zoom-BYoC3mS3.js";import"./dompurify-J5RlrwSC.js";import"./dagre-d3-es-CTpFWynZ.js";import"./lodash-es-Dt6r0yiR.js";import"./d3-shape-CX8xTzfR.js";import"./d3-path-CimkQT29.js";import"./d3-fetch-BOsq7VnW.js";import"./khroma-DUX6PT6k.js";import"./uuid-DhYbOkY1.js";import"./d3-scale-DRZz3QW5.js";import"./internmap-BkD7Hj8s.js";import"./d3-array-DGRYoJHh.js";import"./d3-format-CzD4bSOQ.js";import"./d3-time-format-CUNN4Ell.js";import"./d3-time-6cSPyVSY.js";import"./d3-axis-DSWTncID.js";import"./elkjs-oKFFZvz7.js";import"./cytoscape-DtBltrT8.js";import"./cytoscape-cose-bilkent-Cgr1thlj.js";import"./cose-base-CwCxnKwh.js";import"./layout-base-CMXQqlmj.js";import"./d3-sankey-DgqkLiUE.js";import"./d3-scale-chromatic-B-NsZVaP.js";import"./ts-dedent-DrFu-skq.js";import"./stylis-D5iaQeiq.js";import"./mdast-util-from-markdown-CLAsVoWb.js";import"./micromark-CTBPIv-_.js";import"./micromark-util-combine-extensions-Bka6Sc1c.js";import"./micromark-util-chunked-DrRIdSP-.js";import"./micromark-factory-space-x2vfxbz5.js";import"./micromark-util-character-Bcm1tP9o.js";import"./micromark-core-commonmark-AH8VCgT7.js";import"./micromark-util-classify-character-Cq7Fg3xE.js";import"./micromark-util-resolve-all-PQCKh0dx.js";import"./decode-named-character-reference-C3-224fz.js";import"./micromark-util-subtokenize-QwsxNXk2.js";import"./micromark-factory-destination-CypD_wgM.js";import"./micromark-factory-label-CRHH4ZHP.js";import"./micromark-factory-title-B7kCBvC9.js";import"./micromark-factory-whitespace-B322EA6O.js";import"./micromark-util-normalize-identifier-C9ANKk3v.js";import"./micromark-util-html-tag-name-DbKNfynz.js";import"./micromark-util-decode-numeric-character-reference-DRnCnno4.js";import"./micromark-util-decode-string-DJl8Y_PO.js";import"./unist-util-stringify-position-Ch_qCilz.js";import"./mdast-util-to-string-C_aolqmU.js";import"./jszip-CFFhfFtd.js";import"./octokit-B6bKu3NB.js";import"./@octokit-MBEWYTsi.js";import"./bottleneck-D_vuF9V7.js";import"./universal-user-agent-CLgqIJsR.js";import"./before-after-hook-y8XtM9xW.js";import"./fast-content-type-parse-3SwieiST.js";const D=async(r,i)=>A("gcp.testIamPermissions",async()=>{try{if(!await I())throw new Error("Google API client not ready.");const s=r.startsWith("//")?r.substring(2):r;return(await gapi.client.iam.permissions.testIamPermissions({resource:s,resource_body:{permissions:i}})).result}catch(a){O(a,{service:"gcpService",function:"testIamPermissions",resource:r});const s=a;throw s.result?.error?.message?new Error(`GCP API Error: ${s.result.error.message}`):a}}),w={Viewer:["resourcemanager.projects.get","storage.objects.list","compute.instances.list"],Editor:["storage.objects.create","storage.objects.delete","compute.instances.start","compute.instances.stop"],"Storage Object Admin":["storage.objects.create","storage.objects.delete","storage.objects.get","storage.objects.list","storage.objects.update"]},V=r=>r.includes("/projects/")?"project":r.includes("/b/")?"bucket":r.includes("/instances/")?"instance":"unknown",st=()=>{const{state:r}=M(),[i,a]=l.useState([]),[s,p]=l.useState("//cloudresourcemanager.googleapis.com/projects/your-gcp-project-id"),[u,f]=l.useState(`storage.objects.get2storage.objects.create`),[N,y]=l.useState("idle"),[v,g]=l.useState(""),[m,x]=l.useState(null),d=l.useMemo(()=>u.split(`3`).map(t=>t.trim()).filter(Boolean),[u]),S=()=>{s.trim()&&!i.find(t=>t.id===s)&&(a(t=>[...t,{id:s,name:s.split("/").pop()||s,type:V(s),status:"neutral"}]),p(""))},P=l.useCallback(async()=>{if(!r.user){g("You must be signed in to run a simulation.");return}if(i.length===0||d.length===0){g("Please add at least one resource and one permission.");return}y("running"),g(""),x(null),a(c=>c.map(o=>({...o,status:"pending",results:[]})));const t=i.map(c=>D(c.id,d).then(o=>({id:c.id,success:!0,data:o})).catch(o=>({id:c.id,success:!1,error:o}))),k=await Promise.allSettled(t);a(c=>c.map(o=>{const b=k.find(n=>n.value?.id===o.id);if(!b||!b.value.success)return{...o,status:"fail"};const R=b.value.data.permissions||[],h=d.map(n=>({permission:n,granted:R.includes(n)})),E=h.every(n=>n.granted),G=h.every(n=>!n.granted);let j="partial";return E&&(j="success"),G&&(j="fail"),{...o,status:j,results:h}})),y("completed")},[i,d,r.user]),C={neutral:"border-slate-600",pending:"border-yellow-500 animate-pulse",success:"border-green-500",fail:"border-red-500",partial:"border-orange-500"};return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary bg-background",children:[m&&e.jsx("div",{className:"fixed inset-0 bg-black/60 z-50 flex items-center justify-center",onClick:()=>x(null),children:e.jsxs("div",{className:"bg-surface rounded-lg shadow-xl p-6 w-full max-w-lg animate-pop-in",onClick:t=>t.stopPropagation(),children:[e.jsx("h3",{className:"text-lg font-bold truncate",children:m.name}),e.jsx("p",{className:"text-xs text-text-secondary font-mono mb-4",children:m.id}),e.jsx("ul",{className:"space-y-2 max-h-96 overflow-y-auto",children:m.results?.map(t=>e.jsxs("li",{className:`flex items-center justify-between p-2 rounded text-sm ${t.granted?"bg-green-500/10":"bg-red-500/10"}`,children:[e.jsx("span",{className:"font-mono",children:t.permission}),e.jsx("span",{className:`font-bold ${t.granted?"text-green-500":"text-red-500"}`,children:t.granted?"GRANTED":"DENIED"})]},t.permission))})]})}),e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center",children:[e.jsx($,{}),e.jsx("span",{className:"ml-3",children:"GCP IAM Policy Visualizer"})]}),e.jsx("p",{className:"text-text-secondary mt-1",children:"Visually test and audit GCP IAM permissions in real-time across your resources."})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-1 lg:grid-cols-3 gap-6 min-h-0",children:[e.jsxs("aside",{className:"lg:col-span-1 bg-surface p-4 rounded-lg border border-border flex flex-col gap-4",children:[e.jsx("h3",{className:"text-xl font-bold",children:"Simulation Controls"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-semibold",children:"1. Add Resource"}),e.jsxs("div",{className:"flex gap-1 mt-1",children:[e.jsx("input",{value:s,onChange:t=>p(t.target.value),placeholder:"Full GCP resource name...",className:"flex-grow p-2 bg-background border rounded text-xs"}),e.jsx("button",{onClick:S,className:"btn-primary px-3 text-sm",children:"+"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-semibold",children:"2. Define Permission Set"}),e.jsxs("select",{onChange:t=>f(w[t.target.value]?.join(`4`)||""),className:"w-full mt-1 p-2 bg-background border rounded text-xs mb-1",children:[e.jsx("option",{children:"Load common role..."}),Object.keys(w).map(t=>e.jsx("option",{children:t},t))]}),e.jsx("textarea",{value:u,onChange:t=>f(t.target.value),placeholder:"One permission per line...",className:"w-full h-32 p-2 bg-background border rounded text-xs font-mono"})]}),e.jsxs("button",{onClick:P,disabled:N==="running",className:"btn-primary py-3 flex items-center justify-center gap-2",children:[e.jsx(z,{})," ",N==="running"?"Simulating...":"Run Simulation"]}),v&&e.jsx("p",{className:"text-red-500 text-xs text-center",children:v})]}),e.jsxs("main",{className:"lg:col-span-2 bg-gray-50 dark:bg-slate-900/50 rounded-lg p-4 border-2 border-dashed border-border overflow-auto relative",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4",children:i.map(t=>e.jsxs("div",{onClick:()=>t.results&&x(t),className:`p-4 bg-surface rounded-lg border-4 transition-colors duration-500 ${C[t.status]} ${t.results?"cursor-pointer hover:scale-105":""}`,children:[e.jsx("h4",{className:"font-bold truncate",children:t.name}),e.jsx("p",{className:"text-xs text-text-secondary capitalize",children:t.type})]},t.id))}),i.length===0&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-text-secondary",children:"Add resources to begin your simulation."})]})]})]})};export{st as IamPolicyVisualizer};5//# sourceMappingURL=IamPolicyVisualizer-D_8gW7AF.js.map6