-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from BESTSELLER/ES-984-Refactoring
Es 984 refactoring
- Loading branch information
Showing
10 changed files
with
310 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Resource: harbor_project_member_group | ||
|
||
## Example Usage | ||
``` | ||
resource "haror_project" "main" { | ||
name = "main" | ||
} | ||
resource "harbor_project_member_group" "main" { | ||
project_id = harbor_project.main.id | ||
name = "testing1" | ||
role = "master" | ||
type = "oidc" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
The following arguments are supported: | ||
|
||
* **name** - (Required) The name of the member entity | ||
|
||
* **project_id** - (Required) The project id of the project that the entity will have access to. | ||
|
||
* **role** - (Required) The premissions that the entity will be granted. | ||
|
||
* **type** - (Requried) The group type. Can be set to **"ldap"**, **"internal"** or **"oidc"** | ||
|
||
`NOTE: odic group type can only be used with harbor version v1.10.1 and above` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Resource: harbor_project_member_user | ||
|
||
## Example Usage | ||
``` | ||
resource "haror_project" "main" { | ||
name = "main" | ||
} | ||
resource "harbor_project_member_user" "main" { | ||
project_id = harbor_project.main.id | ||
user_name = "testing1" | ||
role = "master" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
The following arguments are supported: | ||
|
||
* **user_name** - (Required) The name of the member entity | ||
|
||
* **project_id** - (Required) The project id of the project that the entity will have access to. | ||
|
||
* **role** - (Required) The premissions that the entity will be granted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package provider | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/BESTSELLER/terraform-provider-harbor/client" | ||
"github.com/BESTSELLER/terraform-provider-harbor/models" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceMembersGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"project_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"member_id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"role": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { | ||
v := val.(string) | ||
if v != "projectadmin" && v != "developer" && v != "guest" && v != "master" { | ||
errs = append(errs, fmt.Errorf("%q must be either projectadmin, developer, guest or master, got: %s", key, v)) | ||
} | ||
return | ||
}, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { | ||
v := val.(string) | ||
if v != "ldap" && v != "internal" && v != "oidc" { | ||
errs = append(errs, fmt.Errorf("%q must be either ldap, internal or oidc, got: %s", key, v)) | ||
} | ||
return | ||
}, | ||
}, | ||
}, | ||
Create: resourceMembersGroupCreate, | ||
Read: resourceMembersGroupRead, | ||
Update: resourceMembersGroupUpdate, | ||
Delete: resourceMembersGroupDelete, | ||
} | ||
} | ||
|
||
func resourceMembersGroupCreate(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
projectid := checkProjectid(d.Get("project_id").(string)) | ||
path := projectid + "/members" | ||
|
||
body := client.ProjectBody(d) | ||
|
||
_, headers, err := apiClient.SendRequest("POST", path, body, 201) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id, err := client.GetID(headers) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(id) | ||
return resourceMembersGroupRead(d, m) | ||
} | ||
|
||
func resourceMembersGroupRead(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
|
||
resp, _, err := apiClient.SendRequest("GET", d.Id(), nil, 200) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
var jsonData models.ProjectMembersBody | ||
err = json.Unmarshal([]byte(resp), &jsonData) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.Set("role", client.RoleTypeNumber(jsonData.RoleID)) | ||
return nil | ||
} | ||
|
||
func resourceMembersGroupUpdate(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
|
||
body := client.ProjectMembersUserBody(d) | ||
_, _, err := apiClient.SendRequest("GET", d.Id(), body, 200) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
return resourceMembersGroupRead(d, m) | ||
} | ||
|
||
func resourceMembersGroupDelete(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
|
||
_, _, err := apiClient.SendRequest("DELETE", d.Id(), nil, 200) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package provider | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/BESTSELLER/terraform-provider-harbor/client" | ||
"github.com/BESTSELLER/terraform-provider-harbor/models" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceMembersUser() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"project_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"user_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"member_id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"role": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { | ||
v := val.(string) | ||
if v != "projectadmin" && v != "developer" && v != "guest" && v != "master" { | ||
errs = append(errs, fmt.Errorf("%q must be either projectadmin, developer, guest or master, got: %s", key, v)) | ||
} | ||
return | ||
}, | ||
}, | ||
}, | ||
Create: resourceMembersUserCreate, | ||
Read: resourceMembersUserRead, | ||
Update: resourceMembersUserUpdate, | ||
Delete: resourceMembersUserDelete, | ||
} | ||
} | ||
|
||
func resourceMembersUserCreate(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
path := d.Get("project_id").(string) + "/members" | ||
|
||
body := client.ProjectMembersUserBody(d) | ||
|
||
_, headers, err := apiClient.SendRequest("POST", path, body, 201) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id, err := client.GetID(headers) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(id) | ||
return resourceMembersUserRead(d, m) | ||
} | ||
|
||
func resourceMembersUserRead(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
|
||
resp, _, err := apiClient.SendRequest("GET", d.Id(), nil, 200) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
var jsonData models.ProjectMembersBody | ||
err = json.Unmarshal([]byte(resp), &jsonData) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.Set("role", client.RoleTypeNumber(jsonData.RoleID)) | ||
return nil | ||
} | ||
|
||
func resourceMembersUserUpdate(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
|
||
body := client.ProjectMembersUserBody(d) | ||
_, _, err := apiClient.SendRequest("PUT", d.Id(), body, 200) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
return resourceMembersUserRead(d, m) | ||
} | ||
|
||
func resourceMembersUserDelete(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*client.Client) | ||
|
||
_, _, err := apiClient.SendRequest("DELETE", d.Id(), nil, 200) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters