Skip to content

Commit

Permalink
Merge pull request #1142 from CompositionalIT/fix-1141
Browse files Browse the repository at this point in the history
Update to newer az structure.
  • Loading branch information
isaacabraham authored Oct 26, 2024
2 parents fae51b8 + d94f4ee commit cc02ad0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Release Notes
=============
## vNext
* Az: Update `ad` commands to work with latest (breaking) structure.
* PostgreSQL: Fix a number of issues around the introduction of Flexible Servers.

## 1.9.2
Expand Down
47 changes: 22 additions & 25 deletions src/Farmer/Builders/Builders.KeyVault.fs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ type AccessPolicyBuilder() =
let accessPolicy = AccessPolicyBuilder()

type AccessPolicy =
static let createFilter searchField values =
let query =
values
|> Seq.map (fun value -> $"{searchField} eq '{value}'")
|> String.concat " or "

$"\"{query}\""

static let handleSearchResponse =
Serialization.ofJson<{| DisplayName: string; Id: Guid |} array>
>> Array.map (fun r -> {| r with Id = ObjectId r.Id |})

/// Quickly creates an access policy for the supplied Principal. If no permissions are supplied, defaults to GET and LIST.
static member create(principal: PrincipalId, ?permissions) = accessPolicy {
object_id principal
Expand All @@ -375,36 +387,21 @@ type AccessPolicy =
secret_permissions (permissions |> Option.defaultValue Secret.ReadSecrets)
}

static member private findEntity(searchField, values, searcher) =
values
|> Seq.map (sprintf "%s eq '%s'" searchField)
|> String.concat " or "
|> sprintf "\"%s\""
|> searcher
|> Result.map (
Serialization.ofJson<
{|
DisplayName: string
ObjectId: Guid
|} array
>
)
|> Result.toOption
|> Option.map (
Array.map (fun r -> {|
r with
ObjectId = ObjectId r.ObjectId
|})
)
|> Option.defaultValue Array.empty

/// Locates users in Azure Active Directory based on the supplied email addresses.
static member findUsers emailAddresses =
AccessPolicy.findEntity ("mail", emailAddresses, Deploy.Az.searchUsers)
let filter = createFilter "mail" emailAddresses

Deploy.Az.searchUsers filter
|> Result.map handleSearchResponse
|> Result.defaultValue Array.empty

/// Locates groups in Azure Active Directory based on the supplied group names.
static member findGroups groupNames =
AccessPolicy.findEntity ("displayName", groupNames, Deploy.Az.searchGroups)
let filter = createFilter "displayName" groupNames

Deploy.Az.searchGroups filter
|> Result.map handleSearchResponse
|> Result.defaultValue Array.empty

[<RequireQualifiedAccess>]
type SimpleCreateMode =
Expand Down
3 changes: 3 additions & 0 deletions src/Farmer/Result.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module Result =
| Ok s -> Some s
| Error _ -> None

let defaultValue defaultValue =
toOption >> Option.defaultValue defaultValue

let ignore result = Result.map ignore result

let sequence results =
Expand Down

0 comments on commit cc02ad0

Please sign in to comment.