Skip to content

Commit

Permalink
Add kimsufi.GetCurrentCredential, rename TestAuth > GetAuthDetail
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoBrigitte committed Dec 6, 2024
1 parent 97f158f commit b29c485
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pkg/kimsufi/authentication/authentication_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package authentication

type CurrentCredentialResponse struct {
ApplicationID int `json:"applicationId"`
Creation string `json:"creation"`
CredentialID int `json:"credentialId"`
Expiration string `json:"expiration"`
LastUse string `json:"lastUse"`
OVHSupport bool `json:"ovhSupport"`
Rules []CurrentCredentialRule `json:"rules"`
Status string `json:"status"`
}

type CurrentCredentialRule struct {
Method string `json:"method"`
Path string `json:"path"`
}
17 changes: 15 additions & 2 deletions pkg/kimsufi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"

kimsufiauthentication "github.com/TheoBrigitte/kimsufi-notifier/pkg/kimsufi/authentication"
kimsufiavailability "github.com/TheoBrigitte/kimsufi-notifier/pkg/kimsufi/availability"
kimsuficatalog "github.com/TheoBrigitte/kimsufi-notifier/pkg/kimsufi/catalog"
)
Expand Down Expand Up @@ -140,8 +141,8 @@ func (s *Service) ListServers(ovhSubsidiary string) (*kimsuficatalog.Catalog, er
return catalog, nil
}

// TestAuth performs a test API request to check if the client is authenticated.
func (s *Service) TestAuth() error {
// GetAuthDetails performs a test API request to check if the client is authenticated.
func (s *Service) GetAuthDetails() error {
path := "/auth/details"

err := s.client.Get(path, nil)
Expand All @@ -152,6 +153,18 @@ func (s *Service) TestAuth() error {
return nil
}

func (s *Service) GetCurrentCredential() (*kimsufiauthentication.CurrentCredentialResponse, error) {
path := "/auth/currentCredential"

var resp kimsufiauthentication.CurrentCredentialResponse
err := s.client.Get(path, &resp)
if err != nil {
return nil, err
}

return &resp, nil
}

// WithAuth returns a new authenticated Service with the given credentials.
func (s *Service) WithAuth(appKey, appSecret, consumerKey string) (*Service, error) {
authClient, err := ovh.NewClient(s.client.Endpoint(), appKey, appSecret, consumerKey)
Expand Down

0 comments on commit b29c485

Please sign in to comment.