1import{j as e,b as se,s as ie,i as K,d as le,O as W,V as N,Q as re,U as ce,dd as de,M as me,b1 as ue,N as k,dT as pe,ah as xe,m9 as he,cn as ge,C as fe}from"./index-ChxFcAuc.js";import{d as we,a as l}from"./vendor-core-C0v-OB8t.js";import{Q as y,u as ye,F as I,bX as je}from"./App-B3uEhegP.js";import{a as Ce,S as E,A as V}from"./AMAddUpdatePolicyModal-DBRmXt8q.js";import{C as ke}from"./CloudLoader-czquIfzp.js";import{F as f}from"./FormHorizontalFieldGroup-CJ0Vs0dE.js";import{R}from"./Radio-CuOBtoku.js";import{A as q}from"./aws-C7r99lL2.js";import{h as Ae}from"./main-Bgx8rRqW.js";import{u as be}from"./useSubmitAMAddUpdate-Boq0UmoD.js";import{C as _e}from"./CustomSelectPopup-C2J2KYZm.js";import{S as Se}from"./SelectedItem-Bwn-L4U8.js";import{C as Ne}from"./CustomSelectOption-CNy0WMKq.js";import{u as Ie}from"./useFetchRegionsCost-CIXZB8dV.js";import{w as Re}from"./withBackBtn-BONWhaYS.js";import{m as Te}from"./aws-connect-CNqsGt_d.js";import{A as ze}from"./AMManualPopup-CDckMpCt.js";import{B as Be}from"./BlockHeader-BPNKvwRz.
1js";import{B as Oe}from"./BlockContent-DLwhzrem.js";import{a as Le}from"./main-B_G75NJ-.js";import"./vendor-ant-ui-DEh1p71x.js";import"./CodeBlock-GR_VrOKS.js";import"./useGetEnvsData-DkXREWrz.js";import"./PulsatingCircleAlarm-C5WCZoxH.js";const ve="description_HI7Sj",Me="radioWrapper_fR04a",We="radio_mMPa9",Ee="radioText_ngwyW",Fe="radioCaption_b9Hoc",Ue="stackButtons_eT7aB",Pe="policy_IE-9I",Ye="policyIcon_Qm27I",He="policyText_KAMte",n={description:ve,radioWrapper:Me,radio:We,radioText:Ee,radioCaption:Fe,stackButtons:Ue,policy:Pe,policyIcon:Ye,policyText:He},Ge=({onClose:A,mode:x})=>{const i=[{text:"Main CF stack will run.",link:{text:"Template ",href:"https://uniskai-eu-templates.s3.eu-central-1.amazonaws.com/role_lambda.json"}},{text:"Lambda function will be created from main stack.",link:{text:"Code ",href:"https://uniskai-lambdas.s3.amazonaws.com/cf_lambda_code.zip"}},{text:"CUR bucket stack will run from lambda function if necessary.",link:{text:"Template ",href:"https://uniskai-eu-templates.s3.eu-central-1.amazonaws.com/role_curbucket.json"}},{text:"Connection role stack will run from lambda function.",link:{text:"Template ",href:{read:"https://uniskai-eu-templates.s3.eu-central-1.amazonaws.com/role_readonly.json",write:"https://uniskai-eu-templates.s3.eu-central-1.amazonaws.com/role_readwrite.json"}[x]}}];return e.jsx(y,{onClose:A,children:e.jsxs(y.Content,{style:{height:"100%",maxWidth:360,margin:"0px 50px"},children:[e.jsx(y.Title,{children:"Review Steps"}),e.jsx(y.Description,{style:{display:"flex",flexDirection:"column",alignItems:"flex-start",gap:12,textAlign:"left"},children:i.map((m,c)=>e.jsxs("p",{children:[c+1,". ",m.text," ",e.jsxs("a",{href:m.link.href,target:"_blank",children:[m.link.text," ",e.jsx(Ce,{})]})]}))})]})})},$e=({bucketName:A,stsData:x,envData:a,mode:i,setMode:m,connection:c,setConnection:h})=>{var Q;const{environments:T,organizations:j}=se(t=>({environments:t.aws.entities.environments,organizations:t.organizations}),ie),{handleAdd:z,handleUpdate:b}=be(),{showNotification:w}=ye(),C=K(),g=we(),X=t=>{const o={},{arn:r,name:u}=t;return u.length>q.maxEnvNameLength&&(o.name=`Max length is ${q.maxEnvNameLength}`),r||(o.arn="Please enter role arn"),o},B=le().id,[J,F]=l.useState(!1),[O,U]=l.useState(null),[Z,P]=l.useState(!1),[D,Y]=l.useState(!1);l.useEffect(()=>{let t,o=!1;return O&&(t=window.setInterval(async()=>{var u;const r=await W.getAWSAccountConnectionStatus({wait_token:O});if(r.ok){const{completed:S}=r.data;if(P(!S),S){if(o=!0,T.allIds.includes(r.data.id)){const s=r.data.organization.id;if(a)w({status:N.good,text:"Access was changed successful"});else{const d=s===B?"current oraganization.":((u=j.items.find(p=>p.id===s))==null?void 0:u.name)+" oraganization.";w({status:N.info,text:`Account already exist in ${d}`})}}else w({status:N.good,text:"Account successfully added."});U(null),await C(re()),await C(ce.getOrganizations()),g("/cabinet/accounts")}}else o||w({status:N.bad,text:"Something went wrong."})},10*1e3)),()=>{clearInterval(t)}},[O]);const[H,_]=l.useState(!1),[ee,G]=l.useState(!1),[te,ae]=l.useState(!1),ne=()=>window.open(Ae()),L=de({hasGlobal:!1,envId:a==null?void 0:a.id});Ie({envIds:a!=null&&a.id?[a==null?void 0:a.id]:null});const v=l.useMemo(()=>a&&L?L.filter(t=>t.active).map(t=>({region_code:t.value,region_name:t.name,full_name:t.name+" | "+t.value})):me.map(t=>({region_code:t.RegionName,region_name:t.FullName,full_name:t.FullName+" | "+t.RegionName})),[L,a]),$=t=>{var o;return(o=v.find(r=>r.full_name===t))==null?void 0:o.region_code},oe=()=>v.find(t=>t.region_code==="us-east-1");return e.jsxs(e.Fragment,{children:[e.jsx(ue,{initialValues:{arn:"",externalId:x.external_id,accountId:x.account_id,name:(a==null?void 0:a.name)||"",save:!0,full_region_name:((Q=oe())==null?void 0:Q.full_name)||""},validate:X,onSubmit:async(t,{setStatus:o})=>{const r={auth_data:{role_arn:t.arn,external_id:t.externalId},name:t.name||"",provider:xe.aws,save_credentials:t.save,auth_type:"sts",organization:B,region_code:$(t.full_region_name)};a?await b({id:a.id,data:r,setStatus:o}):await z({data:r,setStatus:o})},children:({isSubmitting:t,status:o,submitForm:r,values:u,setFieldValue:S,errors:M})=>e.jsxs(e.Fragment,{children:[o&&e.jsx(f,{label:"",children:e.jsx("div",{style:{marginBottom:8,color:"red"},children:o})}),e.jsx(f,{label:"Account name",children:e.jsx(I,{name:"name",inputStyle:{width:360},placeholder:"e.g. AWS Stage",disabled:!!a,showError:!!M.name})}),e.jsx(f,{label:"Access",style:{alignItems:"flex-start"},children:e.jsxs("div",{className:n.radios,children:[e.jsxs("div",{className:n.radioWra
1pper,children:[e.jsxs("div",{className:n.radio,onClick:()=>m("write"),children:[e.jsx(R,{style:{marginRight:0},value:"write",checked:i==="write",onChange:()=>m("write"),name:"write"}),e.jsx("p",{className:n.radioText,children:"Read/write"})]}),e.jsx("p",{className:n.radioCaption,children:"You will be able to actively save money and fix all issues"})]}),e.jsxs("div",{className:n.radioWrapper,children:[e.jsxs("div",{className:n.radio,onClick:()=>m("read"),children:[e.jsx(R,{style:{marginRight:0},value:"read",checked:i==="read",onChange:()=>m("read"),name:"read"}),e.jsx("p",{className:n.radioText,children:"Read-only"})]}),e.jsx("p",{className:n.radioCaption,children:"You will get full visibility of your cloud environment and optimization insights"})]})]})}),e.jsx(f,{label:"Connection",style:{alignItems:"flex-start"},children:e.jsxs("div",{className:n.radios,children:[e.jsxs("div",{className:n.radioWrapper,children:[e.jsxs("div",{className:n.radio,onClick:()=>h("cloudformation"),children:[e.jsx(R,{style:{marginRight:0},value:"cloudformation",checked:c==="cloudformation",onChange:()=>h("cloudformation"),name:"cloudformation"}),e.jsx("p",{className:n.radioText,children:"CloudFormation stack"})]}),e.jsx("p",{className:n.radioCaption,children:"ARN-role will be automatically created by CloudFormation stack"}),c==="cloudformation"&&e.jsxs("div",{children:[e.jsx("div",{style:{marginTop:10},children:te?e.jsx(_e,{renderInitiator:(s,d)=>e.jsx(Se,{opened:d,onClick:s,text:u.full_region_name||"Select region",size:{width:"360px",height:"48px"},grey:!0}),items:v.map(s=>({value:s.full_name,label:s.full_name})),searchParameter:s=>s.label,renderCustomSelectOption:(s,d)=>e.jsx(Ne,{value:s.value,label:s.label,onClick:p=>{S("full_region_name",s.value),d()}}),popup:{top:!0,left:!0,width:"360px",maxHeight:"200px"}}):e.jsxs("p",{children:["A CUR bucket will be created in ",e.jsx("b",{children:u.full_region_name})," ","if necessary."," ",e.jsx("a",{onClick:()=>{ae(!0)},children:"Change region"})]})}),e.jsxs("div",{className:n.stackButtons,children:[e.jsx(k,{size:"small",text:"Review policy",type:"transparent",onClick:()=>_(!0),renderLeft:()=>e.jsx(E,{className:n.policyIcon})}),e.jsx(k,{size:"small",text:"Review steps",type:"transparent",onClick:()=>G(!0),renderLeft:()=>e.jsx(E,{className:n.policyIcon})}),H&&e.jsx(V,{title:i==="read"&&"Read-only policy"||i==="write"&&"Read/write policy"||"",mode:i,onClose:()=>_(!1)}),ee&&e.jsx(Ge,{onClose:()=>G(!1),mode:i})]})]})]}),e.jsxs("div",{className:n.radioWrapper,children:[e.jsxs("div",{className:n.radio,onClick:()=>h("manual"),children:[e.jsx(R,{style:{marginRight:0},value:"manual",checked:c==="manual",onChange:()=>h("manual"),name:"manual"}),e.jsx("p",{className:n.radioText,children:"Manual"})]}),e.jsx("p",{className:n.radioCaption,children:"You will get full control of creating policy and ARN-role. Use External ID and Account ID bellow"}),c==="manual"&&e.jsxs(e.Fragment,{children:[e.jsx(I,{name:"externalId",inputStyle:{width:360},label:"External ID",style:{display:"block",marginBottom:12},disabled:!0,copy:!0}),e.jsx(I,{name:"accountId",inputStyle:{width:360},label:"Account ID",style:{display:"block",marginBottom:12},disabled:!0,copy:!0}),e.jsxs("div",{className:n.stackButtons,children:[e.jsx(k,{text:"Open AWS CONSOLE",type:"blue",size:"small",onClick:ne}),e.jsxs("div",{className:n.policy,onClick:()=>_(!0),children:[e.jsx(E,{className:n.policyIcon}),e.jsx("p",{className:n.policyText,children:"Review policy"})]}),H&&e.jsx(V,{title:i==="read"&&"Read-only policy"||i==="write"&&"Read/write policy"||"",mode:i,onClose:()=>_(!1)})]})]})]})]})}),c==="cloudformation"&&e.jsxs(f,{label:"",children:[e.jsx("span",{}),e.jsx(k,{text:"Launch now",type:"blue",size:"medium",submitting:J,disabled:!u.full_region_name.length&&c==="cloudformation"||!!M.name,onClick:async()=>{const s={read:"ro",write:"rw"};F(!0);const d=await W.getCloudFormationStackConnectionUrl({orgId:B,name:u.name,cur_bucket_region:$(u.full_region_name),mode:s[i]});if(F(!1),d.status===200&&d.data.connection_url.length&&(window.open(d.data.connection_url),d.data.wait_token)){U(d.data.wait_token);const p=await W.getAWSAccountConnectionStatus({wait_token:d.data.wait_token});p.status===200&&(P(!p.data.completed),Y(!p.data.completed),p.data.completed&&p.data.existing&&C(pe.setShowExistingAccountModalData({existingName:p.data.name,provider:p.data.provider,accountId:p.data.account_id})))}}})]}),c!=="cloudformation"&&e.jsxs(f,{label:"Role ARN",style:{alignItems:"flex-start"},children:[e.jsx("p",{style:{marginBottom:8},children:"Paste created role to field bellow"}),e.jsx(I,{name:"arn",placeholder:"e.g. arn:aws:iam::867020061529:role/PSLabs",inputStyle:{width:360}})]}),c!=="cloudformation"&&e.jsx(f,{label:"",children:e.jsx(k,{text:"Connect account",type:"blue",size:"medium",style:{width:200},onClick:r,disabled:u.arn.length===0,submitting:t})})]})}),Z&&D&&e.jsx(y,{onClose:()=>{Y(!1)},closeOnlyOnCloseButtonClick:!0,children:e.jsxs(y.Content,{children:[e.jsx(ke,{}),e.jsx("p",{style:{fontSize:"18px"},children:"Account connecting right now"})]})})]})},Qe=({bucketName:A,envData:x,mode:a})=>{const i=K(),[m,c]=l.useState(null);l.useEffect(()=>{(async()=>{const g=await i(he());g!=null&&g.data&&c(g==null?void 0:g.data)})()},[]);const[h,T]=l.useState(a&&a!=="change"?a:"write"),[j,z]=l.useState("cloudformation"),b=l.useMemo(()=>Le[j][h],[j,h]),{showIntercomArticle:w}=je(b),C=()=>
1{if(a){if(a==="write")return"Switch to read/write";if(a==="read")return"Switch to read-only"}return x?"Update account":"Cross-account role connection"};return m?e.jsxs(ge,{style:{flex:1},children:[e.jsx(Be,{headerTitle:C()}),e.jsxs(Oe,{children:[e.jsx("p",{className:n.description,children:a?`You need to reconnect ${x==null?void 0:x.name} with new ARN-role. Itâs easy. `:"You can grant read-only or read/write access. You can switch between access modes and/or cancel the connection at any time. "}),e.jsx($e,{bucketName:A,stsData:m,envData:x,mode:h,setMode:T,connection:j,setConnection:z}),e.jsx(ze,{moreThan1Manual:!0,position:{bottom:"30px",right:"50px"},popupPosition:{bottom:"10px",right:"0px"},image:Te,title:"Cross-account role connection ",description:"Learn how to grant secure access to your AWS account.",onClick:()=>w(b)})]})]}):e.jsx(fe,{})},ft=Re(Qe);export{ft as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.