Skip to content

Commit

Permalink
feature: pack authnode api
Browse files Browse the repository at this point in the history
Signed-off-by: wenjia322 <[email protected]>
  • Loading branch information
wenjia322 committed Jan 9, 2020
1 parent 6c39ad9 commit 455a23d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 55 deletions.
56 changes: 1 addition & 55 deletions sdk/auth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package auth

import (
"encoding/json"

"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/util/auth"
"github.com/chubaofs/chubaofs/util/cryptoutil"
"github.com/chubaofs/chubaofs/util/keystore"
)

type API struct {
ac *AuthClient
}

func (api *API) GetTicket(clientId string, clientKey string, serviceID string) (ticket *auth.Ticket, err error) {
var (
key []byte
Expand Down Expand Up @@ -47,53 +43,3 @@ func (api *API) GetTicket(clientId string, clientKey string, serviceID string) (
}
return
}

func (api *API) OSSAddCaps(clientID, clientKey, accessKey string, caps []byte) (newAKCaps *keystore.AccessKeyCaps, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
akCaps := &keystore.AccessKeyCaps{
AccessKey: accessKey,
Caps: caps,
}
return api.ac.serveOSSRequest(clientID, clientKey, api.ac.ticket, akCaps, proto.MsgAuthOSAddCapsReq, proto.OSAddCaps)
}

func (api *API) OSSDeleteCaps(clientID, clientKey, accessKey string, caps []byte) (newAKCaps *keystore.AccessKeyCaps, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
akCaps := &keystore.AccessKeyCaps{
AccessKey: accessKey,
Caps: caps,
}
return api.ac.serveOSSRequest(clientID, clientKey, api.ac.ticket, akCaps, proto.MsgAuthOSDeleteCapsReq, proto.OSDeleteCaps)
}

func (api *API) OSSGetCaps(clientID, clientKey, accessKey string) (caps *keystore.AccessKeyCaps, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
akCaps := &keystore.AccessKeyCaps{
AccessKey: accessKey,
}
return api.ac.serveOSSRequest(clientID, clientKey, api.ac.ticket, akCaps, proto.MsgAuthOSGetCapsReq, proto.OSGetCaps)
}

func (api *API) AdminGetCaps(clientID, clientKey, userID string) (res *keystore.KeyInfo, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
keyInfo := &keystore.KeyInfo{
ID: userID,
}
return api.ac.serveAdminRequest(clientID, clientKey, api.ac.ticket, keyInfo, proto.MsgAuthGetCapsReq, proto.AdminGetCaps)
}
82 changes: 82 additions & 0 deletions sdk/auth/api_admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package auth

import (
"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/util/keystore"
)

func (api *API) AdminCreateKey(clientID, clientKey, userID, role string, caps []byte) (res *keystore.KeyInfo, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
keyInfo := &keystore.KeyInfo{
ID: userID,
Role: role,
Caps: caps,
}
return api.ac.serveAdminRequest(clientID, clientKey, api.ac.ticket, keyInfo, proto.MsgAuthCreateKeyReq, proto.AdminCreateKey)
}

func (api *API) AdminDeleteKey(clientID, clientKey, userID string) (res *keystore.KeyInfo, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
keyInfo := &keystore.KeyInfo{
ID: userID,
}
return api.ac.serveAdminRequest(clientID, clientKey, api.ac.ticket, keyInfo, proto.MsgAuthDeleteKeyReq, proto.AdminDeleteKey)
}

func (api *API) AdminGetKey(clientID, clientKey, userID string) (res *keystore.KeyInfo, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
keyInfo := &keystore.KeyInfo{
ID: userID,
}
return api.ac.serveAdminRequest(clientID, clientKey, api.ac.ticket, keyInfo, proto.MsgAuthGetKeyReq, proto.AdminGetKey)
}

func (api *API) AdminAddCaps(clientID, clientKey, userID string, caps []byte) (res *keystore.KeyInfo, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
keyInfo := &keystore.KeyInfo{
ID: userID,
Caps: caps,
}
return api.ac.serveAdminRequest(clientID, clientKey, api.ac.ticket, keyInfo, proto.MsgAuthAddCapsReq, proto.AdminAddCaps)
}

func (api *API) AdminDeleteCaps(clientID, clientKey, userID string, caps []byte) (res *keystore.KeyInfo, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
keyInfo := &keystore.KeyInfo{
ID: userID,
Caps: caps,
}
return api.ac.serveAdminRequest(clientID, clientKey, api.ac.ticket, keyInfo, proto.MsgAuthDeleteCapsReq, proto.AdminDeleteCaps)
}

func (api *API) AdminGetCaps(clientID, clientKey, userID string) (res *keystore.KeyInfo, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
keyInfo := &keystore.KeyInfo{
ID: userID,
}
return api.ac.serveAdminRequest(clientID, clientKey, api.ac.ticket, keyInfo, proto.MsgAuthGetCapsReq, proto.AdminGetCaps)
}
48 changes: 48 additions & 0 deletions sdk/auth/api_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package auth

import (
"github.com/chubaofs/chubaofs/proto"
"github.com/chubaofs/chubaofs/util/keystore"
)

type API struct {
ac *AuthClient
}

func (api *API) OSSAddCaps(clientID, clientKey, accessKey string, caps []byte) (newAKCaps *keystore.AccessKeyCaps, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
akCaps := &keystore.AccessKeyCaps{
AccessKey: accessKey,
Caps: caps,
}
return api.ac.serveOSSRequest(clientID, clientKey, api.ac.ticket, akCaps, proto.MsgAuthOSAddCapsReq, proto.OSAddCaps)
}

func (api *API) OSSDeleteCaps(clientID, clientKey, accessKey string, caps []byte) (newAKCaps *keystore.AccessKeyCaps, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
akCaps := &keystore.AccessKeyCaps{
AccessKey: accessKey,
Caps: caps,
}
return api.ac.serveOSSRequest(clientID, clientKey, api.ac.ticket, akCaps, proto.MsgAuthOSDeleteCapsReq, proto.OSDeleteCaps)
}

func (api *API) OSSGetCaps(clientID, clientKey, accessKey string) (caps *keystore.AccessKeyCaps, err error) {
if api.ac.ticket == nil {
if api.ac.ticket, err = api.GetTicket(clientID, clientKey, proto.AuthServiceID); err != nil {
return
}
}
akCaps := &keystore.AccessKeyCaps{
AccessKey: accessKey,
}
return api.ac.serveOSSRequest(clientID, clientKey, api.ac.ticket, akCaps, proto.MsgAuthOSGetCapsReq, proto.OSGetCaps)
}

0 comments on commit 455a23d

Please sign in to comment.