diff --git a/bluemix/configuration/core_config/bx_config.go b/bluemix/configuration/core_config/bx_config.go index 907740f..40b3d36 100644 --- a/bluemix/configuration/core_config/bx_config.go +++ b/bluemix/configuration/core_config/bx_config.go @@ -55,6 +55,7 @@ type BXConfigData struct { Trace string ColorEnabled string HTTPTimeout int + TypeOfSSO string CLIInfoEndpoint string // overwrite the cli info endpoint CheckCLIVersionDisabled bool UsageStatsDisabled bool // deprecated: use UsageStatsEnabled @@ -412,6 +413,13 @@ func (c *bxConfig) ColorEnabled() (enabled string) { return } +func (c *bxConfig) TypeOfSSO() (style string) { + c.read(func() { + style = c.data.TypeOfSSO + }) + return +} + func (c *bxConfig) HTTPTimeout() (timeout int) { c.read(func() { timeout = c.data.HTTPTimeout @@ -639,6 +647,12 @@ func (c *bxConfig) SetHTTPTimeout(timeout int) { }) } +func (c *bxConfig) SetTypeOfSSO(style string) { + c.write(func() { + c.data.TypeOfSSO = style + }) +} + func (c *bxConfig) SetCheckCLIVersionDisabled(disabled bool) { c.write(func() { c.data.CheckCLIVersionDisabled = disabled diff --git a/bluemix/configuration/core_config/repository.go b/bluemix/configuration/core_config/repository.go index 8c035e6..dd9d502 100644 --- a/bluemix/configuration/core_config/repository.go +++ b/bluemix/configuration/core_config/repository.go @@ -51,6 +51,7 @@ type Repository interface { PluginRepos() []models.PluginRepo PluginRepo(string) (models.PluginRepo, bool) IsSSLDisabled() bool + TypeOfSSO() string HTTPTimeout() int CLIInfoEndpoint() string CheckCLIVersionDisabled() bool @@ -99,6 +100,7 @@ type Repository interface { SetPluginRepo(models.PluginRepo) UnsetPluginRepo(string) SetSSLDisabled(bool) + SetTypeOfSSO(string) SetHTTPTimeout(int) // SetUsageSatsDisabled disable or enable usage statistics data collection // Deprecated: use SetUsageSatsEnabled instead diff --git a/bluemix/version.go b/bluemix/version.go index 0c17f77..74497e4 100644 --- a/bluemix/version.go +++ b/bluemix/version.go @@ -3,7 +3,7 @@ package bluemix import "fmt" // Version is the SDK version -var Version = VersionType{Major: 1, Minor: 2, Build: 0} +var Version = VersionType{Major: 1, Minor: 3, Build: 0} // VersionType describe version info type VersionType struct { diff --git a/common/rest/request.go b/common/rest/request.go index f1badd9..cd37ab6 100644 --- a/common/rest/request.go +++ b/common/rest/request.go @@ -1,44 +1,45 @@ // Request examples: -// // create a simple GET request -// req := GetRequest("http://www.example.com") // -// // set header -// req.Set("Accept", "application/json") +// // create a simple GET request +// req := GetRequest("http://www.example.com") // -// // set query parameters -// req.Query("foo1", "bar1") -// req.Query("foo2", "bar2") +// // set header +// req.Set("Accept", "application/json") // -// // Build to a HTTP request -// req.Build() +// // set query parameters +// req.Query("foo1", "bar1") +// req.Query("foo2", "bar2") // -// // method chaining is also supported -// // the above is equal to: -// GetRequest("http://www.example.com"). -// Set("Accept", "application/json"). -// Query("foo1", "bar1"). -// Query("foo2", "bar2"). -// Build() +// // Build to a HTTP request +// req.Build() // -// // struct body -// foo = Foo{Bar: "val"} -// PostRequest("http://www.example.com"). -// Body(foo) +// // method chaining is also supported +// // the above is equal to: +// GetRequest("http://www.example.com"). +// Set("Accept", "application/json"). +// Query("foo1", "bar1"). +// Query("foo2", "bar2"). +// Build() // -// // String body -// PostRequest("http://www.example.com"). -// Body("{\"bar\": \"val\"}") +// // struct body +// foo = Foo{Bar: "val"} +// PostRequest("http://www.example.com"). +// Body(foo) // -// // Stream body -// PostRequest("http://www.example.com"). -// Body(strings.NewReader("abcde")) +// // String body +// PostRequest("http://www.example.com"). +// Body("{\"bar\": \"val\"}") // -// // Multipart POST request -// var f *os.File -// PostRequest("http://www.example.com"). -// Field("foo", "bar"). -// File("file1", File{Name: f.Name(), Content: f}). -// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"}) +// // Stream body +// PostRequest("http://www.example.com"). +// Body(strings.NewReader("abcde")) +// +// // Multipart POST request +// var f *os.File +// PostRequest("http://www.example.com"). +// Field("foo", "bar"). +// File("file1", File{Name: f.Name(), Content: f}). +// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"}) package rest import ( @@ -79,6 +80,8 @@ type Request struct { queryParams url.Values formParams url.Values + basicAuthn *BasicAuthInfo + // files to upload files map[string][]File @@ -86,6 +89,11 @@ type Request struct { body interface{} } +type BasicAuthInfo struct { + user string + pass string +} + // NewRequest creates a new request with a given rawUrl. func NewRequest(rawUrl string) *Request { return &Request{ @@ -165,6 +173,14 @@ func (r *Request) Set(key string, value string) *Request { return r } +func (r *Request) SetBasicAuth(user string, pass string) *Request { + r.basicAuthn = &BasicAuthInfo{ + user: user, + pass: pass, + } + return r +} + // Query appends the key, value pair to the request query which will be // encoded as url query parameters on HTTP request's url. func (r *Request) Query(key string, value string) *Request { @@ -210,6 +226,10 @@ func (r *Request) Build() (*http.Request, error) { return req, err } + if r.basicAuthn != nil { + req.SetBasicAuth(r.basicAuthn.user, r.basicAuthn.pass) + } + for k, vs := range r.header { for _, v := range vs { req.Header.Add(k, v)