-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #25, ReadMe and improved example for examples/sdkExample
Signed-off-by: Phil Hunt <[email protected]>
- Loading branch information
1 parent
1a9ad86
commit 095799f
Showing
5 changed files
with
93 additions
and
92 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
![Hexa](https://hexaorchestration.org/wp-content/themes/hexa/img/logo.svg) | ||
|
||
# Example: Using the SDK To Read Polcies from AVP | ||
|
||
The GoLang code in [exampleIntegration.go](exampleIntegration.go) shows how to open an integration using the Hexa-Mapper SDK. | ||
In this example, a credential file for AWS is read in and an integration is opened. The application then calls | ||
`GetPolicyApplicationPoints` to discover the defined AVP integrations. It then calls `GetPolicies` and `SetPolicies` to retrieve | ||
and set policies GoLang. | ||
|
||
In this example, the retrieved policies are formatted in a hexaPolicy.Policies structure. | ||
|
||
For more information on the contents of the Amazon credential file, use the Hexa CLI as follows: | ||
|
||
```shell | ||
hexa help add avp | ||
``` | ||
|
||
See the AVP Provider [README](../../providers/aws/avpProvider/README.md) for more information. | ||
|
||
See the [developer guide](../../docs/Developer.md) for more information on use of the SDK integration. |
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,73 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/hexa-org/policy-mapper/api/policyprovider" | ||
"github.com/hexa-org/policy-mapper/pkg/hexapolicy" | ||
"github.com/hexa-org/policy-mapper/sdk" | ||
) | ||
|
||
func main() { | ||
keybytes, err := os.ReadFile("awsCredential.txt") | ||
if err != nil { | ||
panic(-1) | ||
} | ||
|
||
info := policyprovider.IntegrationInfo{ | ||
Name: sdk.ProviderTypeAvp, | ||
Key: keybytes, | ||
} | ||
|
||
integration, err := sdk.OpenIntegration(sdk.WithIntegrationInfo(info)) | ||
if err != nil { | ||
fmt.Println("Error opening integration: " + err.Error()) | ||
panic(-1) | ||
} | ||
|
||
apps, err := integration.GetPolicyApplicationPoints(nil) | ||
if err != nil { | ||
panic(-1) | ||
} | ||
|
||
for _, app := range apps { | ||
jsonBytes, _ := json.MarshalIndent(app, "", " ") | ||
fmt.Println(string(jsonBytes)) | ||
} | ||
|
||
for alias := range integration.Apps { | ||
policies := getAndPrintPolicies(integration, alias) | ||
|
||
// Note that the returned policies object has the "app" alias included as policies.App. | ||
setPolicies(integration, policies) | ||
} | ||
|
||
} | ||
|
||
func getAndPrintPolicies(integration *sdk.Integration, alias string) *hexapolicy.Policies { | ||
|
||
fmt.Println("PAP " + alias) | ||
|
||
policies, err := integration.GetPolicies(alias) | ||
if err != nil { | ||
fmt.Println("Error retrieving policies: " + err.Error()) | ||
} | ||
jsonBytes, _ := json.MarshalIndent(policies, "", " ") | ||
fmt.Println("IDQL returned:") | ||
fmt.Println(string(jsonBytes)) | ||
|
||
return policies | ||
} | ||
|
||
func setPolicies(integration *sdk.Integration, policies *hexapolicy.Policies) { | ||
|
||
status, err := integration.SetPolicyInfo(*policies.App, policies.Policies) | ||
if err != nil { | ||
fmt.Println("Error getting policy: " + err.Error()) | ||
panic(-1) | ||
} | ||
fmt.Println("Request completed with http status " + strconv.Itoa(status)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.