diff --git a/generate-protos.sh b/generate-protos.sh index 12942177..fdc63b3e 100644 --- a/generate-protos.sh +++ b/generate-protos.sh @@ -5,7 +5,7 @@ PROTO_DIR="${PROJECT_PATH}/protos" docker run --rm \ -v "$(pwd):${PROJECT_PATH}" \ - -v "$(pwd)/protos:${PROTO_DIR}" \ + -v "$(pwd)/v3/protos:${PROTO_DIR}" \ -w "${PROJECT_PATH}" \ --entrypoint bash \ golang:latest \ diff --git a/v3/pkg/accesscode/accesscode.go b/v3/pkg/accesscode/accesscode.go index d225e2e1..30d88205 100644 --- a/v3/pkg/accesscode/accesscode.go +++ b/v3/pkg/accesscode/accesscode.go @@ -3,11 +3,12 @@ package accesscode import ( "context" "fmt" + "sort" + "time" + hfv1 "github.com/hobbyfarm/gargantua/v3/pkg/apis/hobbyfarm.io/v1" hfClientset "github.com/hobbyfarm/gargantua/v3/pkg/client/clientset/versioned" util2 "github.com/hobbyfarm/gargantua/v3/pkg/util" - "sort" - "time" "github.com/golang/glog" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -48,6 +49,25 @@ func (acc AccessCodeClient) GetAccessCodesWithOTACs(codes []string) ([]hfv1.Acce if err != nil { return nil, fmt.Errorf("error while retrieving one time access codes %v", err) } + if otac.Spec.MaxDuration != "" { + otac.Spec.MaxDuration, err = util2.GetDurationWithDays(otac.Spec.MaxDuration) + + maxDuration, err := time.ParseDuration(otac.Spec.MaxDuration) + if err != nil { + glog.V(4).Infof("Error parsing OTAC %s MaxDuration '%s': %s", otac.Name, otac.Spec.MaxDuration, err) + continue + } + redeemedTimestamp, err := time.Parse(time.UnixDate, otac.Spec.RedeemedTimestamp) + + if err != nil { + return nil, fmt.Errorf("error while parsing redeemedTimestamp time for OTAC %s: %v", otac.Name, err) + } + + if time.Now().After(redeemedTimestamp.Add(maxDuration)) { // if the access code is expired don't return any scenarios + glog.V(4).Infof("OTAC %s reached MaxDuration of %s", otac.Name, otac.Spec.MaxDuration) + continue + } + } codes = append(codes, se.Spec.AccessCode) } diff --git a/v3/pkg/apis/hobbyfarm.io/v1/types.go b/v3/pkg/apis/hobbyfarm.io/v1/types.go index 53a77ea9..28c7e88a 100644 --- a/v3/pkg/apis/hobbyfarm.io/v1/types.go +++ b/v3/pkg/apis/hobbyfarm.io/v1/types.go @@ -412,6 +412,7 @@ type OneTimeAccessCodeList struct { type OneTimeAccessCodeSpec struct { User string `json:"user"` RedeemedTimestamp string `json:"redeemed_timestamp"` + MaxDuration string `json:"max_duration"` } // +genclient diff --git a/v3/pkg/authserver/authserver.go b/v3/pkg/authserver/authserver.go index 29d6609f..7f5d66bf 100644 --- a/v3/pkg/authserver/authserver.go +++ b/v3/pkg/authserver/authserver.go @@ -3,11 +3,13 @@ package authserver import ( "context" "encoding/json" + "net/http" + "time" + "github.com/hobbyfarm/gargantua/v3/pkg/accesscode" hfClientset "github.com/hobbyfarm/gargantua/v3/pkg/client/clientset/versioned" "github.com/hobbyfarm/gargantua/v3/pkg/rbac" util2 "github.com/hobbyfarm/gargantua/v3/pkg/util" - "net/http" "github.com/golang/glog" "github.com/gorilla/mux" @@ -38,6 +40,13 @@ func (a AuthServer) SetupRoutes(r *mux.Router) { glog.V(2).Infof("set up route") } +type PreparedScheduledEvent struct { + Id string `json:"id"` + Description string `json:"description"` + Name string `json:"name"` + EndDate string `json:"end_timestamp"` +} + func (a AuthServer) ListScheduledEventsFunc(w http.ResponseWriter, r *http.Request) { user, err := rbac.AuthenticateRequest(r, a.authClient) if err != nil { @@ -46,7 +55,7 @@ func (a AuthServer) ListScheduledEventsFunc(w http.ResponseWriter, r *http.Reque } // This holds a map of AC -> SE - accessCodeScheduledEvent := make(map[string]string) + accessCodeScheduledEvent := make(map[string]PreparedScheduledEvent) // First we add ScheduledEvents based on OneTimeAccessCodes otacReq, _ := labels.NewRequirement(util2.OneTimeAccessCodeLabel, selection.In, user.GetAccessCodes()) @@ -63,7 +72,24 @@ func (a AuthServer) ListScheduledEventsFunc(w http.ResponseWriter, r *http.Reque if err != nil { continue } - accessCodeScheduledEvent[otac.Name] = se.Spec.Name + endTime := se.Spec.EndTime + + // If OTAC specifies a max Duration we need to calculate the EndTime correctly + if otac.Spec.MaxDuration != "" { + otacEndTime, err := time.Parse(time.UnixDate, otac.Spec.RedeemedTimestamp) + if err != nil { + continue + } + otacDurationWithDays, err := util2.GetDurationWithDays(otac.Spec.MaxDuration) + otacDuration, err := time.ParseDuration(otacDurationWithDays) + if err != nil { + continue + } + otacEndTime = otacEndTime.Add(otacDuration) + endTime = otacEndTime.Format(time.UnixDate) + } + + accessCodeScheduledEvent[otac.Name] = PreparedScheduledEvent{se.Name, se.Spec.Description, se.Spec.Name, endTime} } } @@ -77,7 +103,7 @@ func (a AuthServer) ListScheduledEventsFunc(w http.ResponseWriter, r *http.Reque glog.Error(err) continue } - accessCodeScheduledEvent[ac.Spec.Code] = se.Spec.Name + accessCodeScheduledEvent[ac.Spec.Code] = PreparedScheduledEvent{se.Name, se.Spec.Description, se.Spec.Name, se.Spec.EndTime} } encodedMap, err := json.Marshal(accessCodeScheduledEvent) diff --git a/v3/pkg/scheduledeventserver/scheduledevent.go b/v3/pkg/scheduledeventserver/scheduledevent.go index d6aca6d3..61a8c404 100644 --- a/v3/pkg/scheduledeventserver/scheduledevent.go +++ b/v3/pkg/scheduledeventserver/scheduledevent.go @@ -4,15 +4,16 @@ import ( "context" "encoding/json" "fmt" - hfv1 "github.com/hobbyfarm/gargantua/v3/pkg/apis/hobbyfarm.io/v1" - hfClientset "github.com/hobbyfarm/gargantua/v3/pkg/client/clientset/versioned" - rbac2 "github.com/hobbyfarm/gargantua/v3/pkg/rbac" - util2 "github.com/hobbyfarm/gargantua/v3/pkg/util" "net/http" "strconv" "strings" "time" + hfv1 "github.com/hobbyfarm/gargantua/v3/pkg/apis/hobbyfarm.io/v1" + hfClientset "github.com/hobbyfarm/gargantua/v3/pkg/client/clientset/versioned" + rbac2 "github.com/hobbyfarm/gargantua/v3/pkg/rbac" + util2 "github.com/hobbyfarm/gargantua/v3/pkg/util" + "github.com/hobbyfarm/gargantua/v3/protos/authn" "github.com/hobbyfarm/gargantua/v3/protos/authr" @@ -66,7 +67,7 @@ func (s ScheduledEventServer) SetupRoutes(r *mux.Router) { r.HandleFunc("/a/scheduledevent/new", s.CreateFunc).Methods("POST") r.HandleFunc("/a/scheduledevent/{id}", s.GetFunc).Methods("GET") r.HandleFunc("/a/scheduledevent/{id}", s.UpdateFunc).Methods("PUT") - r.HandleFunc("/a/scheduledevent/{id}/otacs/add/{count}", s.GenerateOTACsFunc).Methods("GET") + r.HandleFunc("/a/scheduledevent/{id}/otacs/add/{count}", s.GenerateOTACsFunc).Methods("POST") r.HandleFunc("/a/scheduledevent/{id}/otacs/delete/{otac}", s.DeleteOTACFunc).Methods("GET") r.HandleFunc("/a/scheduledevent/{id}/otacs/list", s.GetOTACsFunc).Methods("GET") r.HandleFunc("/a/scheduledevent/delete/{id}", s.DeleteFunc).Methods("DELETE") @@ -700,6 +701,8 @@ func (s ScheduledEventServer) GenerateOTACsFunc(w http.ResponseWriter, r *http.R return } + maxDurationValue := r.PostFormValue("max_duration") + scheduledEvent, err := s.hfClientSet.HobbyfarmV1().ScheduledEvents(util2.GetReleaseNamespace()).Get(s.ctx, id, metav1.GetOptions{}) if err != nil { glog.Error(err) @@ -736,6 +739,7 @@ func (s ScheduledEventServer) GenerateOTACsFunc(w http.ResponseWriter, r *http.R Spec: hfv1.OneTimeAccessCodeSpec{ User: "", RedeemedTimestamp: "", + MaxDuration: maxDurationValue, }, } otac, err = s.hfClientSet.HobbyfarmV1().OneTimeAccessCodes(util2.GetReleaseNamespace()).Create(s.ctx, otac, metav1.CreateOptions{}) diff --git a/v3/pkg/util/util.go b/v3/pkg/util/util.go index 2703941b..d7b2ee34 100644 --- a/v3/pkg/util/util.go +++ b/v3/pkg/util/util.go @@ -11,10 +11,11 @@ import ( "encoding/json" "encoding/pem" "fmt" + mrand "math/rand" + hfv1 "github.com/hobbyfarm/gargantua/v3/pkg/apis/hobbyfarm.io/v1" hfClientset "github.com/hobbyfarm/gargantua/v3/pkg/client/clientset/versioned" - "github.com/hobbyfarm/gargantua/v3/pkg/client/listers/hobbyfarm.io/v1" - mrand "math/rand" + v1 "github.com/hobbyfarm/gargantua/v3/pkg/client/listers/hobbyfarm.io/v1" "github.com/golang/glog" "golang.org/x/crypto/ssh" @@ -535,3 +536,21 @@ func GetProtoMarshaller() protojson.MarshalOptions { func StringPtr(s string) *string { return &s } + +// This Method converts a given duration into a valid duration for time.ParseDuration. +// time.ParseDuration does not accept "d" for days +func GetDurationWithDays(s string) (string, error) { + // When the duration is given in days, convert it to hours instead as time.ParseDuration does not accept Days + if strings.HasSuffix(s, "d") { + durationWithoutSuffix := strings.TrimSuffix(s, "d") + // string to int + durationDays, err := strconv.Atoi(durationWithoutSuffix) + if err != nil { + return "", err + } + + s = fmt.Sprintf("%dh", durationDays*24) + } + + return s, nil +} diff --git a/v3/protos/accesscode/accesscode.pb.go b/v3/protos/accesscode/accesscode.pb.go index ec12feb0..98a4135b 100644 --- a/v3/protos/accesscode/accesscode.pb.go +++ b/v3/protos/accesscode/accesscode.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc v3.21.12 // source: accesscode/accesscode.proto @@ -123,6 +123,7 @@ type OneTimeAccessCode struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` User string `protobuf:"bytes,2,opt,name=user,proto3" json:"user,omitempty"` RedeemedTimestamp string `protobuf:"bytes,3,opt,name=redeemed_timestamp,json=redeemedTimestamp,proto3" json:"redeemed_timestamp,omitempty"` + MaxDuration string `protobuf:"bytes,4,opt,name=max_duration,json=maxDuration,proto3" json:"max_duration,omitempty"` } func (x *OneTimeAccessCode) Reset() { @@ -178,6 +179,13 @@ func (x *OneTimeAccessCode) GetRedeemedTimestamp() string { return "" } +func (x *OneTimeAccessCode) GetMaxDuration() string { + if x != nil { + return x.MaxDuration + } + return "" +} + var File_accesscode_accesscode_proto protoreflect.FileDescriptor var file_accesscode_accesscode_proto_rawDesc = []byte{ @@ -190,32 +198,34 @@ var file_accesscode_accesscode_proto_rawDesc = []byte{ 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2a, 0x0a, 0x12, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x69, - 0x64, 0x22, 0x66, 0x0a, 0x11, 0x4f, 0x6e, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x41, 0x63, 0x63, 0x65, - 0x73, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, - 0x64, 0x65, 0x65, 0x6d, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x72, 0x65, 0x64, 0x65, 0x65, 0x6d, 0x65, 0x64, - 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x32, 0xe8, 0x01, 0x0a, 0x0d, 0x41, 0x63, - 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x76, 0x63, 0x12, 0x42, 0x0a, 0x07, 0x47, - 0x65, 0x74, 0x4f, 0x74, 0x61, 0x63, 0x12, 0x17, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, - 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x1a, - 0x1e, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x4f, 0x6e, - 0x65, 0x54, 0x69, 0x6d, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, - 0x44, 0x0a, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x74, 0x61, 0x63, 0x12, 0x1e, 0x2e, - 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x4f, 0x6e, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x1a, 0x16, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4d, 0x0a, 0x11, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x65, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x17, 0x2e, 0x61, 0x63, 0x63, + 0x64, 0x22, 0x89, 0x01, 0x0a, 0x11, 0x4f, 0x6e, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x41, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x2d, 0x0a, 0x12, 0x72, + 0x65, 0x64, 0x65, 0x65, 0x6d, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x72, 0x65, 0x64, 0x65, 0x65, 0x6d, 0x65, + 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x61, + 0x78, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x6d, 0x61, 0x78, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0xe8, 0x01, + 0x0a, 0x0d, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x53, 0x76, 0x63, 0x12, + 0x42, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x4f, 0x74, 0x61, 0x63, 0x12, 0x17, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, - 0x65, 0x49, 0x64, 0x1a, 0x1f, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x64, - 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x68, 0x6f, 0x62, 0x62, 0x79, 0x66, 0x61, 0x72, 0x6d, 0x2f, 0x67, 0x61, 0x72, - 0x67, 0x61, 0x6e, 0x74, 0x75, 0x61, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, - 0x2f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x65, 0x49, 0x64, 0x1a, 0x1e, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x2e, 0x4f, 0x6e, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, + 0x6f, 0x64, 0x65, 0x12, 0x44, 0x0a, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x74, 0x61, + 0x63, 0x12, 0x1e, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2e, + 0x4f, 0x6e, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x64, + 0x65, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4d, 0x0a, 0x11, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x65, 0x45, 0x78, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x17, + 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x52, 0x65, 0x73, + 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x1a, 0x1f, 0x2e, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, + 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x56, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x6f, 0x62, 0x62, 0x79, 0x66, 0x61, 0x72, 0x6d, + 0x2f, 0x67, 0x61, 0x72, 0x67, 0x61, 0x6e, 0x74, 0x75, 0x61, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/v3/protos/accesscode/accesscode.proto b/v3/protos/accesscode/accesscode.proto index 288f0eca..dff06000 100644 --- a/v3/protos/accesscode/accesscode.proto +++ b/v3/protos/accesscode/accesscode.proto @@ -41,4 +41,5 @@ message OneTimeAccessCode { string id = 1; string user = 2; string redeemed_timestamp = 3; + string max_duration = 4; } \ No newline at end of file diff --git a/v3/protos/authn/authn.pb.go b/v3/protos/authn/authn.pb.go index c3f590f1..e8f1c7e9 100644 --- a/v3/protos/authn/authn.pb.go +++ b/v3/protos/authn/authn.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc v3.21.12 // source: authn/authn.proto diff --git a/v3/protos/authr/authr.pb.go b/v3/protos/authr/authr.pb.go index e1d3cf3e..74eb25ad 100644 --- a/v3/protos/authr/authr.pb.go +++ b/v3/protos/authr/authr.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc v3.21.12 // source: authr/authr.proto diff --git a/v3/protos/rbac/rbac.pb.go b/v3/protos/rbac/rbac.pb.go index bf7e2184..9a2ec3d5 100644 --- a/v3/protos/rbac/rbac.pb.go +++ b/v3/protos/rbac/rbac.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc v3.21.12 // source: rbac/rbac.proto diff --git a/v3/protos/setting/setting.pb.go b/v3/protos/setting/setting.pb.go index 924835a9..a80bdee6 100644 --- a/v3/protos/setting/setting.pb.go +++ b/v3/protos/setting/setting.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc v3.21.12 // source: setting/setting.proto @@ -184,8 +184,8 @@ type CreateSettingRequest struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"` Labels map[string]string `protobuf:"bytes,3,rep,name=labels,proto3" json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Value string `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"` - Property *Property `protobuf:"bytes,5,opt,name=property,proto3" json:"property,omitempty"` + Value string `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"` + Property *Property `protobuf:"bytes,5,opt,name=property,proto3" json:"property,omitempty"` } func (x *CreateSettingRequest) Reset() { diff --git a/v3/protos/user/user.pb.go b/v3/protos/user/user.pb.go index 04389203..5032556d 100644 --- a/v3/protos/user/user.pb.go +++ b/v3/protos/user/user.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.32.0 // protoc v3.21.12 // source: user/user.proto diff --git a/v3/services/accesscodesvc/internal/crd.go b/v3/services/accesscodesvc/internal/crd.go index 1d8c59b4..3b1d2d89 100644 --- a/v3/services/accesscodesvc/internal/crd.go +++ b/v3/services/accesscodesvc/internal/crd.go @@ -22,7 +22,8 @@ func GenerateAccessCodeCRD() []crder.CRD { AddVersion("v1", &v1.OneTimeAccessCode{}, func(cv *crder.Version) { cv. WithColumn("User", ".spec.user"). - WithColumn("Redeemed", ".spec.redeemed_timestamp") + WithColumn("Redeemed", ".spec.redeemed_timestamp"). + WithColumn("MaxDuration", ".spec.max_duration") }) }), } diff --git a/v3/services/accesscodesvc/internal/grpc.go b/v3/services/accesscodesvc/internal/grpc.go index 7069f4b0..d97dc8ae 100644 --- a/v3/services/accesscodesvc/internal/grpc.go +++ b/v3/services/accesscodesvc/internal/grpc.go @@ -41,6 +41,7 @@ func (a *GrpcAccessCodeServer) getOtac(id string) (*accessCodeProto.OneTimeAcces Id: obj.Name, User: obj.Spec.User, RedeemedTimestamp: obj.Spec.RedeemedTimestamp, + MaxDuration: obj.Spec.MaxDuration, }, nil } @@ -108,6 +109,7 @@ func (a *GrpcAccessCodeServer) UpdateOtac(ctx context.Context, otacRequest *acce otac.Spec.User = otacRequest.GetUser() otac.Spec.RedeemedTimestamp = otacRequest.GetRedeemedTimestamp() + otac.Spec.MaxDuration = otacRequest.GetMaxDuration() otac.Labels[util.UserLabel] = otacRequest.GetUser() _, updateErr := a.hfClientSet.HobbyfarmV1().OneTimeAccessCodes(util.GetReleaseNamespace()).Update(a.ctx, otac, metav1.UpdateOptions{})