Skip to content

Commit

Permalink
Converting the AuthSecret field to a union AuthInfo type
Browse files Browse the repository at this point in the history
This change will enable operators to chose different auth schemes for
brokers, as the OSB API spec begins to support more in the future.

Fixes kubernetes-retired#864
  • Loading branch information
arschles committed Jun 5, 2017
1 parent c3b84ae commit 83d0ed0
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 70 deletions.
7 changes: 4 additions & 3 deletions contrib/examples/apiserver/broker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ spec:
# put the basic auth for the broker in a secret, and reference the secret here.
# service-catalog will use the contents of the secret. The secret should have "username"
# and "password" keys
authSecret:
namespace: some-namespace
name: secret-name
authInfo:
basicAuthSecret:
namespace: some-namespace
name: secret-name
18 changes: 15 additions & 3 deletions pkg/apis/servicecatalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,21 @@ type BrokerSpec struct {
// URL is the address used to communicate with the Broker.
URL string

// AuthSecret is a reference to a Secret containing auth information the
// catalog should use to authenticate to this Broker.
AuthSecret *v1.ObjectReference
// AuthInfo contains the data that the service catalog should use to authenticate
// with the Broker
AuthInfo *BrokerAuthInfo
}

// BrokerAuthInfo is a union type that contains information on one of the authentication methods
// the the service catalog and brokers may support, according to the OpenServiceBroker API
// specification (https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md).
//
// Note that we currently restrict a single broker to have only one of these fields
// set on it.
type BrokerAuthInfo struct {
// BasicAuthSecret is a reference to a Secret containing auth information the
// catalog should use to authenticate to this Broker using basic auth.
BasicAuthSecret *v1.ObjectReference
}

// BrokerStatus represents the current status of a Broker.
Expand Down
211 changes: 194 additions & 17 deletions pkg/apis/servicecatalog/v1alpha1/types.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ func (x *BrokerSpec) CodecEncodeSelf(e *codec1978.Encoder) {
var yyq2 [2]bool
_, _, _ = yysep2, yyq2, yy2arr2
const yyr2 bool = false
yyq2[1] = x.AuthSecret != nil
yyq2[1] = x.AuthInfo != nil
var yynn2 int
if yyr2 || yy2arr2 {
r.EncodeArrayStart(2)
Expand Down Expand Up @@ -871,23 +871,23 @@ func (x *BrokerSpec) CodecEncodeSelf(e *codec1978.Encoder) {
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234)
if yyq2[1] {
if x.AuthSecret == nil {
if x.AuthInfo == nil {
r.EncodeNil()
} else {
x.AuthSecret.CodecEncodeSelf(e)
x.AuthInfo.CodecEncodeSelf(e)
}
} else {
r.EncodeNil()
}
} else {
if yyq2[1] {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("authSecret"))
r.EncodeString(codecSelferC_UTF81234, string("authInfo"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
if x.AuthSecret == nil {
if x.AuthInfo == nil {
r.EncodeNil()
} else {
x.AuthSecret.CodecEncodeSelf(e)
x.AuthInfo.CodecEncodeSelf(e)
}
}
}
Expand Down Expand Up @@ -964,16 +964,16 @@ func (x *BrokerSpec) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
*((*string)(yyv4)) = r.DecodeString()
}
}
case "authSecret":
case "authInfo":
if r.TryDecodeAsNil() {
if x.AuthSecret != nil {
x.AuthSecret = nil
if x.AuthInfo != nil {
x.AuthInfo = nil
}
} else {
if x.AuthSecret == nil {
x.AuthSecret = new(pkg3_v1.ObjectReference)
if x.AuthInfo == nil {
x.AuthInfo = new(BrokerAuthInfo)
}
x.AuthSecret.CodecDecodeSelf(d)
x.AuthInfo.CodecDecodeSelf(d)
}
default:
z.DecStructFieldNotFound(-1, yys3)
Expand Down Expand Up @@ -1023,14 +1023,14 @@ func (x *BrokerSpec) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
}
z.DecSendContainerState(codecSelfer_containerArrayElem1234)
if r.TryDecodeAsNil() {
if x.AuthSecret != nil {
x.AuthSecret = nil
if x.AuthInfo != nil {
x.AuthInfo = nil
}
} else {
if x.AuthSecret == nil {
x.AuthSecret = new(pkg3_v1.ObjectReference)
if x.AuthInfo == nil {
x.AuthInfo = new(BrokerAuthInfo)
}
x.AuthSecret.CodecDecodeSelf(d)
x.AuthInfo.CodecDecodeSelf(d)
}
for {
yyj7++
Expand All @@ -1048,6 +1048,183 @@ func (x *BrokerSpec) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
}

func (x *BrokerAuthInfo) CodecEncodeSelf(e *codec1978.Encoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperEncoder(e)
_, _, _ = h, z, r
if x == nil {
r.EncodeNil()
} else {
yym1 := z.EncBinary()
_ = yym1
if false {
} else if z.HasExtensions() && z.EncExt(x) {
} else {
yysep2 := !z.EncBinary()
yy2arr2 := z.EncBasicHandle().StructToArray
var yyq2 [1]bool
_, _, _ = yysep2, yyq2, yy2arr2
const yyr2 bool = false
yyq2[0] = x.BasicAuthSecret != nil
var yynn2 int
if yyr2 || yy2arr2 {
r.EncodeArrayStart(1)
} else {
yynn2 = 0
for _, b := range yyq2 {
if b {
yynn2++
}
}
r.EncodeMapStart(yynn2)
yynn2 = 0
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234)
if yyq2[0] {
if x.BasicAuthSecret == nil {
r.EncodeNil()
} else {
x.BasicAuthSecret.CodecEncodeSelf(e)
}
} else {
r.EncodeNil()
}
} else {
if yyq2[0] {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("basicAuthSecret"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
if x.BasicAuthSecret == nil {
r.EncodeNil()
} else {
x.BasicAuthSecret.CodecEncodeSelf(e)
}
}
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayEnd1234)
} else {
z.EncSendContainerState(codecSelfer_containerMapEnd1234)
}
}
}
}

func (x *BrokerAuthInfo) CodecDecodeSelf(d *codec1978.Decoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
yym1 := z.DecBinary()
_ = yym1
if false {
} else if z.HasExtensions() && z.DecExt(x) {
} else {
yyct2 := r.ContainerType()
if yyct2 == codecSelferValueTypeMap1234 {
yyl2 := r.ReadMapStart()
if yyl2 == 0 {
z.DecSendContainerState(codecSelfer_containerMapEnd1234)
} else {
x.codecDecodeSelfFromMap(yyl2, d)
}
} else if yyct2 == codecSelferValueTypeArray1234 {
yyl2 := r.ReadArrayStart()
if yyl2 == 0 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
} else {
x.codecDecodeSelfFromArray(yyl2, d)
}
} else {
panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234)
}
}
}

func (x *BrokerAuthInfo) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
var yys3Slc = z.DecScratchBuffer() // default slice to decode into
_ = yys3Slc
var yyhl3 bool = l >= 0
for yyj3 := 0; ; yyj3++ {
if yyhl3 {
if yyj3 >= l {
break
}
} else {
if r.CheckBreak() {
break
}
}
z.DecSendContainerState(codecSelfer_containerMapKey1234)
yys3Slc = r.DecodeBytes(yys3Slc, true, true)
yys3 := string(yys3Slc)
z.DecSendContainerState(codecSelfer_containerMapValue1234)
switch yys3 {
case "basicAuthSecret":
if r.TryDecodeAsNil() {
if x.BasicAuthSecret != nil {
x.BasicAuthSecret = nil
}
} else {
if x.BasicAuthSecret == nil {
x.BasicAuthSecret = new(pkg3_v1.ObjectReference)
}
x.BasicAuthSecret.CodecDecodeSelf(d)
}
default:
z.DecStructFieldNotFound(-1, yys3)
} // end switch yys3
} // end for yyj3
z.DecSendContainerState(codecSelfer_containerMapEnd1234)
}

func (x *BrokerAuthInfo) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
var yyj5 int
var yyb5 bool
var yyhl5 bool = l >= 0
yyj5++
if yyhl5 {
yyb5 = yyj5 > l
} else {
yyb5 = r.CheckBreak()
}
if yyb5 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return
}
z.DecSendContainerState(codecSelfer_containerArrayElem1234)
if r.TryDecodeAsNil() {
if x.BasicAuthSecret != nil {
x.BasicAuthSecret = nil
}
} else {
if x.BasicAuthSecret == nil {
x.BasicAuthSecret = new(pkg3_v1.ObjectReference)
}
x.BasicAuthSecret.CodecDecodeSelf(d)
}
for {
yyj5++
if yyhl5 {
yyb5 = yyj5 > l
} else {
yyb5 = r.CheckBreak()
}
if yyb5 {
break
}
z.DecSendContainerState(codecSelfer_containerArrayElem1234)
z.DecStructFieldNotFound(yyj5-1, "")
}
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
}

func (x *BrokerStatus) CodecEncodeSelf(e *codec1978.Encoder) {
var h codecSelfer1234
z, r := codec1978.GenHelperEncoder(e)
Expand Down
18 changes: 15 additions & 3 deletions pkg/apis/servicecatalog/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@ type BrokerSpec struct {
// URL is the address used to communicate with the Broker.
URL string `json:"url"`

// AuthSecret is a reference to a Secret containing auth information the
// catalog should use to authenticate to this Broker.
AuthSecret *v1.ObjectReference `json:"authSecret,omitempty"`
// AuthInfo contains the data that the service catalog should use to authenticate
// with the Broker
AuthInfo *BrokerAuthInfo `json:"authInfo,omitempty"`
}

// BrokerAuthInfo is a union type that contains information on one of the authentication methods
// the the service catalog and brokers may support, according to the OpenServiceBroker API
// specification (https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md).
//
// Note that we currently restrict a single broker to have only one of these fields
// set on it.
type BrokerAuthInfo struct {
// BasicAuthSecret is a reference to a Secret containing auth information the
// catalog should use to authenticate to this Broker using basic auth.
BasicAuthSecret *v1.ObjectReference `json:"basicAuthSecret,omitempty"`
}

// BrokerStatus represents the current status of a Broker.
Expand Down
24 changes: 22 additions & 2 deletions pkg/apis/servicecatalog/v1alpha1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func RegisterConversions(scheme *runtime.Scheme) error {
Convert_servicecatalog_BindingStatus_To_v1alpha1_BindingStatus,
Convert_v1alpha1_Broker_To_servicecatalog_Broker,
Convert_servicecatalog_Broker_To_v1alpha1_Broker,
Convert_v1alpha1_BrokerAuthInfo_To_servicecatalog_BrokerAuthInfo,
Convert_servicecatalog_BrokerAuthInfo_To_v1alpha1_BrokerAuthInfo,
Convert_v1alpha1_BrokerCondition_To_servicecatalog_BrokerCondition,
Convert_servicecatalog_BrokerCondition_To_v1alpha1_BrokerCondition,
Convert_v1alpha1_BrokerList_To_servicecatalog_BrokerList,
Expand Down Expand Up @@ -225,6 +227,24 @@ func Convert_servicecatalog_Broker_To_v1alpha1_Broker(in *servicecatalog.Broker,
return autoConvert_servicecatalog_Broker_To_v1alpha1_Broker(in, out, s)
}

func autoConvert_v1alpha1_BrokerAuthInfo_To_servicecatalog_BrokerAuthInfo(in *BrokerAuthInfo, out *servicecatalog.BrokerAuthInfo, s conversion.Scope) error {
out.BasicAuthSecret = (*v1.ObjectReference)(unsafe.Pointer(in.BasicAuthSecret))
return nil
}

func Convert_v1alpha1_BrokerAuthInfo_To_servicecatalog_BrokerAuthInfo(in *BrokerAuthInfo, out *servicecatalog.BrokerAuthInfo, s conversion.Scope) error {
return autoConvert_v1alpha1_BrokerAuthInfo_To_servicecatalog_BrokerAuthInfo(in, out, s)
}

func autoConvert_servicecatalog_BrokerAuthInfo_To_v1alpha1_BrokerAuthInfo(in *servicecatalog.BrokerAuthInfo, out *BrokerAuthInfo, s conversion.Scope) error {
out.BasicAuthSecret = (*v1.ObjectReference)(unsafe.Pointer(in.BasicAuthSecret))
return nil
}

func Convert_servicecatalog_BrokerAuthInfo_To_v1alpha1_BrokerAuthInfo(in *servicecatalog.BrokerAuthInfo, out *BrokerAuthInfo, s conversion.Scope) error {
return autoConvert_servicecatalog_BrokerAuthInfo_To_v1alpha1_BrokerAuthInfo(in, out, s)
}

func autoConvert_v1alpha1_BrokerCondition_To_servicecatalog_BrokerCondition(in *BrokerCondition, out *servicecatalog.BrokerCondition, s conversion.Scope) error {
out.Type = servicecatalog.BrokerConditionType(in.Type)
out.Status = servicecatalog.ConditionStatus(in.Status)
Expand Down Expand Up @@ -273,7 +293,7 @@ func Convert_servicecatalog_BrokerList_To_v1alpha1_BrokerList(in *servicecatalog

func autoConvert_v1alpha1_BrokerSpec_To_servicecatalog_BrokerSpec(in *BrokerSpec, out *servicecatalog.BrokerSpec, s conversion.Scope) error {
out.URL = in.URL
out.AuthSecret = (*v1.ObjectReference)(unsafe.Pointer(in.AuthSecret))
out.AuthInfo = (*servicecatalog.BrokerAuthInfo)(unsafe.Pointer(in.AuthInfo))
return nil
}

Expand All @@ -283,7 +303,7 @@ func Convert_v1alpha1_BrokerSpec_To_servicecatalog_BrokerSpec(in *BrokerSpec, ou

func autoConvert_servicecatalog_BrokerSpec_To_v1alpha1_BrokerSpec(in *servicecatalog.BrokerSpec, out *BrokerSpec, s conversion.Scope) error {
out.URL = in.URL
out.AuthSecret = (*v1.ObjectReference)(unsafe.Pointer(in.AuthSecret))
out.AuthInfo = (*BrokerAuthInfo)(unsafe.Pointer(in.AuthInfo))
return nil
}

Expand Down
Loading

0 comments on commit 83d0ed0

Please sign in to comment.