Skip to content

Commit

Permalink
Revamp session code to include URL
Browse files Browse the repository at this point in the history
Signed-off-by: Yussuf Shaikh <[email protected]>
  • Loading branch information
yussufsh committed Jan 14, 2022
1 parent bd866ac commit 59ccfe2
Show file tree
Hide file tree
Showing 24 changed files with 815 additions and 299 deletions.
3 changes: 1 addition & 2 deletions clients/instance/ibm-pi-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ type IBMPIClient struct {

// NewIBMPIClient ...
func NewIBMPIClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPIClient {
authInfo := ibmpisession.NewAuth(sess, cloudInstanceID)
return &IBMPIClient{
session: sess,
cloudInstanceID: cloudInstanceID,
authInfo: authInfo,
authInfo: sess.AuthInfo(cloudInstanceID),
ctx: ctx,
}
}
2 changes: 1 addition & 1 deletion clients/instance/ibm-pi-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (f *IBMPIInstanceClient) Create(body *models.PVMInstanceCreate) (*models.PV
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithBody(body)
postok, postcreated, postAccepted, err := f.session.Power.PCloudpVMInstances.PcloudPvminstancesPost(params, ibmpisession.NewAuth(f.session, f.cloudInstanceID))
postok, postcreated, postAccepted, err := f.session.Power.PCloudpVMInstances.PcloudPvminstancesPost(params, f.authInfo)
if err != nil {
return nil, fmt.Errorf("failed to Create PVM Instance :%w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions clients/instance/ibm-pi-key.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewIBMPIKeyClient(ctx context.Context, sess *ibmpisession.IBMPISession, clo

// Get Key...
func (f *IBMPIKeyClient) Get(id string) (*models.SSHKey, error) {
var tenantid = f.session.UserAccount
var tenantid = f.session.Options.UserAccount
params := p_cloud_tenants_ssh_keys.NewPcloudTenantsSshkeysGetParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
WithTenantID(tenantid).WithSshkeyName(id)
Expand All @@ -42,7 +42,7 @@ func (f *IBMPIKeyClient) Get(id string) (*models.SSHKey, error) {

// GetAll Information about all the PVM Instances for a Client
func (f *IBMPIKeyClient) GetAll() (*models.SSHKeys, error) {
var tenantid = f.session.UserAccount
var tenantid = f.session.Options.UserAccount
params := p_cloud_tenants_ssh_keys.NewPcloudTenantsSshkeysGetallParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
WithTenantID(tenantid)
Expand All @@ -58,9 +58,10 @@ func (f *IBMPIKeyClient) GetAll() (*models.SSHKeys, error) {

// Create PI Key ...
func (f *IBMPIKeyClient) Create(body *models.SSHKey) (*models.SSHKey, error) {
var tenantid = f.session.Options.UserAccount
params := p_cloud_tenants_ssh_keys.NewPcloudTenantsSshkeysPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
WithTenantID(f.session.UserAccount).WithBody(body)
WithTenantID(tenantid).WithBody(body)
postok, postcreated, err := f.session.Power.PCloudTenantsSSHKeys.PcloudTenantsSshkeysPost(params, f.authInfo)
if err != nil {
return nil, fmt.Errorf(errors.CreatePIKeyOperationFailed, err)
Expand All @@ -76,7 +77,7 @@ func (f *IBMPIKeyClient) Create(body *models.SSHKey) (*models.SSHKey, error) {

// Delete ...
func (f *IBMPIKeyClient) Delete(id string) error {
var tenantid = f.session.UserAccount
var tenantid = f.session.Options.UserAccount
params := p_cloud_tenants_ssh_keys.NewPcloudTenantsSshkeysDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).
WithTenantID(tenantid).WithSshkeyName(id)
Expand Down
2 changes: 1 addition & 1 deletion clients/instance/ibm-pi-tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *IBMPITenantClient) Get(tenantid string) (*models.Tenant, error) {
func (f *IBMPITenantClient) GetSelfTenant() (*models.Tenant, error) {
params := p_cloud_tenants.NewPcloudTenantsGetParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
WithTenantID(f.session.UserAccount)
WithTenantID(f.session.Options.UserAccount)
resp, err := f.session.Power.PCloudTenants.PcloudTenantsGet(params, f.authInfo)
if err != nil {
return nil, fmt.Errorf("failed to get self tenant with error %w", err)
Expand Down
21 changes: 19 additions & 2 deletions examples/cloud-connection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
v "github.com/IBM-Cloud/power-go-client/clients/instance"
ps "github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM/go-sdk-core/v5/core"
)

const (
Expand All @@ -22,14 +23,30 @@ func main() {
region := " < REGION > "
zone := " < ZONE > "
accountID := " < ACCOUNT ID > "
//os.Setenv("IBMCLOUD_POWER_API_ENDPOINT", region+".power-iaas.test.cloud.ibm.com")
url := region + ".power-iaas.test.cloud.ibm.com"

// Cloud connection inputs
name := " < NAME OF THE CONNECTION > "
piID := " < POWER INSTANCE ID > "
var speed int64 = 5000

session, err := ps.New(token, region, true, accountID, zone)
authenticator := &core.BearerTokenAuthenticator{
BearerToken: token,
}
// authenticator := &core.IamAuthenticator{
// ApiKey: "< API KEY >",
// // Uncomment for test environment
// URL: "https://iam.test.cloud.ibm.com",
// }
// Create the session
options := &ps.IBMPIOptions{
Authenticator: authenticator,
UserAccount: accountID,
Zone: zone,
URL: url,
Debug: true,
}
session, err := ps.NewIBMPISession(options)
if err != nil {
log.Fatal(err)
}
Expand Down
21 changes: 19 additions & 2 deletions examples/dhcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

v "github.com/IBM-Cloud/power-go-client/clients/instance"
ps "github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM/go-sdk-core/v5/core"
)

func main() {
Expand All @@ -15,12 +16,28 @@ func main() {
region := " < REGION > "
zone := " < ZONE > "
accountID := " < ACCOUNT ID > "
//os.Setenv("IBMCLOUD_POWER_API_ENDPOINT", region+".power-iaas.test.cloud.ibm.com")
url := region + ".power-iaas.test.cloud.ibm.com"

// dhcp inputs
piID := " < POWER INSTANCE ID > "

session, err := ps.New(token, region, true, accountID, zone)
authenticator := &core.BearerTokenAuthenticator{
BearerToken: token,
}
// authenticator := &core.IamAuthenticator{
// ApiKey: "< API KEY >",
// // Uncomment for test environment
// URL: "https://iam.test.cloud.ibm.com",
// }
// Create the session
options := &ps.IBMPIOptions{
Authenticator: authenticator,
UserAccount: accountID,
Zone: zone,
URL: url,
Debug: true,
}
session, err := ps.NewIBMPISession(options)
if err != nil {
log.Fatal(err)
}
Expand Down
21 changes: 19 additions & 2 deletions examples/images/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
v "github.com/IBM-Cloud/power-go-client/clients/instance"
ps "github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM/go-sdk-core/v5/core"
)

func main() {
Expand All @@ -17,14 +18,30 @@ func main() {
region := " < REGION > "
zone := " < ZONE > "
accountID := " < ACCOUNT ID > "
//os.Setenv("IBMCLOUD_POWER_API_ENDPOINT", region+".power-iaas.test.cloud.ibm.com")
url := region + ".power-iaas.test.cloud.ibm.com"

// Image inputs
piID := " < POWER INSTANCE ID > "
name := " < NAME OF THE IMAGE > "
image := " <IMAGE ID> "

session, err := ps.New(token, region, true, accountID, zone)
authenticator := &core.BearerTokenAuthenticator{
BearerToken: token,
}
// authenticator := &core.IamAuthenticator{
// ApiKey: "< API KEY >",
// // Uncomment for test environment
// URL: "https://iam.test.cloud.ibm.com",
// }
// Create the session
options := &ps.IBMPIOptions{
Authenticator: authenticator,
UserAccount: accountID,
Zone: zone,
URL: url,
Debug: true,
}
session, err := ps.NewIBMPISession(options)
if err != nil {
log.Fatal(err)
}
Expand Down
21 changes: 19 additions & 2 deletions examples/instance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
v "github.com/IBM-Cloud/power-go-client/clients/instance"
ps "github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM/go-sdk-core/v5/core"
)

func main() {
Expand All @@ -16,7 +17,7 @@ func main() {
region := " < REGION > "
zone := " < ZONE > "
accountID := " < ACCOUNT ID > "
//os.Setenv("IBMCLOUD_POWER_API_ENDPOINT", region+".power-iaas.test.cloud.ibm.com")
url := region + ".power-iaas.test.cloud.ibm.com"

// volume inputs
name := " < NAME OF THE volume > "
Expand All @@ -32,7 +33,23 @@ func main() {
procType := "shared"
sysType := "s922"

session, err := ps.New(token, region, true, accountID, zone)
authenticator := &core.BearerTokenAuthenticator{
BearerToken: token,
}
// authenticator := &core.IamAuthenticator{
// ApiKey: "< API KEY >",
// // Uncomment for test environment
// URL: "https://iam.test.cloud.ibm.com",
// }
// Create the session
options := &ps.IBMPIOptions{
Authenticator: authenticator,
UserAccount: accountID,
Zone: zone,
URL: url,
Debug: true,
}
session, err := ps.NewIBMPISession(options)
if err != nil {
log.Fatal(err)
}
Expand Down
22 changes: 20 additions & 2 deletions examples/key/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
v "github.com/IBM-Cloud/power-go-client/clients/instance"
ps "github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM/go-sdk-core/v5/core"
)

func main() {
Expand All @@ -16,14 +17,31 @@ func main() {
region := " < REGION > "
zone := " < ZONE > "
accountID := " < ACCOUNT ID > "
//os.Setenv("IBMCLOUD_POWER_API_ENDPOINT", region+".power-iaas.test.cloud.ibm.com")
url := region + ".power-iaas.test.cloud.ibm.com"

// ssh inputs
name := " < NAME OF THE ssh > "
piID := " < POWER INSTANCE ID > "
ssh := " <ssh ID> "

session, err := ps.New(token, region, true, accountID, zone)
authenticator := &core.BearerTokenAuthenticator{
BearerToken: token,
}
// authenticator := &core.IamAuthenticator{
// ApiKey: "< API KEY >",
// // Uncomment for test environment
// URL: "https://iam.test.cloud.ibm.com",
// }
// Create the session
options := &ps.IBMPIOptions{
Authenticator: authenticator,
UserAccount: accountID,
Zone: zone,
URL: url,
Debug: true,
}

session, err := ps.NewIBMPISession(options)
if err != nil {
log.Fatal(err)
}
Expand Down
73 changes: 0 additions & 73 deletions examples/key_authenticator/main.go

This file was deleted.

22 changes: 20 additions & 2 deletions examples/network/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
v "github.com/IBM-Cloud/power-go-client/clients/instance"
ps "github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM/go-sdk-core/v5/core"
)

func main() {
Expand All @@ -20,7 +21,7 @@ func main() {
region := " < REGION > "
zone := " < ZONE > "
accountID := " < ACCOUNT ID > "
//os.Setenv("IBMCLOUD_POWER_API_ENDPOINT", region+".power-iaas.test.cloud.ibm.com")
url := region + ".power-iaas.test.cloud.ibm.com"

// network public vlan inputs
// name := " < NAME OF THE network > "
Expand All @@ -39,7 +40,24 @@ func main() {
gateway, startIP, endIP := generateIPData(cidr)
jumbo := false

session, err := ps.New(token, region, true, accountID, zone)
authenticator := &core.BearerTokenAuthenticator{
BearerToken: token,
}
// authenticator := &core.IamAuthenticator{
// ApiKey: "< API KEY >",
// // Uncomment for test environment
// URL: "https://iam.test.cloud.ibm.com",
// }

// Create the session
options := &ps.IBMPIOptions{
Authenticator: authenticator,
UserAccount: accountID,
Zone: zone,
URL: url,
Debug: true,
}
session, err := ps.NewIBMPISession(options)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading

0 comments on commit 59ccfe2

Please sign in to comment.