-
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 #17 from BESTSELLER/multiple-actions-for-robot-acc…
…ount created actions attribute for robot account
- Loading branch information
Showing
4 changed files
with
107 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,51 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/BESTSELLER/terraform-provider-harbor/models" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func RobotBody(d *schema.ResourceData, resource string) models.RobotBody { | ||
return models.RobotBody{ | ||
func RobotBody(d *schema.ResourceData, projectid string) models.RobotBody { | ||
resource := strings.Replace(projectid, "s", "", +1) | ||
|
||
body := models.RobotBody{ | ||
Name: d.Get("name").(string), | ||
Description: d.Get("description").(string), | ||
Access: []models.RobotBodyAccess{ | ||
{ | ||
Action: d.Get("action").(string), | ||
Resource: resource, | ||
}, | ||
}, | ||
} | ||
_, existingAttributeOk := d.GetOk("action") | ||
_, newAttributeOk := d.GetOk("actions") | ||
|
||
robotAccess := models.RobotBodyAccess{} | ||
|
||
if !existingAttributeOk && !newAttributeOk { | ||
fmt.Errorf("one of action or actions must be configured") | ||
|
||
} else if existingAttributeOk { | ||
robotAccess.Action = d.Get("action").(string) | ||
robotAccess.Resource = resource + "/repository" | ||
body.Access = append(body.Access, robotAccess) | ||
|
||
} else if newAttributeOk { | ||
access := d.Get("actions").([]interface{}) | ||
for _, v := range access { | ||
|
||
switch v.(string) { | ||
case "push", "pull": | ||
robotAccess.Action = v.(string) | ||
robotAccess.Resource = resource + "/repository" | ||
case "read": | ||
robotAccess.Action = v.(string) | ||
robotAccess.Resource = resource + "/helm-chart" | ||
case "create": | ||
robotAccess.Action = v.(string) | ||
robotAccess.Resource = resource + "/helm-chart-version" | ||
} | ||
body.Access = append(body.Access, robotAccess) | ||
} | ||
} | ||
|
||
return body | ||
} |
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