diff --git a/casdoorsdk/email.go b/casdoorsdk/email.go index 0df5af3..f8f8841 100644 --- a/casdoorsdk/email.go +++ b/casdoorsdk/email.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Casdoor Authors. All Rights Reserved. +// 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. @@ -49,7 +49,3 @@ func (c *Client) SendEmail(title string, content string, sender string, receiver return nil } - -func SendEmail(title string, content string, sender string, receivers ...string) error { - return globalClient.SendEmail(title, content, sender, receivers...) -} diff --git a/casdoorsdk/email_global.go b/casdoorsdk/email_global.go new file mode 100644 index 0000000..c5f0cad --- /dev/null +++ b/casdoorsdk/email_global.go @@ -0,0 +1,19 @@ +// 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 SendEmail(title string, content string, sender string, receivers ...string) error { + return globalClient.SendEmail(title, content, sender, receivers...) +} diff --git a/casdoorsdk/enfocer.go b/casdoorsdk/enfocer.go index db00b8e..8a3c161 100644 --- a/casdoorsdk/enfocer.go +++ b/casdoorsdk/enfocer.go @@ -1,3 +1,17 @@ +// 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 ( diff --git a/casdoorsdk/enforcer_global.go b/casdoorsdk/enforcer_global.go index 87019f0..7d9b900 100644 --- a/casdoorsdk/enforcer_global.go +++ b/casdoorsdk/enforcer_global.go @@ -1,3 +1,17 @@ +// 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 GetEnforcers() ([]*Enforcer, error) { diff --git a/casdoorsdk/jwt.go b/casdoorsdk/jwt.go index 11496d7..ab321ca 100644 --- a/casdoorsdk/jwt.go +++ b/casdoorsdk/jwt.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Casdoor Authors. All Rights Reserved. +// 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. @@ -48,7 +48,3 @@ func (c *Client) ParseJwtToken(token string) (*Claims, error) { return nil, err } - -func ParseJwtToken(token string) (*Claims, error) { - return globalClient.ParseJwtToken(token) -} diff --git a/casdoorsdk/jwt_global.go b/casdoorsdk/jwt_global.go new file mode 100644 index 0000000..5cc47a1 --- /dev/null +++ b/casdoorsdk/jwt_global.go @@ -0,0 +1,19 @@ +// 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 ParseJwtToken(token string) (*Claims, error) { + return globalClient.ParseJwtToken(token) +} diff --git a/casdoorsdk/organization.go b/casdoorsdk/organization.go index cc1be15..e16ca73 100644 --- a/casdoorsdk/organization.go +++ b/casdoorsdk/organization.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Casdoor Authors. All Rights Reserved. +// 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. @@ -86,10 +86,6 @@ func (c *Client) GetOrganization(name string) (*Organization, error) { return organization, nil } -func GetOrganization(name string) ([]*Organization, error) { - return globalClient.GetOrganizations() -} - func (c *Client) GetOrganizations() ([]*Organization, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -110,10 +106,6 @@ func (c *Client) GetOrganizations() ([]*Organization, error) { return organizations, nil } -func GetOrganizations() ([]*Organization, error) { - return globalClient.GetOrganizations() -} - func (c *Client) GetOrganizationNames() ([]*Organization, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -134,10 +126,6 @@ func (c *Client) GetOrganizationNames() ([]*Organization, error) { return organizationNames, nil } -func GetOrganizationNames() ([]*Organization, error) { - return globalClient.GetOrganizationNames() -} - func (c *Client) AddOrganization(organization *Organization) (bool, error) { if organization.Owner == "" { organization.Owner = "admin" @@ -146,10 +134,6 @@ func (c *Client) AddOrganization(organization *Organization) (bool, error) { return affected, err } -func AddOrganization(organization *Organization) (bool, error) { - return globalClient.AddOrganization(organization) -} - func (c *Client) DeleteOrganization(name string) (bool, error) { organization := Organization{ Owner: "admin", @@ -160,15 +144,7 @@ func (c *Client) DeleteOrganization(name string) (bool, error) { return affected, err } -func DeleteOrganization(name string) (bool, error) { - return globalClient.DeleteOrganization(name) -} - func (c *Client) UpdateOrganization(organization *Organization) (bool, error) { _, affected, err := c.modifyOrganization("update-organization", organization, nil) return affected, err } - -func UpdateOrganization(organization *Organization) (bool, error) { - return globalClient.UpdateOrganization(organization) -} diff --git a/casdoorsdk/organization_global.go b/casdoorsdk/organization_global.go new file mode 100644 index 0000000..dd6e4a5 --- /dev/null +++ b/casdoorsdk/organization_global.go @@ -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 GetOrganization(name string) ([]*Organization, error) { + return globalClient.GetOrganizations() +} + +func GetOrganizations() ([]*Organization, error) { + return globalClient.GetOrganizations() +} + +func GetOrganizationNames() ([]*Organization, error) { + return globalClient.GetOrganizationNames() +} + +func AddOrganization(organization *Organization) (bool, error) { + return globalClient.AddOrganization(organization) +} + +func DeleteOrganization(name string) (bool, error) { + return globalClient.DeleteOrganization(name) +} + +func UpdateOrganization(organization *Organization) (bool, error) { + return globalClient.UpdateOrganization(organization) +} diff --git a/casdoorsdk/resource.go b/casdoorsdk/resource.go index a62a18e..7e05e3a 100644 --- a/casdoorsdk/resource.go +++ b/casdoorsdk/resource.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Casdoor Authors. All Rights Reserved. +// 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. @@ -61,18 +61,10 @@ func (c *Client) GetResource(id string) (*Resource, error) { return resource, nil } -func GetResource(id string) (*Resource, error) { - return globalClient.GetResource(id) -} - func (c *Client) GetResourceEx(owner, name string) (*Resource, error) { return c.GetResource(fmt.Sprintf("%s/%s", owner, name)) } -func GetResourceEx(owner, name string) (*Resource, error) { - return globalClient.GetResourceEx(owner, name) -} - func (c *Client) GetResources(owner, user, field, value, sortField, sortOrder string) ([]*Resource, error) { queryMap := map[string]string{ "owner": owner, @@ -98,10 +90,6 @@ func (c *Client) GetResources(owner, user, field, value, sortField, sortOrder st return resources, nil } -func GetResources(owner, user, field, value, sortField, sortOrder string) ([]*Resource, error) { - return globalClient.GetResources(owner, user, field, value, sortField, sortOrder) -} - func (c *Client) GetPaginationResources(owner, user, field, value string, pageSize, page int, sortField, sortOrder string) ([]*Resource, error) { queryMap := map[string]string{ "owner": owner, @@ -129,10 +117,6 @@ func (c *Client) GetPaginationResources(owner, user, field, value string, pageSi return resources, nil } -func GetPaginationResources(owner, user, field, value string, pageSize, page int, sortField, sortOrder string) ([]*Resource, error) { - return globalClient.GetPaginationResources(owner, user, field, value, pageSize, page, sortField, sortOrder) -} - func (c *Client) UploadResource(user string, tag string, parent string, fullFilePath string, fileBytes []byte) (string, string, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -157,10 +141,6 @@ func (c *Client) UploadResource(user string, tag string, parent string, fullFile return fileUrl, name, nil } -func UploadResource(user string, tag string, parent string, fullFilePath string, fileBytes []byte) (string, string, error) { - return globalClient.UploadResource(user, tag, parent, fullFilePath, fileBytes) -} - func (c *Client) UploadResourceEx(user string, tag string, parent string, fullFilePath string, fileBytes []byte, createdTime string, description string) (string, string, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -187,10 +167,6 @@ func (c *Client) UploadResourceEx(user string, tag string, parent string, fullFi return fileUrl, name, nil } -func UploadResourceEx(user string, tag string, parent string, fullFilePath string, fileBytes []byte, createdTime string, description string) (string, string, error) { - return globalClient.UploadResourceEx(user, tag, parent, fullFilePath, fileBytes, createdTime, description) -} - func (c *Client) DeleteResource(name string) (bool, error) { resource := Resource{ Owner: c.OrganizationName, @@ -208,7 +184,3 @@ func (c *Client) DeleteResource(name string) (bool, error) { return resp.Data == "Affected", nil } - -func DeleteResource(name string) (bool, error) { - return globalClient.DeleteResource(name) -} diff --git a/casdoorsdk/resource_global.go b/casdoorsdk/resource_global.go new file mode 100644 index 0000000..272661d --- /dev/null +++ b/casdoorsdk/resource_global.go @@ -0,0 +1,43 @@ +// 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 GetResource(id string) (*Resource, error) { + return globalClient.GetResource(id) +} + +func GetResourceEx(owner, name string) (*Resource, error) { + return globalClient.GetResourceEx(owner, name) +} + +func GetResources(owner, user, field, value, sortField, sortOrder string) ([]*Resource, error) { + return globalClient.GetResources(owner, user, field, value, sortField, sortOrder) +} + +func GetPaginationResources(owner, user, field, value string, pageSize, page int, sortField, sortOrder string) ([]*Resource, error) { + return globalClient.GetPaginationResources(owner, user, field, value, pageSize, page, sortField, sortOrder) +} + +func UploadResource(user string, tag string, parent string, fullFilePath string, fileBytes []byte) (string, string, error) { + return globalClient.UploadResource(user, tag, parent, fullFilePath, fileBytes) +} + +func UploadResourceEx(user string, tag string, parent string, fullFilePath string, fileBytes []byte, createdTime string, description string) (string, string, error) { + return globalClient.UploadResourceEx(user, tag, parent, fullFilePath, fileBytes, createdTime, description) +} + +func DeleteResource(name string) (bool, error) { + return globalClient.DeleteResource(name) +} diff --git a/casdoorsdk/role.go b/casdoorsdk/role.go index 5a80d40..487287e 100644 --- a/casdoorsdk/role.go +++ b/casdoorsdk/role.go @@ -1,4 +1,4 @@ -// Copyright 2022 The Casdoor Authors. All Rights Reserved. +// 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. @@ -55,10 +55,6 @@ func (c *Client) GetRoles() ([]*Role, error) { return roles, nil } -func GetRoles() ([]*Role, error) { - return globalClient.GetRoles() -} - func (c *Client) GetPaginationRoles(p int, pageSize int, queryMap map[string]string) ([]*Role, int, error) { queryMap["owner"] = c.OrganizationName queryMap["p"] = strconv.Itoa(p) @@ -78,10 +74,6 @@ func (c *Client) GetPaginationRoles(p int, pageSize int, queryMap map[string]str return roles, int(response.Data2.(float64)), nil } -func GetPaginationRoles(p int, pageSize int, queryMap map[string]string) ([]*Role, int, error) { - return globalClient.GetPaginationRoles(p, pageSize, queryMap) -} - func (c *Client) GetRole(name string) (*Role, error) { queryMap := map[string]string{ "id": fmt.Sprintf("%s/%s", c.OrganizationName, name), @@ -102,42 +94,22 @@ func (c *Client) GetRole(name string) (*Role, error) { return role, nil } -func GetRole(name string) (*Role, error) { - return globalClient.GetRole(name) -} - func (c *Client) UpdateRole(role *Role) (bool, error) { _, affected, err := c.modifyRole("update-role", role, nil) return affected, err } -func UpdateRole(role *Role) (bool, error) { - return globalClient.UpdateRole(role) -} - func (c *Client) UpdateRoleForColumns(role *Role, columns []string) (bool, error) { _, affected, err := c.modifyRole("update-role", role, columns) return affected, err } -func UpdateRoleForColumns(role *Role, columns []string) (bool, error) { - return globalClient.UpdateRoleForColumns(role, columns) -} - func (c *Client) AddRole(role *Role) (bool, error) { _, affected, err := c.modifyRole("add-role", role, nil) return affected, err } -func AddRole(role *Role) (bool, error) { - return globalClient.AddRole(role) -} - func (c *Client) DeleteRole(role *Role) (bool, error) { _, affected, err := c.modifyRole("delete-role", role, nil) return affected, err } - -func DeleteRole(role *Role) (bool, error) { - return globalClient.DeleteRole(role) -} diff --git a/casdoorsdk/role_global.go b/casdoorsdk/role_global.go new file mode 100644 index 0000000..ff799d2 --- /dev/null +++ b/casdoorsdk/role_global.go @@ -0,0 +1,43 @@ +// 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 GetRoles() ([]*Role, error) { + return globalClient.GetRoles() +} + +func GetPaginationRoles(p int, pageSize int, queryMap map[string]string) ([]*Role, int, error) { + return globalClient.GetPaginationRoles(p, pageSize, queryMap) +} + +func GetRole(name string) (*Role, error) { + return globalClient.GetRole(name) +} + +func UpdateRole(role *Role) (bool, error) { + return globalClient.UpdateRole(role) +} + +func UpdateRoleForColumns(role *Role, columns []string) (bool, error) { + return globalClient.UpdateRoleForColumns(role, columns) +} + +func AddRole(role *Role) (bool, error) { + return globalClient.AddRole(role) +} + +func DeleteRole(role *Role) (bool, error) { + return globalClient.DeleteRole(role) +} diff --git a/casdoorsdk/session.go b/casdoorsdk/session.go index 3a534ef..5cdcd13 100644 --- a/casdoorsdk/session.go +++ b/casdoorsdk/session.go @@ -55,10 +55,6 @@ func (c *Client) GetSessions() ([]*Session, error) { return sessions, nil } -func GetSessions() ([]*Session, error) { - return globalClient.GetSessions() -} - func (c *Client) GetPaginationSessions(p int, pageSize int, queryMap map[string]string) ([]*Session, int, error) { queryMap["owner"] = c.OrganizationName queryMap["p"] = strconv.Itoa(p) @@ -78,10 +74,6 @@ func (c *Client) GetPaginationSessions(p int, pageSize int, queryMap map[string] return sessions, int(response.Data2.(float64)), nil } -func GetPaginationSessions(p int, pageSize int, queryMap map[string]string) ([]*Session, int, error) { - return globalClient.GetPaginationSessions(p, pageSize, queryMap) -} - func (c *Client) GetSession(name string) (*Session, error) { queryMap := map[string]string{ "id": fmt.Sprintf("%s/%s", c.OrganizationName, name), @@ -102,42 +94,22 @@ func (c *Client) GetSession(name string) (*Session, error) { return session, nil } -func GetSession(name string) (*Session, error) { - return globalClient.GetSession(name) -} - func (c *Client) UpdateSession(session *Session) (bool, error) { _, affected, err := c.modifySession("update-session", session, nil) return affected, err } -func UpdateSession(session *Session) (bool, error) { - return globalClient.UpdateSession(session) -} - func (c *Client) UpdateSessionForColumns(session *Session, columns []string) (bool, error) { _, affected, err := c.modifySession("update-session", session, columns) return affected, err } -func UpdateSessionForColumns(session *Session, columns []string) (bool, error) { - return globalClient.UpdateSessionForColumns(session, columns) -} - func (c *Client) AddSession(session *Session) (bool, error) { _, affected, err := c.modifySession("add-session", session, nil) return affected, err } -func AddSession(session *Session) (bool, error) { - return globalClient.AddSession(session) -} - func (c *Client) DeleteSession(session *Session) (bool, error) { _, affected, err := c.modifySession("delete-session", session, nil) return affected, err } - -func DeleteSession(session *Session) (bool, error) { - return globalClient.DeleteSession(session) -} diff --git a/casdoorsdk/session_global.go b/casdoorsdk/session_global.go new file mode 100644 index 0000000..e0d2e0f --- /dev/null +++ b/casdoorsdk/session_global.go @@ -0,0 +1,43 @@ +// 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 records and +// limitations under the License. + +package casdoorsdk + +func GetSessions() ([]*Session, error) { + return globalClient.GetSessions() +} + +func GetPaginationSessions(p int, pageSize int, queryMap map[string]string) ([]*Session, int, error) { + return globalClient.GetPaginationSessions(p, pageSize, queryMap) +} + +func GetSession(name string) (*Session, error) { + return globalClient.GetSession(name) +} + +func UpdateSession(session *Session) (bool, error) { + return globalClient.UpdateSession(session) +} + +func UpdateSessionForColumns(session *Session, columns []string) (bool, error) { + return globalClient.UpdateSessionForColumns(session, columns) +} + +func AddSession(session *Session) (bool, error) { + return globalClient.AddSession(session) +} + +func DeleteSession(session *Session) (bool, error) { + return globalClient.DeleteSession(session) +} diff --git a/casdoorsdk/sms.go b/casdoorsdk/sms.go index 9293260..435034c 100644 --- a/casdoorsdk/sms.go +++ b/casdoorsdk/sms.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Casdoor Authors. All Rights Reserved. +// 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. @@ -14,38 +14,6 @@ package casdoorsdk -import ( - "encoding/json" - "fmt" -) - -type smsForm struct { - Content string `json:"content"` - Receivers []string `json:"receivers"` -} - -func (c *Client) SendSms(content string, receivers ...string) error { - form := smsForm{ - Content: content, - Receivers: receivers, - } - postBytes, err := json.Marshal(form) - if err != nil { - return err - } - - resp, err := c.DoPost("send-sms", nil, postBytes, false, false) - if err != nil { - return err - } - - if resp.Status != "ok" { - return fmt.Errorf(resp.Msg) - } - - return nil -} - func SendSms(content string, receivers ...string) error { return globalClient.SendSms(content, receivers...) } diff --git a/casdoorsdk/sms_global.go b/casdoorsdk/sms_global.go new file mode 100644 index 0000000..8d837cc --- /dev/null +++ b/casdoorsdk/sms_global.go @@ -0,0 +1,47 @@ +// 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" + "fmt" +) + +type smsForm struct { + Content string `json:"content"` + Receivers []string `json:"receivers"` +} + +func (c *Client) SendSms(content string, receivers ...string) error { + form := smsForm{ + Content: content, + Receivers: receivers, + } + postBytes, err := json.Marshal(form) + if err != nil { + return err + } + + resp, err := c.DoPost("send-sms", nil, postBytes, false, false) + if err != nil { + return err + } + + if resp.Status != "ok" { + return fmt.Errorf(resp.Msg) + } + + return nil +} diff --git a/casdoorsdk/token.go b/casdoorsdk/token.go index ea0e015..1dac238 100644 --- a/casdoorsdk/token.go +++ b/casdoorsdk/token.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Casdoor Authors. All Rights Reserved. +// 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. @@ -72,10 +72,6 @@ func (c *Client) GetOAuthToken(code string, state string) (*oauth2.Token, error) return token, err } -func GetOAuthToken(code string, state string) (*oauth2.Token, error) { - return globalClient.GetOAuthToken(code, state) -} - // RefreshOAuthToken refreshes the OAuth token func (c *Client) RefreshOAuthToken(refreshToken string) (*oauth2.Token, error) { config := oauth2.Config{ @@ -102,10 +98,6 @@ func (c *Client) RefreshOAuthToken(refreshToken string) (*oauth2.Token, error) { return token, err } -func RefreshOAuthToken(refreshToken string) (*oauth2.Token, error) { - return globalClient.RefreshOAuthToken(refreshToken) -} - func (c *Client) GetTokens(p int, pageSize int) ([]*Token, int, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -128,10 +120,6 @@ func (c *Client) GetTokens(p int, pageSize int) ([]*Token, int, error) { return tokens, int(response.Data2.(float64)), nil } -func GetTokens(p int, pageSize int) ([]*Token, int, error) { - return globalClient.GetTokens(p, pageSize) -} - func (c *Client) DeleteToken(name string) (bool, error) { organization := Organization{ Owner: "admin", @@ -149,7 +137,3 @@ func (c *Client) DeleteToken(name string) (bool, error) { return resp.Data == "Affected", nil } - -func DeleteToken(name string) (bool, error) { - return globalClient.DeleteToken(name) -} diff --git a/casdoorsdk/token_global.go b/casdoorsdk/token_global.go new file mode 100644 index 0000000..07512b2 --- /dev/null +++ b/casdoorsdk/token_global.go @@ -0,0 +1,35 @@ +// 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 ( + "golang.org/x/oauth2" +) + +func GetOAuthToken(code string, state string) (*oauth2.Token, error) { + return globalClient.GetOAuthToken(code, state) +} + +func RefreshOAuthToken(refreshToken string) (*oauth2.Token, error) { + return globalClient.RefreshOAuthToken(refreshToken) +} + +func GetTokens(p int, pageSize int) ([]*Token, int, error) { + return globalClient.GetTokens(p, pageSize) +} + +func DeleteToken(name string) (bool, error) { + return globalClient.DeleteToken(name) +} diff --git a/casdoorsdk/url.go b/casdoorsdk/url.go index 0969379..37ba366 100644 --- a/casdoorsdk/url.go +++ b/casdoorsdk/url.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Casdoor Authors. All Rights Reserved. +// 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. @@ -29,10 +29,6 @@ func (c *Client) GetSignupUrl(enablePassword bool, redirectUri string) string { } } -func GetSignupUrl(enablePassword bool, redirectUri string) string { - return globalClient.GetSignupUrl(enablePassword, redirectUri) -} - func (c *Client) GetSigninUrl(redirectUri string) string { // origin := "https://door.casbin.com" // redirectUri := fmt.Sprintf("%s/callback", origin) @@ -42,10 +38,6 @@ func (c *Client) GetSigninUrl(redirectUri string) string { c.Endpoint, c.ClientId, url.QueryEscape(redirectUri), scope, state) } -func GetSigninUrl(redirectUri string) string { - return globalClient.GetSigninUrl(redirectUri) -} - func (c *Client) GetUserProfileUrl(userName string, accessToken string) string { param := "" if accessToken != "" { @@ -54,10 +46,6 @@ func (c *Client) GetUserProfileUrl(userName string, accessToken string) string { return fmt.Sprintf("%s/users/%s/%s%s", c.Endpoint, c.OrganizationName, userName, param) } -func GetUserProfileUrl(userName string, accessToken string) string { - return globalClient.GetUserProfileUrl(userName, accessToken) -} - func (c *Client) GetMyProfileUrl(accessToken string) string { param := "" if accessToken != "" { @@ -65,7 +53,3 @@ func (c *Client) GetMyProfileUrl(accessToken string) string { } return fmt.Sprintf("%s/account%s", c.Endpoint, param) } - -func GetMyProfileUrl(accessToken string) string { - return globalClient.GetMyProfileUrl(accessToken) -} diff --git a/casdoorsdk/url_global.go b/casdoorsdk/url_global.go new file mode 100644 index 0000000..da9b879 --- /dev/null +++ b/casdoorsdk/url_global.go @@ -0,0 +1,31 @@ +// 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 GetSignupUrl(enablePassword bool, redirectUri string) string { + return globalClient.GetSignupUrl(enablePassword, redirectUri) +} + +func GetSigninUrl(redirectUri string) string { + return globalClient.GetSigninUrl(redirectUri) +} + +func GetUserProfileUrl(userName string, accessToken string) string { + return globalClient.GetUserProfileUrl(userName, accessToken) +} + +func GetMyProfileUrl(accessToken string) string { + return globalClient.GetMyProfileUrl(accessToken) +} diff --git a/casdoorsdk/user.go b/casdoorsdk/user.go index b11aa46..62baf8c 100644 --- a/casdoorsdk/user.go +++ b/casdoorsdk/user.go @@ -222,10 +222,6 @@ func (c *Client) GetGlobalUsers() ([]*User, error) { return users, nil } -func GetGlobalUsers() ([]*User, error) { - return globalClient.GetGlobalUsers() -} - func (c *Client) GetUsers() ([]*User, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -246,10 +242,6 @@ func (c *Client) GetUsers() ([]*User, error) { return users, nil } -func GetUsers() ([]*User, error) { - return globalClient.GetUsers() -} - func (c *Client) GetSortedUsers(sorter string, limit int) ([]*User, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -272,10 +264,6 @@ func (c *Client) GetSortedUsers(sorter string, limit int) ([]*User, error) { return users, nil } -func GetSortedUsers(sorter string, limit int) ([]*User, error) { - return globalClient.GetSortedUsers(sorter, limit) -} - func (c *Client) GetPaginationUsers(p int, pageSize int, queryMap map[string]string) ([]*User, int, error) { queryMap["owner"] = c.OrganizationName queryMap["p"] = strconv.Itoa(p) @@ -296,10 +284,6 @@ func (c *Client) GetPaginationUsers(p int, pageSize int, queryMap map[string]str return users, int(response.Data2.(float64)), nil } -func GetPaginationUsers(p int, pageSize int, queryMap map[string]string) ([]*User, int, error) { - return globalClient.GetPaginationUsers(p, pageSize, queryMap) -} - func (c *Client) GetUserCount(isOnline string) (int, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -321,10 +305,6 @@ func (c *Client) GetUserCount(isOnline string) (int, error) { return count, nil } -func GetUserCount(isOnline string) (int, error) { - return globalClient.GetUserCount(isOnline) -} - func (c *Client) GetUser(name string) (*User, error) { queryMap := map[string]string{ "id": fmt.Sprintf("%s/%s", c.OrganizationName, name), @@ -345,10 +325,6 @@ func (c *Client) GetUser(name string) (*User, error) { return user, nil } -func GetUser(name string) (*User, error) { - return globalClient.GetUser(name) -} - func (c *Client) GetUserByEmail(email string) (*User, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -370,10 +346,6 @@ func (c *Client) GetUserByEmail(email string) (*User, error) { return user, nil } -func GetUserByEmail(email string) (*User, error) { - return globalClient.GetUserByEmail(email) -} - func (c *Client) GetUserByPhone(phone string) (*User, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -395,10 +367,6 @@ func (c *Client) GetUserByPhone(phone string) (*User, error) { return user, nil } -func GetUserByPhone(phone string) (*User, error) { - return globalClient.GetUserByPhone(phone) -} - func (c *Client) GetUserByUserId(userId string) (*User, error) { queryMap := map[string]string{ "owner": c.OrganizationName, @@ -420,10 +388,6 @@ func (c *Client) GetUserByUserId(userId string) (*User, error) { return user, nil } -func GetUserByUserId(userId string) (*User, error) { - return globalClient.GetUserByUserId(userId) -} - // note: oldPassword is not required, if you don't need, just pass a empty string func (c *Client) SetPassword(owner, name, oldPassword, newPassword string) (bool, error) { param := map[string]string{ @@ -446,65 +410,36 @@ func (c *Client) SetPassword(owner, name, oldPassword, newPassword string) (bool return resp.Status == "ok", nil } -// note: oldPassword is not required, if you don't need, just pass a empty string -func SetPassword(owner, name, oldPassword, newPassword string) (bool, error) { - return globalClient.SetPassword(owner, name, oldPassword, newPassword) -} - func (c *Client) UpdateUserById(id string, user *User) (bool, error) { _, affected, err := c.modifyUserById("update-user", id, user, nil) return affected, err } -func UpdateUserById(id string, user *User) (bool, error) { - return globalClient.UpdateUserById(id, user) -} - func (c *Client) UpdateUser(user *User) (bool, error) { _, affected, err := c.modifyUser("update-user", user, nil) return affected, err } -func UpdateUser(user *User) (bool, error) { - return globalClient.UpdateUser(user) -} - func (c *Client) UpdateUserForColumns(user *User, columns []string) (bool, error) { _, affected, err := c.modifyUser("update-user", user, columns) return affected, err } -func UpdateUserForColumns(user *User, columns []string) (bool, error) { - return globalClient.UpdateUserForColumns(user, columns) -} - func (c *Client) AddUser(user *User) (bool, error) { _, affected, err := c.modifyUser("add-user", user, nil) return affected, err } -func AddUser(user *User) (bool, error) { - return globalClient.AddUser(user) -} - func (c *Client) DeleteUser(user *User) (bool, error) { _, affected, err := c.modifyUser("delete-user", user, nil) return affected, err } -func DeleteUser(user *User) (bool, error) { - return globalClient.DeleteUser(user) -} - func (c *Client) CheckUserPassword(user *User) (bool, error) { response, _, err := c.modifyUser("check-user-password", user, nil) return response.Status == "ok", err } -func CheckUserPassword(user *User) (bool, error) { - return globalClient.CheckUserPassword(user) -} - func (u User) GetId() string { return fmt.Sprintf("%s/%s", u.Owner, u.Name) } diff --git a/casdoorsdk/user_global.go b/casdoorsdk/user_global.go new file mode 100644 index 0000000..f1980ff --- /dev/null +++ b/casdoorsdk/user_global.go @@ -0,0 +1,80 @@ +// Copyright 2021 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 GetGlobalUsers() ([]*User, error) { + return globalClient.GetGlobalUsers() +} + +func GetUsers() ([]*User, error) { + return globalClient.GetUsers() +} + +func GetSortedUsers(sorter string, limit int) ([]*User, error) { + return globalClient.GetSortedUsers(sorter, limit) +} + +func GetPaginationUsers(p int, pageSize int, queryMap map[string]string) ([]*User, int, error) { + return globalClient.GetPaginationUsers(p, pageSize, queryMap) +} + +func GetUserCount(isOnline string) (int, error) { + return globalClient.GetUserCount(isOnline) +} + +func GetUser(name string) (*User, error) { + return globalClient.GetUser(name) +} + +func GetUserByEmail(email string) (*User, error) { + return globalClient.GetUserByEmail(email) +} + +func GetUserByPhone(phone string) (*User, error) { + return globalClient.GetUserByPhone(phone) +} + +func GetUserByUserId(userId string) (*User, error) { + return globalClient.GetUserByUserId(userId) +} + +// note: oldPassword is not required, if you don't need, just pass a empty string +func SetPassword(owner, name, oldPassword, newPassword string) (bool, error) { + return globalClient.SetPassword(owner, name, oldPassword, newPassword) +} + +func UpdateUserById(id string, user *User) (bool, error) { + return globalClient.UpdateUserById(id, user) +} + +func UpdateUser(user *User) (bool, error) { + return globalClient.UpdateUser(user) +} + +func UpdateUserForColumns(user *User, columns []string) (bool, error) { + return globalClient.UpdateUserForColumns(user, columns) +} + +func AddUser(user *User) (bool, error) { + return globalClient.AddUser(user) +} + +func DeleteUser(user *User) (bool, error) { + return globalClient.DeleteUser(user) +} + +func CheckUserPassword(user *User) (bool, error) { + return globalClient.CheckUserPassword(user) +}