-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12fb1a6
commit 827034f
Showing
17 changed files
with
386 additions
and
173 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
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 |
---|---|---|
@@ -1,13 +1,30 @@ | ||
module conjur-in-go | ||
|
||
go 1.14 | ||
go 1.19 | ||
|
||
require ( | ||
github.com/gorilla/handlers v1.5.1 | ||
github.com/gorilla/mux v1.8.0 | ||
github.com/mitchellh/go-homedir v1.1.0 | ||
github.com/spf13/cobra v1.1.3 | ||
github.com/spf13/viper v1.7.0 | ||
gorm.io/driver/postgres v1.0.8 | ||
gorm.io/gorm v1.21.8 | ||
) | ||
|
||
require ( | ||
github.com/felixge/httpsnoop v1.0.1 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect | ||
github.com/jackc/pgconn v1.8.0 // indirect | ||
github.com/jackc/pgio v1.0.0 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgproto3/v2 v2.0.6 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect | ||
github.com/jackc/pgtype v1.6.2 // indirect | ||
github.com/jackc/pgx/v4 v4.10.1 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.2 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect | ||
golang.org/x/text v0.3.3 // indirect | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package model | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
"gorm.io/gorm" | ||
|
||
"conjur-in-go/pkg/slosilo" | ||
"conjur-in-go/pkg/slosilo/store" | ||
) | ||
|
||
type Credential struct { | ||
cipher slosilo.SymmetricCipher | ||
RoleId string | ||
ApiKey sql.RawBytes | ||
} | ||
|
||
// // TODO: a better way to do this would be to have some kind of | ||
// // model registry. This registry can be used to carry the context needed for constructing | ||
// // model objects. It can be dependency injectable | ||
|
||
// // TODO: we could also avoid this method of dependency injection by just using context. | ||
// // As long as we have access to *gorm.DB in #AfterFind we can just use that | ||
// func NewCredential(cipher slosilo.SymmetricCipher) *credential { | ||
// return &credential{ | ||
// cipher: cipher, | ||
// } | ||
// } | ||
|
||
func (c Credential) TableName() string { | ||
return "credentials" | ||
} | ||
|
||
func (c *Credential) AfterFind(tx *gorm.DB) (err error) { | ||
decrypt := getKeyStoreFromDb(tx).Cipher().Decrypt | ||
|
||
c.ApiKey, err = decrypt([]byte(c.RoleId), c.ApiKey) | ||
if err != nil { | ||
err = fmt.Errorf("credential decryption failed for role_id=%q", c.RoleId) | ||
} | ||
return | ||
} | ||
|
||
func getKeyStoreFromDb(tx *gorm.DB) *store.KeyStore { | ||
keystore, ok := tx.Statement.Context.Value("keystore").(*store.KeyStore) | ||
if !ok { | ||
panic("no key store") | ||
} | ||
|
||
return keystore | ||
} |
Oops, something went wrong.