-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add missing APIs for objects (#83)
* feat:Add apis for cert. * feat:Add apis for adapter,enforcer,group,model,permission. * feat:Add apis. * fix:remove json. * fix:code format. * fix:update license. * feat: Add global object. * fix: remove duplicate code. * fix: correct copyright year in license.
- Loading branch information
Showing
50 changed files
with
2,683 additions
and
315 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright 2023 The Casdoor Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package casdoorsdk | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
type Adapter struct { | ||
Owner string `xorm:"varchar(100) notnull pk" json:"owner"` | ||
Name string `xorm:"varchar(100) notnull pk" json:"name"` | ||
CreatedTime string `xorm:"varchar(100)" json:"createdTime"` | ||
|
||
Type string `xorm:"varchar(100)" json:"type"` | ||
DatabaseType string `xorm:"varchar(100)" json:"databaseType"` | ||
Host string `xorm:"varchar(100)" json:"host"` | ||
Port int `json:"port"` | ||
User string `xorm:"varchar(100)" json:"user"` | ||
Password string `xorm:"varchar(100)" json:"password"` | ||
Database string `xorm:"varchar(100)" json:"database"` | ||
Table string `xorm:"varchar(100)" json:"table"` | ||
TableNamePrefix string `xorm:"varchar(100)" json:"tableNamePrefix"` | ||
|
||
IsEnabled bool `json:"isEnabled"` | ||
|
||
//*xormadapter.Adapter `xorm:"-" json:"-"` | ||
} | ||
|
||
func (c *Client) GetAdapters() ([]*Adapter, error) { | ||
queryMap := map[string]string{ | ||
"owner": c.OrganizationName, | ||
} | ||
|
||
url := c.GetUrl("get-adapters", queryMap) | ||
|
||
bytes, err := c.DoGetBytes(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var adapters []*Adapter | ||
err = json.Unmarshal(bytes, &adapters) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return adapters, nil | ||
} | ||
|
||
func (c *Client) GetPaginationAdapters(p int, pageSize int, queryMap map[string]string) ([]*Adapter, int, error) { | ||
queryMap["owner"] = c.OrganizationName | ||
queryMap["p"] = strconv.Itoa(p) | ||
queryMap["pageSize"] = strconv.Itoa(pageSize) | ||
|
||
url := c.GetUrl("get-adapters", queryMap) | ||
|
||
response, err := c.DoGetResponse(url) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
adapters, ok := response.Data.([]*Adapter) | ||
if !ok { | ||
return nil, 0, errors.New("response data format is incorrect") | ||
} | ||
|
||
return adapters, int(response.Data2.(float64)), nil | ||
} | ||
|
||
func (c *Client) GetAdapter(name string) (*Adapter, error) { | ||
queryMap := map[string]string{ | ||
"id": fmt.Sprintf("%s/%s", c.OrganizationName, name), | ||
} | ||
|
||
url := c.GetUrl("get-adapter", queryMap) | ||
|
||
bytes, err := c.DoGetBytes(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var adapter *Adapter | ||
err = json.Unmarshal(bytes, &adapter) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return adapter, nil | ||
} | ||
|
||
func (c *Client) UpdateAdapter(adapter *Adapter) (bool, error) { | ||
_, affected, err := c.modifyAdapter("update-adapter", adapter, nil) | ||
return affected, err | ||
} | ||
|
||
func (c *Client) AddAdapter(adapter *Adapter) (bool, error) { | ||
_, affected, err := c.modifyAdapter("add-adapter", adapter, nil) | ||
return affected, err | ||
} | ||
|
||
func (c *Client) DeleteAdapter(adapter *Adapter) (bool, error) { | ||
_, affected, err := c.modifyAdapter("delete-adapter", adapter, nil) | ||
return affected, err | ||
} |
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,39 @@ | ||
// Copyright 2023 The Casdoor Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package casdoorsdk | ||
|
||
func GetAdapters() ([]*Adapter, error) { | ||
return globalClient.GetAdapters() | ||
} | ||
|
||
func GetPaginationAdapters(p int, pageSize int, queryMap map[string]string) ([]*Adapter, int, error) { | ||
return globalClient.GetPaginationAdapters(p, pageSize, queryMap) | ||
} | ||
|
||
func GetAdapter(name string) (*Adapter, error) { | ||
return globalClient.GetAdapter(name) | ||
} | ||
|
||
func UpdateAdapter(adapter *Adapter) (bool, error) { | ||
return globalClient.UpdateAdapter(adapter) | ||
} | ||
|
||
func AddAdapter(adapter *Adapter) (bool, error) { | ||
return globalClient.AddAdapter(adapter) | ||
} | ||
|
||
func DeleteAdapter(adapter *Adapter) (bool, error) { | ||
return globalClient.DeleteAdapter(adapter) | ||
} |
Oops, something went wrong.