Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Posture Management): add service to project #95

Merged
merged 12 commits into from
Mar 26, 2021
Next Next commit
feat(Posture Management): add service to project
pyrooka committed Mar 9, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6b4c11276872ce2454bd8037052dbe9fd3f4a54c
972 changes: 972 additions & 0 deletions posturemanagementv1/posture_management_v1.go

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions posturemanagementv1/posture_management_v1_examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// +build examples

/**
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package posturemanagementv1_test

import (
"encoding/json"
"fmt"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/posturemanagementv1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"os"
)

//
// This file provides an example of how to use the Posture Management service.
//
// The following configuration properties are assumed to be defined:
// POSTURE_MANAGEMENT_URL=<service base url>
// POSTURE_MANAGEMENT_AUTH_TYPE=iam
// POSTURE_MANAGEMENT_APIKEY=<IAM apikey>
// POSTURE_MANAGEMENT_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
//
// These configuration properties can be exported as environment variables, or stored
// in a configuration file and then:
// export IBM_CREDENTIALS_FILE=<name of configuration file>
//
const externalConfigFile = "../posture_management_v1.env"

var (
postureManagementService *posturemanagementv1.PostureManagementV1
config map[string]string
configLoaded bool = false
)

func shouldSkipTest() {
if !configLoaded {
Skip("External configuration is not available, skipping tests...")
}
}

var _ = Describe(`PostureManagementV1 Examples Tests`, func() {
Describe(`External configuration`, func() {
It("Successfully load the configuration", func() {
var err error
_, err = os.Stat(externalConfigFile)
if err != nil {
Skip("External configuration file not found, skipping tests: " + err.Error())
}

os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile)
config, err = core.GetServiceProperties(posturemanagementv1.DefaultServiceName)
if err != nil {
Skip("Error loading service properties, skipping tests: " + err.Error())
}

configLoaded = len(config) > 0
})
})

Describe(`Client initialization`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It("Successfully construct the service client instance", func() {
var err error

// begin-common

postureManagementServiceOptions := &posturemanagementv1.PostureManagementV1Options{}

postureManagementService, err = posturemanagementv1.NewPostureManagementV1UsingExternalConfig(postureManagementServiceOptions)

if err != nil {
panic(err)
}

// end-common

Expect(postureManagementService).ToNot(BeNil())
})
})

Describe(`PostureManagementV1 request examples`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It(`CreateValidationScan request example`, func() {
// begin-create_validation_scan

createValidationScanOptions := postureManagementService.NewCreateValidationScanOptions(
"testString",
)

result, response, err := postureManagementService.CreateValidationScan(createValidationScanOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(result, "", " ")
fmt.Println(string(b))

// end-create_validation_scan

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(result).ToNot(BeNil())

})
It(`ListProfile request example`, func() {
// begin-list_profile

listProfileOptions := postureManagementService.NewListProfileOptions(
"testString",
)

profilesList, response, err := postureManagementService.ListProfile(listProfileOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(profilesList, "", " ")
fmt.Println(string(b))

// end-list_profile

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(profilesList).ToNot(BeNil())

})
It(`ListScopes request example`, func() {
// begin-list_scopes

listScopesOptions := postureManagementService.NewListScopesOptions(
"testString",
)

scopesList, response, err := postureManagementService.ListScopes(listScopesOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(scopesList, "", " ")
fmt.Println(string(b))

// end-list_scopes

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(scopesList).ToNot(BeNil())

})
})
})
156 changes: 156 additions & 0 deletions posturemanagementv1/posture_management_v1_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// +build integration

/**
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package posturemanagementv1_test

import (
"fmt"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/platform-services-go-sdk/posturemanagementv1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"os"
)

/**
* This file contains an integration test for the posturemanagementv1 package.
*
* Notes:
*
* The integration test will automatically skip tests if the required config file is not available.
*/

var _ = Describe(`PostureManagementV1 Integration Tests`, func() {

const externalConfigFile = "../posture_management_v1.env"

var (
err error
postureManagementService *posturemanagementv1.PostureManagementV1
serviceURL string
config map[string]string
)

var shouldSkipTest = func() {
Skip("External configuration is not available, skipping tests...")
}

Describe(`External configuration`, func() {
It("Successfully load the configuration", func() {
_, err = os.Stat(externalConfigFile)
if err != nil {
Skip("External configuration file not found, skipping tests: " + err.Error())
}

os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile)
config, err = core.GetServiceProperties(posturemanagementv1.DefaultServiceName)
if err != nil {
Skip("Error loading service properties, skipping tests: " + err.Error())
}
serviceURL = config["URL"]
if serviceURL == "" {
Skip("Unable to load service URL configuration property, skipping tests")
}

fmt.Printf("Service URL: %s\n", serviceURL)
shouldSkipTest = func() {}
})
})

Describe(`Client initialization`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It("Successfully construct the service client instance", func() {

postureManagementServiceOptions := &posturemanagementv1.PostureManagementV1Options{}

postureManagementService, err = posturemanagementv1.NewPostureManagementV1UsingExternalConfig(postureManagementServiceOptions)

Expect(err).To(BeNil())
Expect(postureManagementService).ToNot(BeNil())
Expect(postureManagementService.Service.Options.URL).To(Equal(serviceURL))
})
})

Describe(`CreateValidationScan - Initiate a validation scan`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It(`CreateValidationScan(createValidationScanOptions *CreateValidationScanOptions)`, func() {

createValidationScanOptions := &posturemanagementv1.CreateValidationScanOptions{
AccountID: core.StringPtr("testString"),
ScopeID: core.Int64Ptr(int64(1)),
ProfileID: core.Int64Ptr(int64(6)),
GroupProfileID: core.Int64Ptr(int64(13)),
}

result, response, err := postureManagementService.CreateValidationScan(createValidationScanOptions)

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(result).ToNot(BeNil())

})
})

Describe(`ListProfile - List profiles`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It(`ListProfile(listProfileOptions *ListProfileOptions)`, func() {

listProfileOptions := &posturemanagementv1.ListProfileOptions{
AccountID: core.StringPtr("testString"),
Name: core.StringPtr("testString"),
}

profilesList, response, err := postureManagementService.ListProfile(listProfileOptions)

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(profilesList).ToNot(BeNil())

})
})

Describe(`ListScopes - List scopes`, func() {
BeforeEach(func() {
shouldSkipTest()
})
It(`ListScopes(listScopesOptions *ListScopesOptions)`, func() {

listScopesOptions := &posturemanagementv1.ListScopesOptions{
AccountID: core.StringPtr("testString"),
Name: core.StringPtr("testString"),
}

scopesList, response, err := postureManagementService.ListScopes(listScopesOptions)

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(scopesList).ToNot(BeNil())

})
})
})

//
// Utility functions are declared in the unit test file
//
28 changes: 28 additions & 0 deletions posturemanagementv1/posture_management_v1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* (C) Copyright IBM Corp. 2021.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package posturemanagementv1_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)

func TestPostureManagementV1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "PostureManagementV1 Suite")
}
1,137 changes: 1,137 additions & 0 deletions posturemanagementv1/posture_management_v1_test.go

Large diffs are not rendered by default.