consistently expect snake case json values in token handler (#4015)
This commit is contained in:
1 parent
a077be691c
commit
f6b9162953
3 files changed
+23
-23
No files matched your search
@@ -18,8 +18,8 @@ import (
|
||||
|
||||
// SearchResult is the struct returned to search requests.
|
||||
type SearchResult struct {
|
||||
Targets []*targets.Target `json:",omitempty"`
|
||||
Sessions []*sessions.Session `json:",omitempty"`
|
||||
Targets []*targets.Target `json:"targets,omitempty"`
|
||||
Sessions []*sessions.Session `json:"sessions,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -24,23 +24,23 @@ type refresher interface {
|
||||
// KeyringToken has keyring held auth token information.
|
||||
type KeyringToken struct {
|
||||
// The keyring type used by boundary to access the auth token
|
||||
KeyringType string
|
||||
KeyringType string `json:"keyring_type"`
|
||||
// The token identifier for the provided keyring type that holds the auth token
|
||||
TokenName string
|
||||
TokenName string `json:"token_name"`
|
||||
}
|
||||
|
||||
// userTokenToAdd is the request body to this handler.
|
||||
type UpsertTokenRequest struct {
|
||||
// BoundaryAddr is a required field for all requests
|
||||
BoundaryAddr string
|
||||
BoundaryAddr string `json:"boundary_addr"`
|
||||
// The id of the auth token asserted to be attempted to be added
|
||||
AuthTokenId string
|
||||
AuthTokenId string `json:"auth_token_id"`
|
||||
// The raw auth token for this user. Either this field or the Keyring field
|
||||
// must be set but not both.
|
||||
AuthToken string
|
||||
AuthToken string `json:"auth_token"`
|
||||
// Keyring is the keyring info used when adding an auth token held in
|
||||
// keyring to the daemon.
|
||||
Keyring *KeyringToken
|
||||
Keyring *KeyringToken `json:"keyring"`
|
||||
}
|
||||
|
||||
func newTokenHandlerFunc(ctx context.Context, repo *cache.Repository, refresher refresher) (http.HandlerFunc, error) {
|
||||
@@ -72,30 +72,30 @@ func newTokenHandlerFunc(ctx context.Context, repo *cache.Repository, refresher
|
||||
|
||||
switch {
|
||||
case perReq.BoundaryAddr == "":
|
||||
writeError(w, "BoundaryAddr is a required field but was empty", http.StatusBadRequest)
|
||||
writeError(w, "boundary_addr is a required field but was empty", http.StatusBadRequest)
|
||||
return
|
||||
case perReq.AuthTokenId == "":
|
||||
writeError(w, "AuthTokenId is a required field but was empty", http.StatusBadRequest)
|
||||
writeError(w, "auth_token_id is a required field but was empty", http.StatusBadRequest)
|
||||
return
|
||||
case perReq.Keyring == nil && perReq.AuthToken == "":
|
||||
writeError(w, "Either keyring info or the authtoken must be provided but were empty", http.StatusBadRequest)
|
||||
writeError(w, "Either keyring info or the auth_token must be provided but were empty", http.StatusBadRequest)
|
||||
return
|
||||
case perReq.Keyring != nil:
|
||||
switch {
|
||||
case perReq.Keyring.TokenName == "":
|
||||
writeError(w, "TokenName is a required field but was empty", http.StatusBadRequest)
|
||||
writeError(w, "keyring.token_name is a required field but was empty", http.StatusBadRequest)
|
||||
return
|
||||
case perReq.Keyring.KeyringType == "":
|
||||
writeError(w, "KeyringType is a required field but was empty", http.StatusBadRequest)
|
||||
writeError(w, "keyring.keyring_type is a required field but was empty", http.StatusBadRequest)
|
||||
return
|
||||
case perReq.Keyring.KeyringType == base.NoneKeyring:
|
||||
writeError(w, fmt.Sprintf("KeyringType is set to %s which is not supported", perReq.Keyring.KeyringType), http.StatusBadRequest)
|
||||
writeError(w, fmt.Sprintf("keyring.keyring_type is set to %s which is not supported", perReq.Keyring.KeyringType), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
case perReq.AuthToken != "":
|
||||
switch {
|
||||
case !strings.HasPrefix(perReq.AuthToken, perReq.AuthTokenId):
|
||||
writeError(w, "The auth token id doesn't match the auth token's prefix", http.StatusBadRequest)
|
||||
writeError(w, "auth_token_id doesn't match the auth_token's prefix", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func TestKeyringToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
require.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "KeyringType is a required field but was empty")
|
||||
assert.Contains(t, apiErr.Message, "keyring_type is a required field but was empty")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
@@ -123,7 +123,7 @@ func TestKeyringToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
require.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "KeyringType is set to none which is not supported")
|
||||
assert.Contains(t, apiErr.Message, "keyring.keyring_type is set to none which is not supported")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
@@ -138,7 +138,7 @@ func TestKeyringToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
assert.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "TokenName is a required field but was empty")
|
||||
assert.Contains(t, apiErr.Message, "keyring.token_name is a required field but was empty")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
@@ -153,7 +153,7 @@ func TestKeyringToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
assert.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "BoundaryAddr is a required field but was empty")
|
||||
assert.Contains(t, apiErr.Message, "boundary_addr is a required field but was empty")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
@@ -168,7 +168,7 @@ func TestKeyringToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
assert.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "AuthTokenId is a required field but was empty")
|
||||
assert.Contains(t, apiErr.Message, "auth_token_id is a required field but was empty")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
@@ -234,7 +234,7 @@ func TestKeyringlessToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
assert.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "BoundaryAddr is a required field but was empty")
|
||||
assert.Contains(t, apiErr.Message, "boundary_addr is a required field but was empty")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
@@ -246,7 +246,7 @@ func TestKeyringlessToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
assert.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "AuthTokenId is a required field but was empty")
|
||||
assert.Contains(t, apiErr.Message, "auth_token_id is a required field but was empty")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
@@ -258,7 +258,7 @@ func TestKeyringlessToken(t *testing.T) {
|
||||
}
|
||||
apiErr := addToken(t, ph, pa)
|
||||
assert.NotNil(t, apiErr)
|
||||
assert.Contains(t, apiErr.Message, "The auth token id doesn't match the auth token's prefix")
|
||||
assert.Contains(t, apiErr.Message, "auth_token_id doesn't match the auth_token's prefix")
|
||||
assert.False(t, tr.called)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user