Skip to content

Commit

Permalink
chore: change owner_name to be email if the type is user (#147)
Browse files Browse the repository at this point in the history
* chore: change owner_name to be email if the type is user

* fix indentation
  • Loading branch information
atulatnirmata authored May 2, 2023
1 parent 4c577e9 commit d5cb956
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ resource "nirmata_cluster" "eks-eu" {

### owner_info
* `owner_type` - (Required) The type of the owner. Valid values are user or team.
* `owner_name` - (Required) The name of the user/team.
* `owner_name` - (Required) The email of the user or the name of the team.

### access_control_list
* `entity_type` - (Required) The type of entity. Valid values are user or team.
* `permission` - (Required) The permission. Valid values are admin, edit, view.
* `name` - (Required) The name of the user/team.
* `name` - (Required) The email of the user or the name of the team.
4 changes: 2 additions & 2 deletions docs/resources/cluster_eks_imported.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ resource "nirmata_cluster_imported" "eks-import" {

### owner_info
* `owner_type` - (Required) The type of the owner. Valid values are user or team.
* `owner_name` - (Required) The name of the user/team.
* `owner_name` - (Required) The email of the user or the name of the team.

### access_control_list
* `entity_type` - (Required) The type of entity. Valid values are user or team.
* `permission` - (Required) The permission. Valid values are admin, edit, view.
* `name` - (Required) The name of the user/team.
* `name` - (Required) The email of the user or the name of the team.
4 changes: 2 additions & 2 deletions docs/resources/cluster_eks_registered.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ resource "kubectl_manifest" "test" {

### owner_info
* `owner_type` - (Required) The type of the owner. Valid values are user or team.
* `owner_name` - (Required) The name of the user/team.
* `owner_name` - (Required) The email of the user or the name of the team.

### access_control_list
* `entity_type` - (Required) The type of entity. Valid values are user or team.
* `permission` - (Required) The permission. Valid values are admin, edit, view.
* `name` - (Required) The name of the user/team.
* `name` - (Required) The email of the user or the name of the team.
4 changes: 2 additions & 2 deletions docs/resources/cluster_gke_imported.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ resource "nirmata_cluster_imported" "gke-import-1" {

### owner_info
* `owner_type` - (Required) The type of the owner. Valid values are user or team.
* `owner_name` - (Required) The name of the user/team.
* `owner_name` - (Required) The email of the user or the name of the team.

### access_control_list
* `entity_type` - (Required) The type of entity. Valid values are user or team.
* `permission` - (Required) The permission. Valid values are admin, edit, view.
* `name` - (Required) The name of the user/team.
* `name` - (Required) The email of the user or the name of the team.

### vault_auth

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/cluster_kind_registered.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ cluster_ca_certificate = "LS0tLS1CRUdJTiB..."

### owner_info
* `owner_type` - (Required) The type of the owner. Valid values are user or team.
* `owner_name` - (Required) The name of the user/team.
* `owner_name` - (Required) The email of the user or the name of the team.

### access_control_list
* `entity_type` - (Required) The type of entity. Valid values are user or team.
* `permission` - (Required) The permission. Valid values are admin, edit, view.
* `name` - (Required) The name of the user/team.
* `name` - (Required) The email of the user or the name of the team.



23 changes: 21 additions & 2 deletions examples/register/aks/aks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ resource "nirmata_cluster_registered" "aks-registered" {
name = "aks-cluster"
cluster_type = "default-add-ons"
endpoint = "https://endpoint"
owner_info {
owner_type = "team"
owner_name = "team1"
}
access_control_list {
entity_type = "user"
permission = "admin"
name = "user1@myorg.com"
}
access_control_list {
entity_type = "team"
permission = "view"
name = "team2"
}
access_control_list {
entity_type = "user"
permission = "edit"
name = "user2@myorg.com"
}
}

# Retrieve AKS cluster information
Expand All @@ -21,8 +40,8 @@ provider "azurerm" {
}

data "azurerm_kubernetes_cluster" "cluster" {
name = "tf-test"
resource_group_name = "tf-test-group"
name = "test-01"
resource_group_name = "test-0_group"
}

provider "kubectl" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/nirmata/api_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func getPolicyDeployGroupStatus(api client.Client, ID client.ID) (string, error)

func getUsers(api client.Client) ([]map[string]interface{}, error) {
opts := &client.GetOptions{}
opts.Fields = []string{"id", "name", "modelIndex", "service"}
opts.Fields = []string{"id", "name", "email", "modelIndex", "service"}
objs, err := api.GetCollection(client.ServiceUsers, "User", opts)
if err != nil {
log.Printf("[ERROR] Failed to fetch users: %v", err)
Expand Down
8 changes: 7 additions & 1 deletion pkg/nirmata/resource_cluster_registered.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ func fetchOwnerId(owner_type, owner_name string, users, teams []map[string]inter
data = teams
}
for _, d := range data {
if owner_name == d["name"] {
var name string
if owner_type == "user" {
name = d["email"].(string)
} else {
name = d["name"].(string)
}
if owner_name == name {
id := d["id"].(string)
log.Printf("[DEBUG] - Found match for owner_name %s with id %s", owner_name, id)
return id, nil
Expand Down

0 comments on commit d5cb956

Please # to comment.