-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
builder origin rbac subcommand #7841
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ed81c10
builder origin rbac operations
jeremymv2 73db411
a rebase merge conflict fix and some improved error handling and cli …
jeremymv2 520ca21
hab client subcommand for origin rbac operations
jeremymv2 39092e8
correcting typo in error message
jeremymv2 f9ec5a7
clippy issues
jeremymv2 0c8864c
adding missing derive ConfigOpt
jeremymv2 640e2ed
fix rbac subcommand help to match configopt
jeremymv2 7016aa0
add missing discription for set configopt variant
jeremymv2 dd3c979
truing up structops with cli args and options
jeremymv2 7b1f484
an implementation with structopt that is suitable
jeremymv2 4c94bd8
fix rebase merge conflict
jeremymv2 6381ea0
adding origin and text_render utility module in core
jeremymv2 787dd7d
moving text render traits into core::util::text_render
jeremymv2 43ca9dd
removing WIP intermediary file artifact
jeremymv2 aff6e0e
removing unused Error entry for the builder-api-client
jeremymv2 633e750
origin member role constants
jeremymv2 6efd8ad
adding TabWriterIntoInnerFailed error variant
jeremymv2 3568a83
validator for parsing Url from args, environment, toml or default
jeremymv2 80dffb7
wire up type primitives all the way to backend builder-api-client set…
jeremymv2 9aee65a
fixup constants and adjust help text
jeremymv2 78f9d5e
moving constants into impl OriginMemberRole and better error handling
jeremymv2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,91 @@ | ||
use crate::{error::Error, | ||
package::ident::is_valid_origin_name}; | ||
use serde_derive::{Deserialize, | ||
Serialize}; | ||
use std::{fmt, | ||
result, | ||
str::FromStr}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
pub struct Origin(String); | ||
|
||
impl Origin { | ||
#[allow(clippy::needless_pass_by_value)] | ||
pub fn validate(value: String) -> result::Result<(), String> { | ||
if is_valid_origin_name(&value) { | ||
Ok(()) | ||
} else { | ||
Err(format!("'{}' is not valid. A valid origin contains a-z, \ | ||
0-9, and _ or - after the first character", | ||
&value)) | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for Origin { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { | ||
Origin::validate(s.to_string()).map_or_else(|e| Err(Error::InvalidOrigin(e)), | ||
|_| Ok(Origin(s.to_string()))) | ||
} | ||
} | ||
|
||
impl fmt::Display for Origin { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } | ||
} | ||
|
||
impl std::convert::TryFrom<&str> for Origin { | ||
type Error = Error; | ||
|
||
fn try_from(s: &str) -> Result<Self, Self::Error> { Self::from_str(s) } | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] | ||
pub enum OriginMemberRole { | ||
ReadonlyMember, | ||
Member, | ||
Maintainer, | ||
Administrator, | ||
Owner, | ||
} | ||
|
||
impl OriginMemberRole { | ||
pub const ADMINISTRATOR: &'static str = "administrator"; | ||
pub const MAINTAINER: &'static str = "maintainer"; | ||
pub const MEMBER: &'static str = "member"; | ||
pub const OWNER: &'static str = "owner"; | ||
pub const READONLY_MEMBER: &'static str = "readonly_member"; | ||
} | ||
|
||
impl Default for OriginMemberRole { | ||
fn default() -> OriginMemberRole { OriginMemberRole::ReadonlyMember } | ||
} | ||
|
||
impl fmt::Display for OriginMemberRole { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let value = match *self { | ||
OriginMemberRole::ReadonlyMember => OriginMemberRole::READONLY_MEMBER, | ||
OriginMemberRole::Member => OriginMemberRole::MEMBER, | ||
OriginMemberRole::Maintainer => OriginMemberRole::MAINTAINER, | ||
OriginMemberRole::Administrator => OriginMemberRole::ADMINISTRATOR, | ||
OriginMemberRole::Owner => OriginMemberRole::OWNER, | ||
}; | ||
write!(f, "{}", value) | ||
} | ||
} | ||
|
||
impl FromStr for OriginMemberRole { | ||
type Err = Error; | ||
|
||
fn from_str(value: &str) -> result::Result<Self, Self::Err> { | ||
match value.to_lowercase().as_ref() { | ||
OriginMemberRole::READONLY_MEMBER => Ok(OriginMemberRole::ReadonlyMember), | ||
OriginMemberRole::MEMBER => Ok(OriginMemberRole::Member), | ||
OriginMemberRole::MAINTAINER => Ok(OriginMemberRole::Maintainer), | ||
OriginMemberRole::ADMINISTRATOR => Ok(OriginMemberRole::Administrator), | ||
OriginMemberRole::OWNER => Ok(OriginMemberRole::Owner), | ||
_ => Err(Error::BadOriginMemberRole(value.to_string())), | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this function already returns a
Result
, could we remove thisexpect
in favor of propagating theErr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handled in 78f9d5e