|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package tfe |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "errors" |
| 9 | +) |
| 10 | + |
| 11 | +func getOrgEntitlements(client *Client, organizationName string) (*Entitlements, error) { |
| 12 | + ctx := context.Background() |
| 13 | + orgEntitlements, err := client.Organizations.ReadEntitlements(ctx, organizationName) |
| 14 | + if err != nil { |
| 15 | + return nil, err |
| 16 | + } |
| 17 | + if orgEntitlements == nil { |
| 18 | + return nil, errors.New("The organization entitlements are empty.") |
| 19 | + } |
| 20 | + return orgEntitlements, nil |
| 21 | +} |
| 22 | + |
| 23 | +func hasGlobalRunTasks(client *Client, organizationName string) (bool, error) { |
| 24 | + oe, err := getOrgEntitlements(client, organizationName) |
| 25 | + if err != nil { |
| 26 | + return false, err |
| 27 | + } |
| 28 | + return oe.GlobalRunTasks, nil |
| 29 | +} |
| 30 | + |
| 31 | +func hasPrivateRunTasks(client *Client, organizationName string) (bool, error) { |
| 32 | + oe, err := getOrgEntitlements(client, organizationName) |
| 33 | + if err != nil { |
| 34 | + return false, err |
| 35 | + } |
| 36 | + return oe.PrivateRunTasks, nil |
| 37 | +} |
| 38 | + |
| 39 | +func hasAuditLogging(client *Client, organizationName string) (bool, error) { |
| 40 | + oe, err := getOrgEntitlements(client, organizationName) |
| 41 | + if err != nil { |
| 42 | + return false, err |
| 43 | + } |
| 44 | + return oe.AuditLogging, nil |
| 45 | +} |
0 commit comments