-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
578 additions
and
27 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,54 @@ | ||
// Copyright 2024 Paul Greenberg [email protected] | ||
// | ||
// 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 authn | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/greenpau/go-authcrunch/pkg/authn/enums/operator" | ||
"github.com/greenpau/go-authcrunch/pkg/ids" | ||
"github.com/greenpau/go-authcrunch/pkg/requests" | ||
"github.com/greenpau/go-authcrunch/pkg/user" | ||
) | ||
|
||
// DeleteUserAPIKey deletes API key from user identity. | ||
func (p *Portal) DeleteUserAPIKey( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore, | ||
bodyData map[string]interface{}) error { | ||
|
||
rr.Key.Usage = "api" | ||
if v, exists := bodyData["id"]; exists { | ||
rr.Key.ID = v.(string) | ||
} else { | ||
resp["message"] = "Profile API did not find id in the request payload" | ||
return handleAPIProfileResponse(w, rr, http.StatusBadRequest, resp) | ||
} | ||
|
||
if err := backend.Request(operator.DeleteAPIKey, rr); err != nil { | ||
resp["message"] = "Profile API failed to delete user api key" | ||
return handleAPIProfileResponse(w, rr, http.StatusInternalServerError, resp) | ||
} | ||
|
||
resp["entry"] = rr.Key.ID | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} |
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,54 @@ | ||
// Copyright 2024 Paul Greenberg [email protected] | ||
// | ||
// 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 authn | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/greenpau/go-authcrunch/pkg/authn/enums/operator" | ||
"github.com/greenpau/go-authcrunch/pkg/ids" | ||
"github.com/greenpau/go-authcrunch/pkg/requests" | ||
"github.com/greenpau/go-authcrunch/pkg/user" | ||
) | ||
|
||
// DeleteUserGPGKey deletes GPG key from user identity. | ||
func (p *Portal) DeleteUserGPGKey( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore, | ||
bodyData map[string]interface{}) error { | ||
|
||
rr.Key.Usage = "gpg" | ||
if v, exists := bodyData["id"]; exists { | ||
rr.Key.ID = v.(string) | ||
} else { | ||
resp["message"] = "Profile API did not find id in the request payload" | ||
return handleAPIProfileResponse(w, rr, http.StatusBadRequest, resp) | ||
} | ||
|
||
if err := backend.Request(operator.DeletePublicKey, rr); err != nil { | ||
resp["message"] = "Profile API failed to delete user GPG key" | ||
return handleAPIProfileResponse(w, rr, http.StatusInternalServerError, resp) | ||
} | ||
|
||
resp["entry"] = rr.Key.ID | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} |
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
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,54 @@ | ||
// Copyright 2024 Paul Greenberg [email protected] | ||
// | ||
// 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 authn | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/greenpau/go-authcrunch/pkg/authn/enums/operator" | ||
"github.com/greenpau/go-authcrunch/pkg/ids" | ||
"github.com/greenpau/go-authcrunch/pkg/requests" | ||
"github.com/greenpau/go-authcrunch/pkg/user" | ||
) | ||
|
||
// DeleteUserSSHKey deletes SSH key from user identity. | ||
func (p *Portal) DeleteUserSSHKey( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore, | ||
bodyData map[string]interface{}) error { | ||
|
||
rr.Key.Usage = "ssh" | ||
if v, exists := bodyData["id"]; exists { | ||
rr.Key.ID = v.(string) | ||
} else { | ||
resp["message"] = "Profile API did not find id in the request payload" | ||
return handleAPIProfileResponse(w, rr, http.StatusBadRequest, resp) | ||
} | ||
|
||
if err := backend.Request(operator.DeletePublicKey, rr); err != nil { | ||
resp["message"] = "Profile API failed to delete user SSH key" | ||
return handleAPIProfileResponse(w, rr, http.StatusInternalServerError, resp) | ||
} | ||
|
||
resp["entry"] = rr.Key.ID | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} |
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,48 @@ | ||
// Copyright 2024 Paul Greenberg [email protected] | ||
// | ||
// 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 authn | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/greenpau/go-authcrunch/pkg/ids" | ||
"github.com/greenpau/go-authcrunch/pkg/requests" | ||
"github.com/greenpau/go-authcrunch/pkg/user" | ||
) | ||
|
||
// FetchDebug fetches debug information. | ||
func (p *Portal) FetchDebug( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore) error { | ||
|
||
entry := make(map[string]interface{}) | ||
database := map[string]interface{}{ | ||
"name": "localdb", | ||
"host": "localhost", | ||
"port": 5432, | ||
"engine": "postgresql", | ||
} | ||
entry["version"] = "1.0.0" | ||
entry["database"] = database | ||
resp["entry"] = entry | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} |
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,76 @@ | ||
// Copyright 2024 Paul Greenberg [email protected] | ||
// | ||
// 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 authn | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/greenpau/go-authcrunch/pkg/authn/enums/operator" | ||
"github.com/greenpau/go-authcrunch/pkg/identity" | ||
"github.com/greenpau/go-authcrunch/pkg/ids" | ||
"github.com/greenpau/go-authcrunch/pkg/requests" | ||
"github.com/greenpau/go-authcrunch/pkg/user" | ||
) | ||
|
||
// FetchUserAPIKeys fetches API keys from user identity. | ||
func (p *Portal) FetchUserAPIKeys( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore) error { | ||
|
||
rr.Key.Usage = "api" | ||
if err := backend.Request(operator.GetAPIKeys, rr); err != nil { | ||
resp["message"] = "Profile API failed to get API keys" | ||
return handleAPIProfileResponse(w, rr, http.StatusInternalServerError, resp) | ||
} | ||
bundle := rr.Response.Payload.(*identity.APIKeyBundle) | ||
resp["entries"] = bundle.Get() | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} | ||
|
||
// FetchUserAPIKey fetches API key from user identity. | ||
func (p *Portal) FetchUserAPIKey( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore, | ||
bodyData map[string]interface{}) error { | ||
|
||
rr.Key.Usage = "api" | ||
if v, exists := bodyData["id"]; exists { | ||
rr.Key.ID = v.(string) | ||
} else { | ||
resp["message"] = "Profile API did not find id in the request payload" | ||
return handleAPIProfileResponse(w, rr, http.StatusBadRequest, resp) | ||
} | ||
|
||
if err := backend.Request(operator.GetAPIKey, rr); err != nil { | ||
resp["message"] = "Profile API failed to get API key" | ||
return handleAPIProfileResponse(w, rr, http.StatusInternalServerError, resp) | ||
} | ||
token := rr.Response.Payload.(*identity.APIKey) | ||
resp["entry"] = token | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} |
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,76 @@ | ||
// Copyright 2024 Paul Greenberg [email protected] | ||
// | ||
// 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 authn | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/greenpau/go-authcrunch/pkg/authn/enums/operator" | ||
"github.com/greenpau/go-authcrunch/pkg/identity" | ||
"github.com/greenpau/go-authcrunch/pkg/ids" | ||
"github.com/greenpau/go-authcrunch/pkg/requests" | ||
"github.com/greenpau/go-authcrunch/pkg/user" | ||
) | ||
|
||
// FetchUserGPGKeys fetches GPG keys from user identity. | ||
func (p *Portal) FetchUserGPGKeys( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore) error { | ||
|
||
rr.Key.Usage = "gpg" | ||
if err := backend.Request(operator.GetPublicKeys, rr); err != nil { | ||
resp["message"] = "Profile API failed to get GPG keys" | ||
return handleAPIProfileResponse(w, rr, http.StatusInternalServerError, resp) | ||
} | ||
bundle := rr.Response.Payload.(*identity.PublicKeyBundle) | ||
resp["entries"] = bundle.Get() | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} | ||
|
||
// FetchUserGPGKey fetches GPG key from user identity. | ||
func (p *Portal) FetchUserGPGKey( | ||
ctx context.Context, | ||
w http.ResponseWriter, | ||
r *http.Request, | ||
rr *requests.Request, | ||
parsedUser *user.User, | ||
resp map[string]interface{}, | ||
usr *user.User, | ||
backend ids.IdentityStore, | ||
bodyData map[string]interface{}) error { | ||
|
||
rr.Key.Usage = "gpg" | ||
if v, exists := bodyData["id"]; exists { | ||
rr.Key.ID = v.(string) | ||
} else { | ||
resp["message"] = "Profile API did not find id in the request payload" | ||
return handleAPIProfileResponse(w, rr, http.StatusBadRequest, resp) | ||
} | ||
|
||
if err := backend.Request(operator.GetPublicKey, rr); err != nil { | ||
resp["message"] = "Profile API failed to get GPG key" | ||
return handleAPIProfileResponse(w, rr, http.StatusInternalServerError, resp) | ||
} | ||
token := rr.Response.Payload.(*identity.PublicKey) | ||
resp["entry"] = token | ||
return handleAPIProfileResponse(w, rr, http.StatusOK, resp) | ||
} |
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
Oops, something went wrong.