microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
flowey/flowey_lib_common/src/ado_task_nuget_authenticate.rs
58lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | //! ADO Task Wrapper: `NuGetAuthenticate@1` |
| 5 | |
| 6 | use flowey::node::prelude::*; |
| 7 | |
| 8 | flowey_request! { |
| 9 | pub enum Request { |
| 10 | EnsureAuth(WriteVar<SideEffect>), |
| 11 | ServiceConnection(String), |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | new_flow_node!(struct Node); |
| 16 | |
| 17 | impl FlowNode for Node { |
| 18 | type Request = Request; |
| 19 | |
| 20 | fn imports(_ctx: &mut ImportCtx<'_>) {} |
| 21 | |
| 22 | fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> { |
| 23 | let mut ensure_auth = Vec::new(); |
| 24 | let mut all_service_connections = Vec::new(); |
| 25 | |
| 26 | for req in requests { |
| 27 | match req { |
| 28 | Request::EnsureAuth(v) => ensure_auth.push(v), |
| 29 | Request::ServiceConnection(conn) => all_service_connections.push(conn), |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | let ensure_auth = ensure_auth; |
| 34 | let all_service_connections = all_service_connections; |
| 35 | |
| 36 | // -- end of req processing -- // |
| 37 | |
| 38 | if ensure_auth.is_empty() { |
| 39 | return Ok(()); |
| 40 | } |
| 41 | |
| 42 | ctx.emit_ado_step("Authenticate to NuGet feeds", move |ctx| { |
| 43 | ensure_auth.claim(ctx); |
| 44 | move |_| { |
| 45 | format!( |
| 46 | r#" |
| 47 | - task: NuGetAuthenticate@1 |
| 48 | inputs: |
| 49 | nuGetServiceConnections: {} |
| 50 | "#, |
| 51 | all_service_connections.join(",") |
| 52 | ) |
| 53 | } |
| 54 | }); |
| 55 | |
| 56 | Ok(()) |
| 57 | } |
| 58 | } |
| 59 | |