go.temporal.io/server@v1.23.0/common/namespace/mutate.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package namespace 26 27 import ( 28 namespacepb "go.temporal.io/api/namespace/v1" 29 "google.golang.org/protobuf/types/known/durationpb" 30 31 "go.temporal.io/server/common/persistence" 32 ) 33 34 type mutationFunc func(*persistence.GetNamespaceResponse) 35 36 func (f mutationFunc) apply(ns *persistence.GetNamespaceResponse) { 37 f(ns) 38 } 39 40 // WithActiveCluster assigns the active cluster to a Namespace during a Clone 41 // operation. 42 func WithActiveCluster(name string) Mutation { 43 return mutationFunc( 44 func(ns *persistence.GetNamespaceResponse) { 45 ns.Namespace.ReplicationConfig.ActiveClusterName = name 46 }) 47 } 48 49 // WithBadBinary adds a bad binary checksum to a Namespace during a Clone 50 // operation. 51 func WithBadBinary(chksum string) Mutation { 52 return mutationFunc( 53 func(ns *persistence.GetNamespaceResponse) { 54 if ns.Namespace.Config.BadBinaries.Binaries == nil { 55 ns.Namespace.Config.BadBinaries.Binaries = make(map[string]*namespacepb.BadBinaryInfo) 56 } 57 ns.Namespace.Config.BadBinaries.Binaries[chksum] = 58 &namespacepb.BadBinaryInfo{} 59 }) 60 } 61 62 // WithID assigns the ID to a Namespace during a Clone operation. 63 func WithID(id string) Mutation { 64 return mutationFunc( 65 func(ns *persistence.GetNamespaceResponse) { 66 ns.Namespace.Info.Id = id 67 }) 68 } 69 70 // WithGlobalFlag sets whether or not this Namespace is global. 71 func WithGlobalFlag(b bool) Mutation { 72 return mutationFunc( 73 func(ns *persistence.GetNamespaceResponse) { 74 ns.IsGlobalNamespace = b 75 }) 76 } 77 78 // WithRentention assigns the retention duration to a Namespace during a Clone 79 // operation. 80 func WithRetention(dur *durationpb.Duration) Mutation { 81 return mutationFunc( 82 func(ns *persistence.GetNamespaceResponse) { 83 ns.Namespace.Config.Retention = dur 84 }) 85 } 86 87 // WithData adds a key-value pair to a Namespace during a Clone operation. 88 func WithData(key, value string) Mutation { 89 return mutationFunc( 90 func(ns *persistence.GetNamespaceResponse) { 91 if ns.Namespace.Info.Data == nil { 92 ns.Namespace.Info.Data = make(map[string]string) 93 } 94 ns.Namespace.Info.Data[key] = value 95 }) 96 }