Skip to content

Commit

Permalink
Merge pull request #12 from synadia-io/fix-7
Browse files Browse the repository at this point in the history
[FIX] renamed package to `authb`
  • Loading branch information
aricart authored Nov 7, 2023
2 parents c2ce868 + 6e4726b commit dd6ea9d
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion account_jstieredlimits.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion account_limits.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

type accountLimits struct {
data *AccountData
Expand Down
2 changes: 1 addition & 1 deletion account_signingkeys.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import (
"github.com/nats-io/jwt/v2"
Expand Down
2 changes: 1 addition & 1 deletion accounts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion key.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import (
"github.com/nats-io/nkeys"
Expand Down
2 changes: 1 addition & 1 deletion operator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import (
"github.com/nats-io/jwt/v2"
Expand Down
2 changes: 1 addition & 1 deletion operator_signingkeys.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import "github.com/nats-io/nkeys"

Expand Down
36 changes: 18 additions & 18 deletions providers/nsc/nsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (a *NscProvider) MaybeMakeDir(path string) error {
return err
}

func (a *NscProvider) Load() ([]*nats_auth.OperatorData, error) {
var operators []*nats_auth.OperatorData
func (a *NscProvider) Load() ([]*authb.OperatorData, error) {
var operators []*authb.OperatorData
if err := a.MaybeMakeDir(a.storesDir); err != nil {
return nil, err
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (a *NscProvider) loadStore(name string) (store.IStore, error) {
return nil, err
}

func (a *NscProvider) loadOperator(si store.IStore) (*nats_auth.OperatorData, error) {
func (a *NscProvider) loadOperator(si store.IStore) (*authb.OperatorData, error) {
token, err := si.ReadRawOperatorClaim()
if err != nil {
return nil, err
Expand All @@ -83,20 +83,20 @@ func (a *NscProvider) loadOperator(si store.IStore) (*nats_auth.OperatorData, er
if err != nil {
return nil, err
}
od := &nats_auth.OperatorData{BaseData: nats_auth.BaseData{EntityName: si.GetName(), Loaded: oc.IssuedAt}, Claim: oc}
od := &authb.OperatorData{BaseData: authb.BaseData{EntityName: si.GetName(), Loaded: oc.IssuedAt}, Claim: oc}
ks := store.NewKeyStore(od.EntityName)
kp, err := ks.GetKeyPair(oc.Issuer)
if err != nil {
return nil, err
}
if kp != nil {
od.Key, _ = nats_auth.KeyFromNkey(kp, nkeys.PrefixByteOperator)
od.Key, _ = authb.KeyFromNkey(kp, nkeys.PrefixByteOperator)
}
if len(oc.SigningKeys) > 0 {
for _, sk := range oc.SigningKeys {
skp, _ := ks.GetKeyPair(sk)
if skp != nil {
k, _ := nats_auth.KeyFromNkey(skp, nkeys.PrefixByteOperator)
k, _ := authb.KeyFromNkey(skp, nkeys.PrefixByteOperator)
if k != nil {
od.OperatorSigningKeys = append(od.OperatorSigningKeys, k)
}
Expand All @@ -113,8 +113,8 @@ func (a *NscProvider) loadOperator(si store.IStore) (*nats_auth.OperatorData, er
return od, err
}

func (a *NscProvider) loadAccounts(si store.IStore, ks store.KeyStore) ([]*nats_auth.AccountData, error) {
var datas []*nats_auth.AccountData
func (a *NscProvider) loadAccounts(si store.IStore, ks store.KeyStore) ([]*authb.AccountData, error) {
var datas []*authb.AccountData
accountNames, err := si.ListSubContainers(store.Accounts)
if err != nil {
return nil, err
Expand All @@ -129,8 +129,8 @@ func (a *NscProvider) loadAccounts(si store.IStore, ks store.KeyStore) ([]*nats_
return datas, nil
}

func (a *NscProvider) loadAccount(si store.IStore, ks store.KeyStore, name string) (*nats_auth.AccountData, error) {
ad := &nats_auth.AccountData{BaseData: nats_auth.BaseData{EntityName: name}}
func (a *NscProvider) loadAccount(si store.IStore, ks store.KeyStore, name string) (*authb.AccountData, error) {
ad := &authb.AccountData{BaseData: authb.BaseData{EntityName: name}}
token, err := si.ReadRawAccountClaim(name)
if err != nil {
return nil, err
Expand All @@ -143,13 +143,13 @@ func (a *NscProvider) loadAccount(si store.IStore, ks store.KeyStore, name strin
ad.Loaded = ad.Claim.IssuedAt
k, _ := ks.GetKeyPair(ad.Claim.Subject)
if k != nil {
ad.Key, _ = nats_auth.KeyFromNkey(k, nkeys.PrefixByteAccount)
ad.Key, _ = authb.KeyFromNkey(k, nkeys.PrefixByteAccount)
}
keys := ad.Claim.SigningKeys.Keys()
for _, k := range keys {
skp, _ := ks.GetKeyPair(k)
if skp != nil {
sk, _ := nats_auth.KeyFromNkey(skp, nkeys.PrefixByteOperator)
sk, _ := authb.KeyFromNkey(skp, nkeys.PrefixByteOperator)
if sk != nil {
ad.AccountSigningKeys = append(ad.AccountSigningKeys, sk)
}
Expand All @@ -168,8 +168,8 @@ func (a *NscProvider) loadAccount(si store.IStore, ks store.KeyStore, name strin
return ad, err
}

func (a *NscProvider) loadUsers(si store.IStore, ks store.KeyStore, account string) ([]*nats_auth.UserData, error) {
var datas []*nats_auth.UserData
func (a *NscProvider) loadUsers(si store.IStore, ks store.KeyStore, account string) ([]*authb.UserData, error) {
var datas []*authb.UserData
names, err := si.ListEntries(store.Accounts, account, store.Users)
if err != nil {
return nil, err
Expand All @@ -184,9 +184,9 @@ func (a *NscProvider) loadUsers(si store.IStore, ks store.KeyStore, account stri
return datas, nil
}

func (a *NscProvider) loadUser(si store.IStore, ks store.KeyStore, account string, name string) (*nats_auth.UserData, error) {
func (a *NscProvider) loadUser(si store.IStore, ks store.KeyStore, account string, name string) (*authb.UserData, error) {
var err error
ud := &nats_auth.UserData{BaseData: nats_auth.BaseData{EntityName: name}}
ud := &authb.UserData{BaseData: authb.BaseData{EntityName: name}}
token, err := si.ReadRawUserClaim(account, name)
if err != nil {
return nil, err
Expand All @@ -201,14 +201,14 @@ func (a *NscProvider) loadUser(si store.IStore, ks store.KeyStore, account strin
if err != nil {
return nil, err
}
ud.Key, err = nats_auth.KeyFromNkey(kp, nkeys.PrefixByteUser)
ud.Key, err = authb.KeyFromNkey(kp, nkeys.PrefixByteUser)
if err != nil {
return nil, err
}
return ud, nil
}

func (a *NscProvider) Store(operators []*nats_auth.OperatorData) error {
func (a *NscProvider) Store(operators []*authb.OperatorData) error {
for _, o := range operators {
var err error
ks := store.NewKeyStore(o.EntityName)
Expand Down
2 changes: 1 addition & 1 deletion scope.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nats_auth
package authb

import (
"errors"
Expand Down
24 changes: 12 additions & 12 deletions tests/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package tests

import (
"github.com/stretchr/testify/require"
"github.com/synadia-io/jwt-auth-builder.go"
authb "github.com/synadia-io/jwt-auth-builder.go"
"time"
)

func (suite *ProviderSuite) Test_AccountsCrud() {
t := suite.T()
auth, err := nats_auth.NewAuth(suite.Provider)
auth, err := authb.NewAuth(suite.Provider)
require.NoError(t, err)
o, err := auth.Operators().Add("O")
require.NoError(t, err)
Expand Down Expand Up @@ -50,22 +50,22 @@ func (suite *ProviderSuite) Test_AccountsCrud() {

func (suite *ProviderSuite) Test_AccountsBasics() {
t := suite.T()
auth, err := nats_auth.NewAuth(suite.Provider)
auth, err := authb.NewAuth(suite.Provider)
require.NoError(t, err)
o, err := auth.Operators().Add("O")
require.NoError(t, err)

a, err := o.Accounts().Add("A")
require.NoError(t, err)

ai := a.(*nats_auth.AccountData)
ai := a.(*authb.AccountData)
require.Equal(t, ai.Claim.Subject, a.Subject())
require.Equal(t, o.Subject(), a.Issuer())
}

func setupTestWithOperatorAndAccount(p *ProviderSuite) (nats_auth.Auth, nats_auth.Operator, nats_auth.Account) {
func setupTestWithOperatorAndAccount(p *ProviderSuite) (authb.Auth, authb.Operator, authb.Account) {
t := p.T()
auth, err := nats_auth.NewAuth(p.Provider)
auth, err := authb.NewAuth(p.Provider)
require.NoError(t, err)
o, err := auth.Operators().Add("O")
require.NoError(t, err)
Expand Down Expand Up @@ -230,7 +230,7 @@ func (suite *ProviderSuite) Test_ScopedPermissionsConnectionTimes() {
s, err := a.ScopedSigningKeys().AddScope("admin")
require.NoError(t, err)
times := s.ConnectionTimes()
require.NoError(t, times.Set(nats_auth.TimeRange{Start: "08:00:00", End: "12:00:00"}))
require.NoError(t, times.Set(authb.TimeRange{Start: "08:00:00", End: "12:00:00"}))
require.Len(t, times.List(), 1)
require.NoError(t, auth.Commit())

Expand Down Expand Up @@ -316,7 +316,7 @@ func (suite *ProviderSuite) Test_ScopedPermissionsSubject() {

func (suite *ProviderSuite) Test_ScopeRotation() {
t := suite.T()
auth, err := nats_auth.NewAuth(suite.Provider)
auth, err := authb.NewAuth(suite.Provider)
require.NoError(t, err)
o, err := auth.Operators().Add("O")
require.NoError(t, err)
Expand Down Expand Up @@ -354,7 +354,7 @@ func (suite *ProviderSuite) Test_ScopeRotation() {

func (suite *ProviderSuite) Test_SigningKeyRotation() {
t := suite.T()
auth, err := nats_auth.NewAuth(suite.Provider)
auth, err := authb.NewAuth(suite.Provider)
require.NoError(t, err)
o, err := auth.Operators().Add("O")
require.NoError(t, err)
Expand Down Expand Up @@ -384,7 +384,7 @@ func (suite *ProviderSuite) Test_SigningKeyRotation() {

func (suite *ProviderSuite) Test_AccountLimits() {
t := suite.T()
auth, err := nats_auth.NewAuth(suite.Provider)
auth, err := authb.NewAuth(suite.Provider)
require.NoError(t, err)
o, err := auth.Operators().Add("O")
require.NoError(t, err)
Expand Down Expand Up @@ -424,7 +424,7 @@ func (suite *ProviderSuite) Test_AccountLimits() {
require.True(t, a.Limits().DisallowBearerTokens())
}

func (suite *ProviderSuite) testTier(auth nats_auth.Auth, account nats_auth.Account, tier int8) {
func (suite *ProviderSuite) testTier(auth authb.Auth, account authb.Account, tier int8) {
t := suite.T()
var err error

Expand Down Expand Up @@ -540,7 +540,7 @@ func (suite *ProviderSuite) testTier(auth nats_auth.Auth, account nats_auth.Acco

func (suite *ProviderSuite) Test_AccountJetStreamLimits() {
t := suite.T()
auth, err := nats_auth.NewAuth(suite.Provider)
auth, err := authb.NewAuth(suite.Provider)
require.NoError(t, err)
o, err := auth.Operators().Add("O")
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions tests/jetstreamstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (ts *KvStore) KeyExists(k string) bool {
return v != nil
}

func (ts *KvStore) GetKey(k string) *nats_auth.Key {
func (ts *KvStore) GetKey(k string) *authb.Key {
v, err := ts.provider.GetKey(k)
require.NoError(ts.t, err)
return v
Expand All @@ -49,7 +49,7 @@ func (ts *KvStore) OperatorExists(name string) bool {
}

func (ts *KvStore) GetOperator(name string) *jwt.OperatorClaims {
var v *nats_auth.OperatorData
var v *authb.OperatorData
operators, err := ts.provider.LoadOperators()
require.NoError(ts.t, err)
for _, o := range operators {
Expand Down
4 changes: 2 additions & 2 deletions tests/nscstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func (ts *NscStore) KeyExists(k string) bool {
return err == nil
}

func (ts *NscStore) GetKey(k string) *nats_auth.Key {
func (ts *NscStore) GetKey(k string) *authb.Key {
fp := filepath.Join(ts.KeysDir(), store.KeysDir, k[:1], k[1:3], fmt.Sprintf("%s%s", k, store.NKeyExtension))
d, err := os.ReadFile(fp)
require.NoError(ts.t, err)
key, err := nats_auth.KeyFrom(string(d))
key, err := authb.KeyFrom(string(d))
require.NoError(ts.t, err)
return key
}
Expand Down
Loading

0 comments on commit dd6ea9d

Please sign in to comment.