New Upstream Release - golang-gopkg-jcmturner-goidentity.v2

Ready changes

Summary

Merged new upstream version: 6.0.1 (was: 2.0.0).

Resulting package

Built on 2023-01-27T13:46 (took 2m47s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-gopkg-jcmturner-goidentity.v2-dev

Lintian Result

Diff

diff --git a/README.md b/README.md
index e8dd19b..6d0dbad 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,9 @@
 # goidentity
 
-Standard interface to holding authenticated identities and their attributes.
+Standard interface for holding authenticated identities and their attributes.
 
-To get the package, execute:
-```
-go get gopkg.in/jcmturner/goidentity.v2
-```
-To import this package, add the following line to your code:
-```go
-import "gopkg.in/jcmturner/goidentity.v2"
+This project has now been converted to use Go modules. Please refer to the latest major version sub directory.
+This follows the practice outlines at https://blog.golang.org/v2-go-modules
+
+[![Version](https://img.shields.io/github/v/release/jcmturner/goidentity?label=Version&sort=semver)](https://github.com/jcmturner/goidentity/releases)
 
-```
\ No newline at end of file
diff --git a/debian/changelog b/debian/changelog
index f562d88..127328c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-gopkg-jcmturner-goidentity.v2 (6.0.1-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Fri, 27 Jan 2023 13:44:03 -0000
+
 golang-gopkg-jcmturner-goidentity.v2 (2.0.0-2) unstable; urgency=medium
 
   * Reupload as source-only
diff --git a/identity.go b/identity.go
index c1543f6..f55d3b4 100644
--- a/identity.go
+++ b/identity.go
@@ -1,6 +1,10 @@
 package goidentity
 
-import "time"
+import (
+	"context"
+	"net/http"
+	"time"
+)
 
 const (
 	CTXKey = "jcmturner/goidentity"
@@ -25,4 +29,24 @@ type Identity interface {
 	Authorized(a string) bool
 	SessionID() string
 	Expired() bool
+	Attributes() map[string]interface{}
+	SetAttribute(k string, v interface{})
+	SetAttributes(map[string]interface{})
+	RemoveAttribute(k string)
+	Marshal() ([]byte, error)
+	Unmarshal([]byte) error
+}
+
+func AddToHTTPRequestContext(id Identity, r *http.Request) *http.Request {
+	ctx := r.Context()
+	ctx = context.WithValue(ctx, CTXKey, id)
+	return r.WithContext(ctx)
+}
+
+func FromHTTPRequestContext(r *http.Request) Identity {
+	ctx := r.Context()
+	if id, ok := ctx.Value(CTXKey).(Identity); ok {
+		return id
+	}
+	return nil
 }
diff --git a/user.go b/user.go
index 623db58..88a7388 100644
--- a/user.go
+++ b/user.go
@@ -1,6 +1,8 @@
 package goidentity
 
 import (
+	"bytes"
+	"encoding/gob"
 	"github.com/hashicorp/go-uuid"
 	"time"
 )
@@ -16,6 +18,7 @@ type User struct {
 	authTime        time.Time
 	sessionID       string
 	expiry          time.Time
+	attributes      map[string]interface{}
 }
 
 func NewUser(username string) User {
@@ -135,3 +138,35 @@ func (u *User) Expired() bool {
 	}
 	return false
 }
+
+func (u *User) Attributes() map[string]interface{} {
+	return u.attributes
+}
+
+func (u *User) SetAttribute(k string, v interface{}) {
+	u.attributes[k] = v
+}
+
+func (u *User) SetAttributes(a map[string]interface{}) {
+	u.attributes = a
+}
+
+func (u *User) RemoveAttribute(k string) {
+	delete(u.attributes, k)
+}
+
+func (u *User) Marshal() ([]byte, error) {
+	buf := new(bytes.Buffer)
+	enc := gob.NewEncoder(buf)
+	err := enc.Encode(u)
+	if err != nil {
+		return []byte{}, err
+	}
+	return buf.Bytes(), nil
+}
+
+func (u *User) Unmarshal(b []byte) error {
+	buf := bytes.NewBuffer(b)
+	dec := gob.NewDecoder(buf)
+	return dec.Decode(u)
+}
diff --git a/user_test.go b/user_test.go
index dbf2fa7..0ac6571 100644
--- a/user_test.go
+++ b/user_test.go
@@ -7,6 +7,5 @@ import (
 
 func TestUserImplementsInterface(t *testing.T) {
 	u := new(User)
-	i := new(Identity)
-	assert.Implements(t, i, u, "User type does not implement the Identity interface")
+	assert.Implements(t, (*Identity)(nil), u, "User type does not implement the Identity interface")
 }
diff --git a/v6/README.md b/v6/README.md
new file mode 100644
index 0000000..3e15042
--- /dev/null
+++ b/v6/README.md
@@ -0,0 +1,7 @@
+# goidentity
+[![GoDoc](https://godoc.org/github.com/jcmturner/goidentity/v6?status.svg)](https://godoc.org/github.com/jcmturner/goidentity/v6) [![Go Report Card](https://goreportcard.com/badge/github.com/jcmturner/goidentity/v6)](https://goreportcard.com/report/github.com/jcmturner/goidentity/v6)
+
+Please import as below
+```
+import "github.com/jcmturner/goidentity/v6"
+```
diff --git a/v6/authenticator.go b/v6/authenticator.go
new file mode 100644
index 0000000..42ec79b
--- /dev/null
+++ b/v6/authenticator.go
@@ -0,0 +1,6 @@
+package goidentity
+
+type Authenticator interface {
+	Authenticate() (Identity, bool, error)
+	Mechanism() string // gives the name of the type of authentication mechanism
+}
diff --git a/v6/go.mod b/v6/go.mod
new file mode 100644
index 0000000..73cb36b
--- /dev/null
+++ b/v6/go.mod
@@ -0,0 +1,8 @@
+module github.com/jcmturner/goidentity/v6
+
+go 1.13
+
+require (
+	github.com/hashicorp/go-uuid v1.0.2
+	github.com/stretchr/testify v1.4.0
+)
diff --git a/v6/go.sum b/v6/go.sum
new file mode 100644
index 0000000..92979e4
--- /dev/null
+++ b/v6/go.sum
@@ -0,0 +1,12 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
+github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/v6/identity.go b/v6/identity.go
new file mode 100644
index 0000000..f55d3b4
--- /dev/null
+++ b/v6/identity.go
@@ -0,0 +1,52 @@
+package goidentity
+
+import (
+	"context"
+	"net/http"
+	"time"
+)
+
+const (
+	CTXKey = "jcmturner/goidentity"
+)
+
+type Identity interface {
+	UserName() string
+	SetUserName(s string)
+	Domain() string
+	SetDomain(s string)
+	DisplayName() string
+	SetDisplayName(s string)
+	Human() bool
+	SetHuman(b bool)
+	AuthTime() time.Time
+	SetAuthTime(t time.Time)
+	AuthzAttributes() []string
+	AddAuthzAttribute(a string)
+	RemoveAuthzAttribute(a string)
+	Authenticated() bool
+	SetAuthenticated(b bool)
+	Authorized(a string) bool
+	SessionID() string
+	Expired() bool
+	Attributes() map[string]interface{}
+	SetAttribute(k string, v interface{})
+	SetAttributes(map[string]interface{})
+	RemoveAttribute(k string)
+	Marshal() ([]byte, error)
+	Unmarshal([]byte) error
+}
+
+func AddToHTTPRequestContext(id Identity, r *http.Request) *http.Request {
+	ctx := r.Context()
+	ctx = context.WithValue(ctx, CTXKey, id)
+	return r.WithContext(ctx)
+}
+
+func FromHTTPRequestContext(r *http.Request) Identity {
+	ctx := r.Context()
+	if id, ok := ctx.Value(CTXKey).(Identity); ok {
+		return id
+	}
+	return nil
+}
diff --git a/v6/user.go b/v6/user.go
new file mode 100644
index 0000000..88a7388
--- /dev/null
+++ b/v6/user.go
@@ -0,0 +1,172 @@
+package goidentity
+
+import (
+	"bytes"
+	"encoding/gob"
+	"github.com/hashicorp/go-uuid"
+	"time"
+)
+
+type User struct {
+	authenticated   bool
+	domain          string
+	userName        string
+	displayName     string
+	email           string
+	human           bool
+	groupMembership map[string]bool
+	authTime        time.Time
+	sessionID       string
+	expiry          time.Time
+	attributes      map[string]interface{}
+}
+
+func NewUser(username string) User {
+	uuid, err := uuid.GenerateUUID()
+	if err != nil {
+		uuid = "00unique-sess-ions-uuid-unavailable0"
+	}
+	return User{
+		userName:        username,
+		groupMembership: make(map[string]bool),
+		sessionID:       uuid,
+	}
+}
+
+func (u *User) UserName() string {
+	return u.userName
+}
+
+func (u *User) SetUserName(s string) {
+	u.userName = s
+}
+
+func (u *User) Domain() string {
+	return u.domain
+}
+
+func (u *User) SetDomain(s string) {
+	u.domain = s
+}
+
+func (u *User) DisplayName() string {
+	if u.displayName == "" {
+		return u.userName
+	}
+	return u.displayName
+}
+
+func (u *User) SetDisplayName(s string) {
+	u.displayName = s
+}
+
+func (u *User) Human() bool {
+	return u.human
+}
+
+func (u *User) SetHuman(b bool) {
+	u.human = b
+}
+
+func (u *User) AuthTime() time.Time {
+	return u.authTime
+}
+
+func (u *User) SetAuthTime(t time.Time) {
+	u.authTime = t
+}
+
+func (u *User) AuthzAttributes() []string {
+	s := make([]string, len(u.groupMembership))
+	i := 0
+	for a := range u.groupMembership {
+		s[i] = a
+		i++
+	}
+	return s
+}
+
+func (u *User) Authenticated() bool {
+	return u.authenticated
+}
+
+func (u *User) SetAuthenticated(b bool) {
+	u.authenticated = b
+}
+
+func (u *User) AddAuthzAttribute(a string) {
+	u.groupMembership[a] = true
+}
+
+func (u *User) RemoveAuthzAttribute(a string) {
+	if _, ok := u.groupMembership[a]; !ok {
+		return
+	}
+	delete(u.groupMembership, a)
+}
+
+func (u *User) EnableAuthzAttribute(a string) {
+	if enabled, ok := u.groupMembership[a]; ok && !enabled {
+		u.groupMembership[a] = true
+	}
+}
+
+func (u *User) DisableAuthzAttribute(a string) {
+	if enabled, ok := u.groupMembership[a]; ok && enabled {
+		u.groupMembership[a] = false
+	}
+}
+
+func (u *User) Authorized(a string) bool {
+	if enabled, ok := u.groupMembership[a]; ok && enabled {
+		return true
+	}
+	return false
+}
+
+func (u *User) SessionID() string {
+	return u.sessionID
+}
+
+func (u *User) SetExpiry(t time.Time) {
+	u.expiry = t
+}
+
+func (u *User) Expired() bool {
+	if !u.expiry.IsZero() && time.Now().UTC().After(u.expiry) {
+		return true
+	}
+	return false
+}
+
+func (u *User) Attributes() map[string]interface{} {
+	return u.attributes
+}
+
+func (u *User) SetAttribute(k string, v interface{}) {
+	u.attributes[k] = v
+}
+
+func (u *User) SetAttributes(a map[string]interface{}) {
+	u.attributes = a
+}
+
+func (u *User) RemoveAttribute(k string) {
+	delete(u.attributes, k)
+}
+
+func (u *User) Marshal() ([]byte, error) {
+	buf := new(bytes.Buffer)
+	enc := gob.NewEncoder(buf)
+	err := enc.Encode(u)
+	if err != nil {
+		return []byte{}, err
+	}
+	return buf.Bytes(), nil
+}
+
+func (u *User) Unmarshal(b []byte) error {
+	buf := bytes.NewBuffer(b)
+	dec := gob.NewDecoder(buf)
+	return dec.Decode(u)
+}
diff --git a/v6/user_test.go b/v6/user_test.go
new file mode 100644
index 0000000..0ac6571
--- /dev/null
+++ b/v6/user_test.go
@@ -0,0 +1,11 @@
+package goidentity
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestUserImplementsInterface(t *testing.T) {
+	u := new(User)
+	assert.Implements(t, (*Identity)(nil), u, "User type does not implement the Identity interface")
+}

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/gocode/src/gopkg.in/jcmturner/goidentity.v2/v6/authenticator.go
-rw-r--r--  root/root   /usr/share/gocode/src/gopkg.in/jcmturner/goidentity.v2/v6/identity.go
-rw-r--r--  root/root   /usr/share/gocode/src/gopkg.in/jcmturner/goidentity.v2/v6/user.go
-rw-r--r--  root/root   /usr/share/gocode/src/gopkg.in/jcmturner/goidentity.v2/v6/user_test.go

No differences were encountered in the control files

More details

Full run details