github.com/cs3org/reva/v2@v2.27.7/internal/grpc/services/ocminvitemanager/token.go (about) 1 // Copyright 2018-2023 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package ocminvitemanager 20 21 import ( 22 "time" 23 24 userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" 25 invitepb "github.com/cs3org/go-cs3apis/cs3/ocm/invite/v1beta1" 26 typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" 27 "github.com/google/uuid" 28 ) 29 30 // CreateToken creates a InviteToken object for the userID indicated by userID. 31 func CreateToken(expiration time.Duration, userID *userpb.UserId, description string) *invitepb.InviteToken { 32 tokenID := uuid.New().String() 33 now := time.Now() 34 expirationTime := now.Add(expiration) 35 36 return &invitepb.InviteToken{ 37 Token: tokenID, 38 UserId: userID, 39 Expiration: &typesv1beta1.Timestamp{ 40 Seconds: uint64(expirationTime.Unix()), 41 Nanos: 0, 42 }, 43 Description: description, 44 } 45 }