Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translator: adding ability to read the token request #112

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions token/services/vault/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func (w *Translator) CommitTokenRequest(raw []byte) error {
}
tr, err := w.RWSet.GetState(w.namespace, key)
if err != nil {
return errors.Wrapf(err, "failed to write token request'%s'", w.TxID)
return errors.Wrapf(err, "failed to read token request'%s'", w.TxID)
}
if tr != nil {
if len(tr) != 0 {
return errors.Wrapf(errors.New("token request with same ID already exists"), "failed to write token request'%s'", w.TxID)
}
err = w.RWSet.SetState(w.namespace, key, raw)
Expand All @@ -79,6 +79,18 @@ func (w *Translator) CommitTokenRequest(raw []byte) error {
return nil
}

func (w *Translator) ReadTokenRequest() ([]byte, error) {
key, err := keys.CreateTokenRequestKey(w.TxID)
if err != nil {
return nil, errors.Errorf("can't create for token request '%s'", w.TxID)
}
tr, err := w.RWSet.GetState(w.namespace, key)
if err != nil {
return nil, errors.Wrapf(err, "failed to read token request'%s'", w.TxID)
}
return tr, nil
}

func (w *Translator) checkProcess(action interface{}) error {
if err := w.checkAction(action); err != nil {
return err
Expand Down