Skip to content

Commit 635e364

Browse files
authoredMar 26, 2021
feat(Posture Management): add service to project (#95)
1 parent 155ac5f commit 635e364

8 files changed

+2529
-13
lines changed
 

‎.secrets.baseline

+20
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@
228228
"verified_result": null
229229
}
230230
],
231+
"posturemanagementv1/posture_management_v1_examples_test.go": [
232+
{
233+
"hashed_secret": "811424347556b661512671f7a53aafa6aaf03ca2",
234+
"is_secret": false,
235+
"is_verified": false,
236+
"line_number": 38,
237+
"type": "Secret Keyword",
238+
"verified_result": null
239+
}
240+
],
241+
"posturemanagementv1/posture_management_v1_test.go": [
242+
{
243+
"hashed_secret": "1f5e25be9b575e9f5d39c82dfd1d9f4d73f1975c",
244+
"is_secret": false,
245+
"is_verified": false,
246+
"line_number": 724,
247+
"type": "Secret Keyword",
248+
"verified_result": null
249+
}
250+
],
231251
"resourcecontrollerv2/resource_controller_v2.go": [
232252
{
233253
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Service Name | Package name
6363
[IAM Identity Service](https://cloud.ibm.com/apidocs/iam-identity-token-api) | iamidentityv1
6464
[IAM Policy Managemenet](https://cloud.ibm.com/apidocs/iam-policy-management) | iampolicymanagementv1
6565
[Open Service Broker](https://cloud.ibm.com/apidocs/resource-controller/ibm-cloud-osb-api) | openservicebrokerv1
66+
[Posture Management](https://cloud.ibm.com/apidocs/security-compliance/posture) | posturemanagementv1
6667
[Resource Controller](https://cloud.ibm.com/apidocs/resource-controller/resource-controller) | resourcecontrollerv2
6768
[Resource Manager](https://cloud.ibm.com/apidocs/resource-controller/resource-manager) | resourcemanagerv2
6869
[Usage Metering](https://cloud.ibm.com/apidocs/usage-metering) | usagemeteringv4

‎go.sum

-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1111
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1212
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
1313
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
14-
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
1514
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
1615
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
1716
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -50,7 +49,6 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe
5049
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
5150
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
5251
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
53-
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
5452
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
5553
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
5654
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
@@ -60,10 +58,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
6058
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
6159
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
6260
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
63-
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
6461
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
6562
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
66-
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
6763
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
6864
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
6965
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -75,12 +71,10 @@ github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxC
7571
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
7672
github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM=
7773
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
78-
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
7974
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
8075
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
8176
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
8277
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
83-
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
8478
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
8579
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
8680
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
@@ -144,15 +138,13 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
144138
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
145139
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
146140
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
147-
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
148141
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
149142
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
150143
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
151144
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
152145
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
153146
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 h1:wBouT66WTYFXdxfVdz9sVWARVd/2vfGcmI45D2gj45M=
154147
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
155-
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
156148
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
157149
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
158150
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -168,14 +160,12 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
168160
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
169161
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
170162
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
171-
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
172163
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
173164
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
174165
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
175166
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
176167
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
177168
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
178-
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
179169
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
180170
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
181171
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@@ -193,12 +183,10 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
193183
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
194184
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
195185
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
196-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
197186
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
198187
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
199188
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
200189
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
201-
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
202190
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
203191
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
204192
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
@@ -207,7 +195,6 @@ gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWd
207195
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
208196
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
209197
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
210-
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
211198
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
212199
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
213200
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=

‎posturemanagementv1/posture_management_v1.go

+966
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
// +build examples
2+
3+
/**
4+
* (C) Copyright IBM Corp. 2021.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package posturemanagementv1_test
20+
21+
import (
22+
"encoding/json"
23+
"fmt"
24+
"os"
25+
26+
"github.com/IBM/go-sdk-core/v5/core"
27+
"github.com/IBM/platform-services-go-sdk/posturemanagementv1"
28+
. "github.com/onsi/ginkgo"
29+
. "github.com/onsi/gomega"
30+
)
31+
32+
//
33+
// This file provides an example of how to use the Posture Management service.
34+
//
35+
// The following configuration properties are assumed to be defined:
36+
// POSTURE_MANAGEMENT_URL=<service base url>
37+
// POSTURE_MANAGEMENT_AUTH_TYPE=iam
38+
// POSTURE_MANAGEMENT_APIKEY=<IAM apikey>
39+
// POSTURE_MANAGEMENT_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
40+
// POSTURE_MANAGEMENT_ACCOUNT_ID=<IBM CLOUD ACCOUNT ID>
41+
// POSTURE_MANAGEMENT_SCOPES_NAME=<The name of the scope>
42+
// POSTURE_MANAGEMENT_PROFILE_NAME=<The name of profile - CIS IBM Foundations Benchmark 1.0.0>
43+
//
44+
// These configuration properties can be exported as environment variables, or stored
45+
// in a configuration file and then:
46+
// export IBM_CREDENTIALS_FILE=<name of configuration file>
47+
//
48+
const externalConfigFile = "../posture_management.env"
49+
50+
var (
51+
postureManagementService *posturemanagementv1.PostureManagementV1
52+
config map[string]string
53+
configLoaded bool = false
54+
55+
accountID string
56+
profileName string
57+
scopesName string
58+
59+
profileID string
60+
scopeID string
61+
62+
groupProfileID = "0"
63+
)
64+
65+
func shouldSkipTest() {
66+
if !configLoaded {
67+
Skip("External configuration is not available, skipping tests...")
68+
}
69+
}
70+
71+
var _ = Describe(`PostureManagementV1 Examples Tests`, func() {
72+
Describe(`External configuration`, func() {
73+
It("Successfully load the configuration", func() {
74+
var err error
75+
_, err = os.Stat(externalConfigFile)
76+
if err != nil {
77+
Skip("External configuration file not found, skipping tests: " + err.Error())
78+
}
79+
80+
os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile)
81+
config, err = core.GetServiceProperties(posturemanagementv1.DefaultServiceName)
82+
if err != nil {
83+
Skip("Error loading service properties, skipping tests: " + err.Error())
84+
}
85+
86+
configLoaded = len(config) > 0
87+
88+
accountID = config["ACCOUNT_ID"]
89+
Expect(accountID).ToNot(BeEmpty())
90+
91+
profileName = config["PROFILE_NAME"]
92+
Expect(profileName).ToNot(BeEmpty())
93+
94+
scopesName = config["SCOPES_NAME"]
95+
Expect(scopesName).ToNot(BeEmpty())
96+
})
97+
})
98+
99+
Describe(`Client initialization`, func() {
100+
BeforeEach(func() {
101+
shouldSkipTest()
102+
})
103+
It("Successfully construct the service client instance", func() {
104+
var err error
105+
106+
// begin-common
107+
108+
postureManagementServiceOptions := &posturemanagementv1.PostureManagementV1Options{}
109+
110+
postureManagementService, err = posturemanagementv1.NewPostureManagementV1UsingExternalConfig(postureManagementServiceOptions)
111+
112+
if err != nil {
113+
panic(err)
114+
}
115+
116+
// end-common
117+
118+
Expect(postureManagementService).ToNot(BeNil())
119+
})
120+
})
121+
122+
Describe(`PostureManagementV1 request examples`, func() {
123+
BeforeEach(func() {
124+
shouldSkipTest()
125+
})
126+
It(`ListProfiles request example`, func() {
127+
// begin-list_profiles
128+
129+
listProfilesOptions := postureManagementService.NewListProfilesOptions(
130+
accountID,
131+
)
132+
listProfilesOptions.SetName(profileName)
133+
134+
profilesList, response, err := postureManagementService.ListProfiles(listProfilesOptions)
135+
if err != nil {
136+
panic(err)
137+
}
138+
b, _ := json.MarshalIndent(profilesList, "", " ")
139+
fmt.Printf("\nListProfiles() result:\n%s\n", string(b))
140+
141+
// end-list_profiles
142+
143+
Expect(err).To(BeNil())
144+
Expect(response.StatusCode).To(Equal(200))
145+
Expect(profilesList).ToNot(BeNil())
146+
147+
profileID = *profilesList.Profiles[0].ProfileID
148+
})
149+
It(`ListScopes request example`, func() {
150+
// begin-list_scopes
151+
152+
listScopesOptions := postureManagementService.NewListScopesOptions(
153+
accountID,
154+
)
155+
listScopesOptions.SetName(scopesName)
156+
157+
scopesList, response, err := postureManagementService.ListScopes(listScopesOptions)
158+
if err != nil {
159+
panic(err)
160+
}
161+
b, _ := json.MarshalIndent(scopesList, "", " ")
162+
fmt.Printf("\nListScopes() result:\n%s\n", string(b))
163+
164+
// end-list_scopes
165+
166+
Expect(err).To(BeNil())
167+
Expect(response.StatusCode).To(Equal(200))
168+
Expect(scopesList).ToNot(BeNil())
169+
170+
scopeID = *scopesList.Scopes[0].ScopeID
171+
})
172+
It(`CreateValidation request example`, func() {
173+
// begin-create_validation
174+
175+
createValidationOptions := postureManagementService.NewCreateValidationOptions(
176+
accountID,
177+
)
178+
createValidationOptions.SetProfileID(profileID)
179+
createValidationOptions.SetScopeID(scopeID)
180+
createValidationOptions.SetGroupProfileID(groupProfileID)
181+
182+
result, response, err := postureManagementService.CreateValidation(createValidationOptions)
183+
if err != nil {
184+
panic(err)
185+
}
186+
b, _ := json.MarshalIndent(result, "", " ")
187+
fmt.Printf("\nCreateValidation() result:\n%s\n", string(b))
188+
189+
// end-create_validation
190+
191+
Expect(err).To(BeNil())
192+
Expect(response.StatusCode).To(Equal(202))
193+
Expect(result).ToNot(BeNil())
194+
195+
})
196+
})
197+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// +build integration
2+
3+
/**
4+
* (C) Copyright IBM Corp. 2021.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package posturemanagementv1_test
20+
21+
import (
22+
"fmt"
23+
"os"
24+
25+
"github.com/IBM/go-sdk-core/v5/core"
26+
"github.com/IBM/platform-services-go-sdk/posturemanagementv1"
27+
. "github.com/onsi/ginkgo"
28+
. "github.com/onsi/gomega"
29+
)
30+
31+
/**
32+
* This file contains an integration test for the posturemanagementv1 package.
33+
*
34+
* Notes:
35+
*
36+
* The integration test will automatically skip tests if the required config file is not available.
37+
*/
38+
39+
var _ = Describe(`PostureManagementV1 Integration Tests`, func() {
40+
41+
const externalConfigFile = "../posture_management.env"
42+
43+
var (
44+
err error
45+
postureManagementService *posturemanagementv1.PostureManagementV1
46+
serviceURL string
47+
config map[string]string
48+
49+
accountID string
50+
profileName string
51+
scopesName string
52+
53+
profileID *string
54+
scopeID *string
55+
56+
groupProfileID = "0"
57+
)
58+
59+
var shouldSkipTest = func() {
60+
Skip("External configuration is not available, skipping tests...")
61+
}
62+
63+
Describe(`External configuration`, func() {
64+
It("Successfully load the configuration", func() {
65+
_, err = os.Stat(externalConfigFile)
66+
if err != nil {
67+
Skip("External configuration file not found, skipping tests: " + err.Error())
68+
}
69+
70+
os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile)
71+
config, err = core.GetServiceProperties(posturemanagementv1.DefaultServiceName)
72+
if err != nil {
73+
Skip("Error loading service properties, skipping tests: " + err.Error())
74+
}
75+
serviceURL = config["URL"]
76+
if serviceURL == "" {
77+
Skip("Unable to load service URL configuration property, skipping tests")
78+
}
79+
80+
accountID = config["ACCOUNT_ID"]
81+
Expect(accountID).ToNot(BeEmpty())
82+
83+
profileName = config["PROFILE_NAME"]
84+
Expect(profileName).ToNot(BeEmpty())
85+
86+
scopesName = config["SCOPES_NAME"]
87+
Expect(scopesName).ToNot(BeEmpty())
88+
89+
fmt.Printf("Service URL: %s\n", serviceURL)
90+
shouldSkipTest = func() {}
91+
})
92+
})
93+
94+
Describe(`Client initialization`, func() {
95+
BeforeEach(func() {
96+
shouldSkipTest()
97+
})
98+
It("Successfully construct the service client instance", func() {
99+
100+
postureManagementServiceOptions := &posturemanagementv1.PostureManagementV1Options{}
101+
102+
postureManagementService, err = posturemanagementv1.NewPostureManagementV1UsingExternalConfig(postureManagementServiceOptions)
103+
104+
Expect(err).To(BeNil())
105+
Expect(postureManagementService).ToNot(BeNil())
106+
Expect(postureManagementService.Service.Options.URL).To(Equal(serviceURL))
107+
})
108+
})
109+
110+
Describe(`ListProfiles - List profiles`, func() {
111+
BeforeEach(func() {
112+
shouldSkipTest()
113+
})
114+
It(`ListProfiles(listProfilesOptions *ListProfilesOptions)`, func() {
115+
116+
listProfilesOptions := &posturemanagementv1.ListProfilesOptions{
117+
AccountID: &accountID,
118+
Name: &profileName,
119+
}
120+
121+
profilesList, response, err := postureManagementService.ListProfiles(listProfilesOptions)
122+
123+
Expect(err).To(BeNil())
124+
Expect(response.StatusCode).To(Equal(200))
125+
Expect(profilesList).ToNot(BeNil())
126+
127+
profileID = profilesList.Profiles[0].ProfileID
128+
})
129+
})
130+
131+
Describe(`ListScopes - List scopes`, func() {
132+
BeforeEach(func() {
133+
shouldSkipTest()
134+
})
135+
It(`ListScopes(listScopesOptions *ListScopesOptions)`, func() {
136+
137+
listScopesOptions := &posturemanagementv1.ListScopesOptions{
138+
AccountID: &accountID,
139+
Name: &scopesName,
140+
}
141+
142+
scopesList, response, err := postureManagementService.ListScopes(listScopesOptions)
143+
144+
Expect(err).To(BeNil())
145+
Expect(response.StatusCode).To(Equal(200))
146+
Expect(scopesList).ToNot(BeNil())
147+
148+
scopeID = scopesList.Scopes[0].ScopeID
149+
})
150+
})
151+
152+
Describe(`CreateValidation - Initiate a validation`, func() {
153+
BeforeEach(func() {
154+
shouldSkipTest()
155+
})
156+
It(`CreateValidation(createValidationOptions *CreateValidationOptions)`, func() {
157+
Expect(scopeID).ToNot(BeNil())
158+
Expect(profileID).ToNot(BeNil())
159+
160+
createValidationOptions := &posturemanagementv1.CreateValidationOptions{
161+
AccountID: &accountID,
162+
ScopeID: scopeID,
163+
ProfileID: profileID,
164+
GroupProfileID: &groupProfileID,
165+
}
166+
167+
result, response, err := postureManagementService.CreateValidation(createValidationOptions)
168+
169+
Expect(err).To(BeNil())
170+
Expect(response.StatusCode).To(Equal(202))
171+
Expect(result).ToNot(BeNil())
172+
173+
})
174+
})
175+
})
176+
177+
//
178+
// Utility functions are declared in the unit test file
179+
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2021.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package posturemanagementv1_test
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
func TestPostureManagementV1(t *testing.T) {
27+
RegisterFailHandler(Fail)
28+
RunSpecs(t, "PostureManagementV1 Suite")
29+
}

‎posturemanagementv1/posture_management_v1_test.go

+1,137
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.