static.go (2104B)
1 /* 2 * MinIO Go Library for Amazon S3 Compatible Cloud Storage 3 * Copyright 2017 MinIO, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package credentials 19 20 // A Static is a set of credentials which are set programmatically, 21 // and will never expire. 22 type Static struct { 23 Value 24 } 25 26 // NewStaticV2 returns a pointer to a new Credentials object 27 // wrapping a static credentials value provider, signature is 28 // set to v2. If access and secret are not specified then 29 // regardless of signature type set it Value will return 30 // as anonymous. 31 func NewStaticV2(id, secret, token string) *Credentials { 32 return NewStatic(id, secret, token, SignatureV2) 33 } 34 35 // NewStaticV4 is similar to NewStaticV2 with similar considerations. 36 func NewStaticV4(id, secret, token string) *Credentials { 37 return NewStatic(id, secret, token, SignatureV4) 38 } 39 40 // NewStatic returns a pointer to a new Credentials object 41 // wrapping a static credentials value provider. 42 func NewStatic(id, secret, token string, signerType SignatureType) *Credentials { 43 return New(&Static{ 44 Value: Value{ 45 AccessKeyID: id, 46 SecretAccessKey: secret, 47 SessionToken: token, 48 SignerType: signerType, 49 }, 50 }) 51 } 52 53 // Retrieve returns the static credentials. 54 func (s *Static) Retrieve() (Value, error) { 55 if s.AccessKeyID == "" || s.SecretAccessKey == "" { 56 // Anonymous is not an error 57 return Value{SignerType: SignatureAnonymous}, nil 58 } 59 return s.Value, nil 60 } 61 62 // IsExpired returns if the credentials are expired. 63 // 64 // For Static, the credentials never expired. 65 func (s *Static) IsExpired() bool { 66 return false 67 }