Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
improve flag management
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Garcia Ruiz committed Oct 27, 2016
1 parent c55fc96 commit b6a5ebb
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 157 deletions.
10 changes: 5 additions & 5 deletions client/api/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *ClientAPI) GetGroupsByOrg(organizationId, pathPrefix, offset, limit, or
}

func (c *ClientAPI) CreateGroup(organizationId, groupName, path string) (string, error) {
body := map[string]string{
body := map[string]interface{}{
"name": groupName,
"path": path,
}
Expand All @@ -51,7 +51,7 @@ func (c *ClientAPI) CreateGroup(organizationId, groupName, path string) (string,
}

func (c *ClientAPI) UpdateGroup(organizationId, groupName, newName, newPath string) (string, error) {
body := map[string]string{
body := map[string]interface{}{
"name": newName,
"path": newPath,
}
Expand All @@ -72,9 +72,9 @@ func (c *ClientAPI) DeleteGroup(organizationId, groupName string) (string, error

func (c *ClientAPI) GetGroupPolicies(organizationId, groupName, offset, limit, orderBy string) (string, error) {
urlParams := map[string]string{
"Offset": offset,
"Limit": limit,
"OrderBy": orderBy,
"Offset": offset,
"Limit": limit,
"OrderBy": orderBy,
}
req, err := c.prepareRequest("GET", internalhttp.API_VERSION_1+"/organizations/"+organizationId+"/groups/"+groupName+"/policies", nil, urlParams)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions client/api/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ type UserAPI interface {
DeleteUser(externalId string) (string, error)
}

type PolicyAPI interface {
GetPolicy(organizationId, policyName string) (string, error)
GetAllPolicies(pathPrefix, offset, limit, orderBy string) (string, error)
CreatePolicy(organizationId, policyName, path, statement string) (string, error)
UpdatePolicy(organizationId, policyName, path, statement string) (string, error)
DeletePolicy(organizationId, policyName string) (string, error)
GetGroupsAttached(organizationId, policyName, offset, limit, orderBy string) (string, error)
GetPoliciesOrganization(organizationId, pathPrefix, offset, limit, orderBy string) (string, error)
}

type GroupAPI interface {
GetGroup(organizationId, groupName string) (string, error)
GetAllGroups(pathPrefix, offset, limit, orderBy string) (string, error)
Expand Down
50 changes: 34 additions & 16 deletions client/api/policy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package api

import internalhttp "github.com/Tecsisa/foulkon/http"
import (
"encoding/json"

"github.com/Tecsisa/foulkon/api"
internalhttp "github.com/Tecsisa/foulkon/http"
)

func (c *ClientAPI) GetPolicy(organizationId, policyName string) (string, error) {
req, err := c.prepareRequest("GET", internalhttp.API_VERSION_1+"/organizations/"+organizationId+"/policies/"+policyName, nil, nil)
Expand All @@ -10,7 +15,7 @@ func (c *ClientAPI) GetPolicy(organizationId, policyName string) (string, error)
return c.makeRequest(req)
}

func (c *ClientAPI) GetAllPolicy(pathPrefix, offset, limit, orderBy string) (string, error) {
func (c *ClientAPI) GetAllPolicies(pathPrefix, offset, limit, orderBy string) (string, error) {
urlParams := map[string]string{
"PathPrefix": pathPrefix,
"Offset": offset,
Expand All @@ -24,29 +29,42 @@ func (c *ClientAPI) GetAllPolicy(pathPrefix, offset, limit, orderBy string) (str
return c.makeRequest(req)
}

func (c *ClientAPI) CreatePolicy(organizationId, policyName, path, effect, actions, resources string) (string, error) {
body := map[string]string{
func (c *ClientAPI) CreatePolicy(organizationId, policyName, path, statement string) (string, error) {

statementApi := []api.Statement{}
if err := json.Unmarshal([]byte(statement), &statementApi); err != nil {
panic(err)
}
body := map[string]interface{}{
"name": policyName,
"path": path,
"Statements": "\"Statements\" : [ { \"Effect\" : \"allow\", \"Actions\" : [\"iam:*\"], \"Resources\" : [\"urn:everything:*\"] } ]",
//"effect": effect,
//"actions": actions,
//"resources": resources,
"Statements": statementApi,
}

req, err := c.prepareRequest("POST", internalhttp.API_VERSION_1+"/organizations/"+organizationId+"/policies", body, nil)
if err != nil {
return "", err
}
return c.makeRequest(req)
}

//func (c *ClientAPI) UpdatePolicy(organizationId, policyName string) (string, error) {
// req, err := c.prepareRequest("PUT", internalhttp.API_VERSION_1+"/organizations/"+organizationId+"/policies/"+policyName, nil, nil)
// if err != nil {
// return "", err
// }
// return c.makeRequest(req)
//}
func (c *ClientAPI) UpdatePolicy(organizationId, policyName, path, statement string) (string, error) {
statementApi := []api.Statement{}
if err := json.Unmarshal([]byte(statement), &statementApi); err != nil {
panic(err)
}
body := map[string]interface{}{
"name": policyName,
"path": path,
"Statements": statementApi,
}

req, err := c.prepareRequest("PUT", internalhttp.API_VERSION_1+"/organizations/"+organizationId+"/policies/"+policyName, body, nil)
if err != nil {
return "", err
}
return c.makeRequest(req)
}

func (c *ClientAPI) DeletePolicy(organizationId, policyName string) (string, error) {
req, err := c.prepareRequest("DELETE", internalhttp.API_VERSION_1+"/organizations/"+organizationId+"/policies/"+policyName, nil, nil)
Expand All @@ -56,7 +74,7 @@ func (c *ClientAPI) DeletePolicy(organizationId, policyName string) (string, err
return c.makeRequest(req)
}

func (c *ClientAPI) GetGroupsPolicy(organizationId, policyName, offset, limit, orderBy string) (string, error) {
func (c *ClientAPI) GetGroupsAttached(organizationId, policyName, offset, limit, orderBy string) (string, error) {
urlParams := map[string]string{
"Offset": offset,
"Limit": limit,
Expand Down
4 changes: 2 additions & 2 deletions client/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *ClientAPI) GetUserGroups(externalId, offset, limit, orderBy string) (st
}

func (c *ClientAPI) CreateUser(externalId, path string) (string, error) {
body := map[string]string{
body := map[string]interface{}{
"externalId": externalId,
"path": path,
}
Expand All @@ -51,7 +51,7 @@ func (c *ClientAPI) CreateUser(externalId, path string) (string, error) {
}

func (c *ClientAPI) UpdateUser(externalId, path string) (string, error) {
body := map[string]string{
body := map[string]interface{}{
"path": path,
}

Expand Down
2 changes: 1 addition & 1 deletion client/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// Helper func for updating request params
func (c *ClientAPI) prepareRequest(method, url string, postContent, queryParams map[string]string) (*http.Request, error) {
func (c *ClientAPI) prepareRequest(method, url string, postContent map[string]interface{}, queryParams map[string]string) (*http.Request, error) {
url = c.Address + url
// insert post content to body
var body *bytes.Buffer
Expand Down
Loading

0 comments on commit b6a5ebb

Please sign in to comment.