|
| 1 | +// |
| 2 | +// Copyright (C) 2025 IOTech Ltd |
| 3 | +// |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +package http |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + |
| 11 | + "github.com/edgexfoundry/go-mod-core-contracts/v4/clients" |
| 12 | + "github.com/edgexfoundry/go-mod-core-contracts/v4/clients/http/utils" |
| 13 | + "github.com/edgexfoundry/go-mod-core-contracts/v4/clients/interfaces" |
| 14 | + "github.com/edgexfoundry/go-mod-core-contracts/v4/common" |
| 15 | + dtoCommon "github.com/edgexfoundry/go-mod-core-contracts/v4/dtos/common" |
| 16 | + "github.com/edgexfoundry/go-mod-core-contracts/v4/errors" |
| 17 | +) |
| 18 | + |
| 19 | +type SecretStoreTokenClient struct { |
| 20 | + baseUrlFunc clients.ClientBaseUrlFunc |
| 21 | + authInjector interfaces.AuthenticationInjector |
| 22 | +} |
| 23 | + |
| 24 | +// NewSecretStoreTokenClient creates an instance of SecretStoreTokenClient |
| 25 | +func NewSecretStoreTokenClient(baseUrl string, authInjector interfaces.AuthenticationInjector) interfaces.SecretStoreTokenClient { |
| 26 | + return &SecretStoreTokenClient{ |
| 27 | + baseUrlFunc: clients.GetDefaultClientBaseUrlFunc(baseUrl), |
| 28 | + authInjector: authInjector, |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// NewSecretStoreTokenClientWithUrlCallback creates an instance of SecretStoreTokenClient with ClientBaseUrlFunc. |
| 33 | +func NewSecretStoreTokenClientWithUrlCallback(baseUrlFunc clients.ClientBaseUrlFunc, authInjector interfaces.AuthenticationInjector) interfaces.AuthClient { |
| 34 | + return &AuthClient{ |
| 35 | + baseUrlFunc: baseUrlFunc, |
| 36 | + authInjector: authInjector, |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +// RegenToken regenerates the secret store client token based on the specified entity id |
| 41 | +func (ac *SecretStoreTokenClient) RegenToken(ctx context.Context, entityId string) (dtoCommon.BaseResponse, errors.EdgeX) { |
| 42 | + var response dtoCommon.BaseResponse |
| 43 | + baseUrl, err := clients.GetBaseUrl(ac.baseUrlFunc) |
| 44 | + if err != nil { |
| 45 | + return response, errors.NewCommonEdgeXWrapper(err) |
| 46 | + } |
| 47 | + |
| 48 | + path := common.NewPathBuilder().SetPath(common.ApiTokenRoute).SetPath(common.EntityId).SetPath(entityId).BuildPath() |
| 49 | + err = utils.PutRequest(ctx, &response, baseUrl, path, nil, nil, ac.authInjector) |
| 50 | + if err != nil { |
| 51 | + return response, errors.NewCommonEdgeXWrapper(err) |
| 52 | + } |
| 53 | + return response, nil |
| 54 | +} |
0 commit comments