-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mode property for restricting file upload access (#28)
* Add mode property for restricting file upload access - implementation and tests Signed-off-by: Georgi Boyvalenkov <[email protected]>
- Loading branch information
1 parent
f33739d
commit 6ba573d
Showing
7 changed files
with
212 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0 | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 | ||
|
||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// AccessMode type, for restricting files allowed to be dynamically requested for upload | ||
type AccessMode int | ||
|
||
// Allowed values for AccessMode | ||
const ( | ||
ModeNA = iota | ||
ModeStrict | ||
ModeLax | ||
ModeScoped | ||
) | ||
|
||
// AccessMode names | ||
const ( | ||
ModeNameStrict = "strict" | ||
ModeNameLax = "lax" | ||
ModeNameScoped = "scoped" | ||
) | ||
|
||
// String returns string representation of AccessMode | ||
func (m AccessMode) String() string { | ||
switch m { | ||
case ModeStrict: | ||
return ModeNameStrict | ||
case ModeLax: | ||
return ModeNameLax | ||
case ModeScoped: | ||
return ModeNameScoped | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
// Set implements flag.Value Set method | ||
func (m *AccessMode) Set(v string) error { | ||
switch v { | ||
case ModeNameStrict: | ||
*m = ModeStrict | ||
case ModeNameLax: | ||
*m = ModeLax | ||
case ModeNameScoped: | ||
*m = ModeScoped | ||
case "": | ||
*m = ModeNA | ||
default: | ||
return fmt.Errorf("accepted values are '%s', '%s' and '%s'", ModeNameStrict, ModeNameLax, ModeNameScoped) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// MarshalJSON marshals AccessMode as JSON | ||
func (m AccessMode) MarshalJSON() ([]byte, error) { | ||
s := m.String() | ||
|
||
return json.Marshal(s) | ||
} | ||
|
||
// UnmarshalJSON un-marshals AccessMode from JSON | ||
func (m *AccessMode) UnmarshalJSON(b []byte) error { | ||
var s string | ||
if err := json.Unmarshal(b, &s); err != nil { | ||
return err | ||
} | ||
|
||
err := m.Set(s) | ||
if err != nil { | ||
return fmt.Errorf("invalid value '%s' for property 'mode' - %w", s, err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters