1package storage 2 3// Copyright 2017 Microsoft Corporation 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 17import ( 18 "strings" 19 "time" 20) 21 22// AccessPolicyDetailsXML has specifics about an access policy 23// annotated with XML details. 24type AccessPolicyDetailsXML struct { 25 StartTime time.Time `xml:"Start"` 26 ExpiryTime time.Time `xml:"Expiry"` 27 Permission string `xml:"Permission"` 28} 29 30// SignedIdentifier is a wrapper for a specific policy 31type SignedIdentifier struct { 32 ID string `xml:"Id"` 33 AccessPolicy AccessPolicyDetailsXML `xml:"AccessPolicy"` 34} 35 36// SignedIdentifiers part of the response from GetPermissions call. 37type SignedIdentifiers struct { 38 SignedIdentifiers []SignedIdentifier `xml:"SignedIdentifier"` 39} 40 41// AccessPolicy is the response type from the GetPermissions call. 42type AccessPolicy struct { 43 SignedIdentifiersList SignedIdentifiers `xml:"SignedIdentifiers"` 44} 45 46// convertAccessPolicyToXMLStructs converts between AccessPolicyDetails which is a struct better for API usage to the 47// AccessPolicy struct which will get converted to XML. 48func convertAccessPolicyToXMLStructs(id string, startTime time.Time, expiryTime time.Time, permissions string) SignedIdentifier { 49 return SignedIdentifier{ 50 ID: id, 51 AccessPolicy: AccessPolicyDetailsXML{ 52 StartTime: startTime.UTC().Round(time.Second), 53 ExpiryTime: expiryTime.UTC().Round(time.Second), 54 Permission: permissions, 55 }, 56 } 57} 58 59func updatePermissions(permissions, permission string) bool { 60 return strings.Contains(permissions, permission) 61} 62