From 7dc2eff83620ce3638c04f1300e31b77df7210e0 Mon Sep 17 00:00:00 2001 From: nohupped Date: Tue, 19 Apr 2016 14:31:16 +0530 Subject: [PATCH 1/6] Add get methods to struct AddRequest wrote get methods to struct AddRequest, as the struct variables are not global, and if I want to compare two add requests before populating it. --- add.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/add.go b/add.go index 61b795e0..aeab3baf 100644 --- a/add.go +++ b/add.go @@ -37,6 +37,13 @@ type AddRequest struct { attributes []Attribute } +func (a AddRequest) GetDNFromAddRequest() string { + return a.dn +} +func (a AddRequest) GetAttributeFromAddRequest() []Attribute { + return a.attributes +} + func (a AddRequest) encode() *ber.Packet { request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationAddRequest, nil, "Add Request") request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.dn, "DN")) From 0c240fdb33f6036cad930797da9180969383e062 Mon Sep 17 00:00:00 2001 From: nohupped Date: Tue, 19 Apr 2016 14:41:57 +0530 Subject: [PATCH 2/6] Changed get method names Changed get method names --- add.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/add.go b/add.go index aeab3baf..fb11324c 100644 --- a/add.go +++ b/add.go @@ -37,10 +37,10 @@ type AddRequest struct { attributes []Attribute } -func (a AddRequest) GetDNFromAddRequest() string { +func (a AddRequest) GetDN() string { return a.dn } -func (a AddRequest) GetAttributeFromAddRequest() []Attribute { +func (a AddRequest) GetAttributes() []Attribute { return a.attributes } From f2d724dd6b2a136ff15319fb8d3b97b8cbe90419 Mon Sep 17 00:00:00 2001 From: nohupped Date: Tue, 19 Apr 2016 17:48:39 +0530 Subject: [PATCH 3/6] Added a SetDN method to AddRequest. Added a SetDN method to AddRequest. A usecase is, the result returned from AD is of uppercase realm for DN, and if a comparison needs to be done against an openldap result, it has to be converted to something similar in lowercase. This method makes it easy, as the SetDN sets the value to the pointer. Eg: ```i.SetDN(r.ReplaceAllStringFunc(input, func(m string) string { return strings.ToLower(m) }))``` --- add.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/add.go b/add.go index fb11324c..3b1cf9a7 100644 --- a/add.go +++ b/add.go @@ -44,6 +44,10 @@ func (a AddRequest) GetAttributes() []Attribute { return a.attributes } +func (a *AddRequest) SetDN(dn string) { + a.dn = dn +} + func (a AddRequest) encode() *ber.Packet { request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationAddRequest, nil, "Add Request") request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.dn, "DN")) From e59ca7b19083ce1b207ea6aa4db93c3d9cad5730 Mon Sep 17 00:00:00 2001 From: "girish.g" Date: Wed, 20 Apr 2016 18:10:36 +0530 Subject: [PATCH 4/6] Removed get methods, and exported struct variables --- add.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/add.go b/add.go index 3b1cf9a7..430260d9 100644 --- a/add.go +++ b/add.go @@ -33,26 +33,16 @@ func (a *Attribute) encode() *ber.Packet { } type AddRequest struct { - dn string - attributes []Attribute + DN string + Attributes []Attribute } -func (a AddRequest) GetDN() string { - return a.dn -} -func (a AddRequest) GetAttributes() []Attribute { - return a.attributes -} - -func (a *AddRequest) SetDN(dn string) { - a.dn = dn -} func (a AddRequest) encode() *ber.Packet { request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationAddRequest, nil, "Add Request") - request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.dn, "DN")) + request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.DN, "DN")) attributes := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Attributes") - for _, attribute := range a.attributes { + for _, attribute := range a.Attributes { attributes.AppendChild(attribute.encode()) } request.AppendChild(attributes) @@ -60,12 +50,12 @@ func (a AddRequest) encode() *ber.Packet { } func (a *AddRequest) Attribute(attrType string, attrVals []string) { - a.attributes = append(a.attributes, Attribute{attrType: attrType, attrVals: attrVals}) + a.Attributes = append(a.Attributes, Attribute{attrType: attrType, attrVals: attrVals}) } func NewAddRequest(dn string) *AddRequest { return &AddRequest{ - dn: dn, + DN: dn, } } From 7fc4f0e98d3d4d33d08ee4d5dc67a1f60475363c Mon Sep 17 00:00:00 2001 From: "girish.g" Date: Fri, 22 Apr 2016 16:32:18 +0530 Subject: [PATCH 5/6] Export Attribute struct's fields --- add.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/add.go b/add.go index 430260d9..c623e3c0 100644 --- a/add.go +++ b/add.go @@ -17,15 +17,17 @@ import ( ) type Attribute struct { - attrType string - attrVals []string + AttrType string + AttrVals []string } + + func (a *Attribute) encode() *ber.Packet { seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Attribute") - seq.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.attrType, "Type")) + seq.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.AttrType, "Type")) set := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSet, nil, "AttributeValue") - for _, value := range a.attrVals { + for _, value := range a.AttrVals { set.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, value, "Vals")) } seq.AppendChild(set) @@ -50,7 +52,7 @@ func (a AddRequest) encode() *ber.Packet { } func (a *AddRequest) Attribute(attrType string, attrVals []string) { - a.Attributes = append(a.Attributes, Attribute{attrType: attrType, attrVals: attrVals}) + a.Attributes = append(a.Attributes, Attribute{AttrType: attrType, AttrVals: attrVals}) } func NewAddRequest(dn string) *AddRequest { From 462eb2298de008cb15bf2aa74c017bd957c001e9 Mon Sep 17 00:00:00 2001 From: "girish.g" Date: Tue, 3 May 2016 00:57:58 +0530 Subject: [PATCH 6/6] Exported attribute Types and Vals of struct Attribute in add.go --- add.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/add.go b/add.go index c623e3c0..48db8212 100644 --- a/add.go +++ b/add.go @@ -17,17 +17,17 @@ import ( ) type Attribute struct { - AttrType string - AttrVals []string + Type string + Vals []string } func (a *Attribute) encode() *ber.Packet { seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Attribute") - seq.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.AttrType, "Type")) + seq.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, a.Type, "Type")) set := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSet, nil, "AttributeValue") - for _, value := range a.AttrVals { + for _, value := range a.Vals { set.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, value, "Vals")) } seq.AppendChild(set) @@ -52,7 +52,7 @@ func (a AddRequest) encode() *ber.Packet { } func (a *AddRequest) Attribute(attrType string, attrVals []string) { - a.Attributes = append(a.Attributes, Attribute{AttrType: attrType, AttrVals: attrVals}) + a.Attributes = append(a.Attributes, Attribute{Type: attrType, Vals: attrVals}) } func NewAddRequest(dn string) *AddRequest {