-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from softlayer/terraform
Adds ability to refresh auth token
- Loading branch information
Showing
8 changed files
with
291 additions
and
63 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
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,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"time" | ||
|
||
"github.com/softlayer/softlayer-go/services" | ||
"github.com/softlayer/softlayer-go/session" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(iamDemoCmd) | ||
} | ||
|
||
var iamDemoCmd = &cobra.Command{ | ||
Use: "iam-demo", | ||
Short: "Will make 1 API call per minute and refresh API key when needed.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return RunIamCmd(cmd, args) | ||
}, | ||
} | ||
|
||
func RunIamCmd(cmd *cobra.Command, args []string) error { | ||
objectMask := "mask[id,companyName]" | ||
|
||
// Sets up the session with authentication headers. | ||
sess := &session.Session{ | ||
Endpoint: session.DefaultEndpoint, | ||
IAMToken: "Bearer TOKEN", | ||
IAMRefreshToken: "REFRESH TOKEN", | ||
Debug: true, | ||
} | ||
|
||
// creates a reference to the service object (SoftLayer_Account) | ||
service := services.GetAccountService(sess) | ||
|
||
// Sets the mask, filter, result limit, and then makes the API call SoftLayer_Account::getHardware() | ||
|
||
for { | ||
account, err := service.Mask(objectMask).GetObject() | ||
if err != nil { | ||
fmt.Printf("======= ERROR ======") | ||
return err | ||
} | ||
fmt.Printf("AccountId: %v, CompanyName: %v\n", *account.Id, *account.CompanyName) | ||
fmt.Printf("Refreshing Token for no reason...\n") | ||
sess.RefreshToken() | ||
fmt.Printf("%s\n", sess.IAMToken) | ||
fmt.Printf("Sleeping for 60s.......\n") | ||
time.Sleep(60 * time.Second) | ||
} | ||
|
||
return nil | ||
} |
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
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
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
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
Oops, something went wrong.