MCPcopy Create free account
hub / github.com/rilldata/rill / IssueServiceAuthToken

Method IssueServiceAuthToken

admin/auth_token.go:96–116  ·  view source on GitHub ↗

IssueServiceAuthToken generates and persists a new auth token for a service.

(ctx context.Context, serviceID string, ttl *time.Duration)

Source from the content-addressed store, hash-verified

94
95// IssueServiceAuthToken generates and persists a new auth token for a service.
96func (s *Service) IssueServiceAuthToken(ctx context.Context, serviceID string, ttl *time.Duration) (AuthToken, error) {
97 tkn := authtoken.NewRandom(authtoken.TypeService)
98
99 var expiresOn *time.Time
100 if ttl != nil {
101 t := time.Now().Add(*ttl)
102 expiresOn = &t
103 }
104
105 sat, err := s.DB.InsertServiceAuthToken(ctx, &database.InsertServiceAuthTokenOptions{
106 ID: tkn.ID.String(),
107 SecretHash: tkn.SecretHash(),
108 ServiceID: serviceID,
109 ExpiresOn: expiresOn,
110 })
111 if err != nil {
112 return nil, err
113 }
114
115 return &serviceAuthToken{model: sat, token: tkn}, nil
116}
117
118// deploymentAuthToken implements AuthToken for tokens belonging to a deployment.
119type deploymentAuthToken struct {

Callers

nothing calls this directly

Calls 5

NewRandomFunction · 0.92
SecretHashMethod · 0.80
AddMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected